aboutsummaryrefslogtreecommitdiff
path: root/atom/packages/vim-surround/spec
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2015-07-10 11:12:25 -0500
committerBen Beltran <ben@nsovocal.com>2015-07-10 11:12:25 -0500
commit24c7594d62d8d7fbbcdb64b11ce4adc5d8e6991a (patch)
treeded312222bb108923da1820ba40b04d710d20e5b /atom/packages/vim-surround/spec
parenteb786e82d170e2abc351a432ade616d6ecdeeb6b (diff)
Adds atom
Diffstat (limited to 'atom/packages/vim-surround/spec')
-rw-r--r--atom/packages/vim-surround/spec/spec-helper.coffee13
-rw-r--r--atom/packages/vim-surround/spec/vim-surround-spec.coffee72
2 files changed, 85 insertions, 0 deletions
diff --git a/atom/packages/vim-surround/spec/spec-helper.coffee b/atom/packages/vim-surround/spec/spec-helper.coffee
new file mode 100644
index 0000000..931e0b9
--- /dev/null
+++ b/atom/packages/vim-surround/spec/spec-helper.coffee
@@ -0,0 +1,13 @@
+getEditorElement = (callback) ->
+ textEditor = null
+
+ waitsForPromise ->
+ atom.project.open().then (e) ->
+ textEditor = e
+
+ runs ->
+ element = document.createElement("atom-text-editor")
+ element.setModel(textEditor)
+ callback(element)
+
+module.exports = { getEditorElement }
diff --git a/atom/packages/vim-surround/spec/vim-surround-spec.coffee b/atom/packages/vim-surround/spec/vim-surround-spec.coffee
new file mode 100644
index 0000000..41a348e
--- /dev/null
+++ b/atom/packages/vim-surround/spec/vim-surround-spec.coffee
@@ -0,0 +1,72 @@
+helpers = require './spec-helper'
+
+describe "Vim Surround activation", ->
+ [editor, pairs, editorElement, vimSurround, configPairs, chars, names] = []
+
+ beforeEach ->
+ pairs = ['()', '{}', '[]', '""', "''"]
+ atom.config.set('vim-surround.pairs', pairs)
+
+ vimSurround = atom.packages.loadPackage('vim-surround')
+ vimSurround.activate()
+
+ configPairs = atom.config.get('vim-surround.pairs')
+
+ helpers.getEditorElement (element) ->
+ editorElement = element
+ editor = editorElement.getModel()
+
+ editorClassList = editorElement.classList
+
+ editorClassList.add('editor')
+ editorClassList.add('vim-mode')
+ editorClassList.add('visual-mode')
+
+
+ describe "When the vim-surround module loads", ->
+ beforeEach ->
+ chars = []
+ pairs.forEach (pair) ->
+ for i in [0..pair.length-1]
+ char = pair[i]
+ chars.push char unless char in chars
+
+ commands = atom.commands.findCommands target: editorElement
+
+ names = []
+ commands.forEach (command) ->
+ names.push(command.name)
+
+ it "Creates a surround command for each configured pair character", ->
+ chars.forEach (char) ->
+ expect(names).toContain("vim-surround:surround-#{char}")
+
+ describe "and the list of pairs changes", ->
+ beforeEach ->
+ pairs = ['()', '{}', '[]', '""', "-+"]
+ atom.config.set('vim-surround.pairs', pairs)
+ commands = atom.commands.findCommands target: editorElement
+ names = (command.name for command in commands)
+ chars = []
+ pairs.forEach (pair) ->
+ for i in [0..pair.length-1]
+ char = pair[i]
+ chars.push char unless char in chars
+
+ it "should add any new pairs.", ->
+ chars.forEach (char) ->
+ expect(names).toContain("vim-surround:surround-#{char}")
+
+ it "should remove any old pairs.", ->
+ expect(names).not.toContain("vim-surround:surround-'")
+
+ describe "and then deactivates", ->
+
+ beforeEach ->
+ vimSurround.deactivate()
+ commands = atom.commands.findCommands target: editorElement
+ names = (command.name for command in commands)
+
+ it "should clear out all commands from the registry", ->
+ chars.forEach (char) ->
+ expect(names).not.toContain("vim-surround:surround-#{char}")