 {inspect} = require 'util'
-p = (args...) -> console.log inspect(args...)
 
 requireFrom = (pack, path) ->
   packPath = atom.packages.resolvePackagePath(pack)


  describe "overwrite config", ->
    [vimState1, vimState2, vimState3] = []
    overwriteConfig = 'vim-mode-plus-move-selected-text.overwrite'
    overwriteClass = 'vim-mode-plus-move-selected-text-overwrite'

    beforeEach ->
      getVimState "sample1", (state, vim) -> vimState1 = state
      getVimState "sample2", (state, vim) -> vimState2 = state

    it "toggle command toggle overwrite config value", ->
      expect(atom.config.get(overwriteConfig)).toBe(false)

      dispatch(editorElement, 'vim-mode-plus-user:move-selected-text-toggle-overwrite')
      expect(atom.config.get(overwriteConfig)).toBe(true)

      dispatch(editorElement, 'vim-mode-plus-user:move-selected-text-toggle-overwrite')
      expect(atom.config.get(overwriteConfig)).toBe(false)

    describe "when overwrite config is toggled in false -> true -> false", ->
      it "add/remove overwrite css class to/from all editorElement including newly created editor", ->
        runs ->
          expect(atom.config.get(overwriteConfig)).toBe(false)
          for {editorElement: el} in [vimState1, vimState2]
            expect(el.classList.contains(overwriteClass)).toBe(false)

          toggleOverwrite(vimState1.editorElement)
          expect(atom.config.get(overwriteConfig)).toBe(true)
          for {editorElement: el} in [vimState1, vimState2]
            expect(el.classList.contains(overwriteClass)).toBe(true)

        getVimState "sample3", (state, vim) ->
          vimState3 = state
          el = state.editorElement
          expect(el.classList.contains(overwriteClass)).toBe(true)

        runs ->
          toggleOverwrite(vimState1.editorElement)
          expect(atom.config.get(overwriteConfig)).toBe(false)
          for {editorElement: el} in [vimState1, vimState2, vimState3]
            expect(el.classList.contains(overwriteClass)).toBe(false)

        waitsForPromise ->
          atom.packages.activatePackage('vim-mode-plus-move-selected-text')


toggleOverwrite = (target) ->
  dispatch(target, 'vim-mode-plus-user:move-selected-text-toggle-overwrite')

getOverwriteConfig = ->
  atom.config.get('vim-mode-plus-move-selected-text.overwrite')

{getVimState, TextData, dispatch} = requireFrom 'vim-mode-plus', 'spec/spec-helper'

