]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/spec/vim-mode-spec.coffee
0f4d8b874ee489add4ae134349c782be6ebdaf6f
[rbdr/dotfiles] / atom / packages / vim-mode / spec / vim-mode-spec.coffee
1 describe "VimMode", ->
2 [editor, editorElement, workspaceElement] = []
3
4 beforeEach ->
5 workspaceElement = atom.views.getView(atom.workspace)
6
7 waitsForPromise ->
8 atom.workspace.open()
9
10 waitsForPromise ->
11 atom.packages.activatePackage('vim-mode')
12
13 waitsForPromise ->
14 atom.packages.activatePackage('status-bar')
15
16 runs ->
17 editor = atom.workspace.getActiveTextEditor()
18 editorElement = atom.views.getView(editor)
19
20 describe ".activate", ->
21 it "puts the editor in command-mode initially by default", ->
22 expect(editorElement.classList.contains('vim-mode')).toBe(true)
23 expect(editorElement.classList.contains('command-mode')).toBe(true)
24
25 it "shows the current vim mode in the status bar", ->
26 statusBarTile = workspaceElement.querySelector("#status-bar-vim-mode")
27 expect(statusBarTile.textContent).toBe("Command")
28 atom.commands.dispatch(editorElement, "vim-mode:activate-insert-mode")
29 expect(statusBarTile.textContent).toBe("Insert")
30
31 it "doesn't register duplicate command listeners for editors", ->
32 editor.setText("12345")
33 editor.setCursorBufferPosition([0, 0])
34
35 pane = atom.workspace.getActivePane()
36 newPane = pane.splitRight()
37 pane.removeItem(editor)
38 newPane.addItem(editor)
39
40 atom.commands.dispatch(editorElement, "vim-mode:move-right")
41 expect(editor.getCursorBufferPosition()).toEqual([0, 1])
42
43 describe ".deactivate", ->
44 it "removes the vim classes from the editor", ->
45 atom.packages.deactivatePackage('vim-mode')
46 expect(editorElement.classList.contains("vim-mode")).toBe(false)
47 expect(editorElement.classList.contains("command-mode")).toBe(false)
48
49 it "removes the vim commands from the editor element", ->
50 vimCommands = ->
51 atom.commands.findCommands(target: editorElement).filter (cmd) ->
52 cmd.name.startsWith("vim-mode:")
53
54 expect(vimCommands().length).toBeGreaterThan(0)
55 atom.packages.deactivatePackage('vim-mode')
56 expect(vimCommands().length).toBe(0)