aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dom_tests
diff options
context:
space:
mode:
authorStephen Blott2015-01-11 12:19:19 +0000
committerStephen Blott2015-01-11 14:36:33 +0000
commitf76c15c6ae6565c0c08569a127974dfd3383ed88 (patch)
tree945c8405da0ce0ddec6d47cd2e3ce60b6d2698ad /tests/dom_tests
parenta8096d235eae39d309c0ffd74e0d2493ff12dd22 (diff)
downloadvimium-f76c15c6ae6565c0c08569a127974dfd3383ed88.tar.bz2
Modes; tweaks, including more tests.
Diffstat (limited to 'tests/dom_tests')
-rw-r--r--tests/dom_tests/dom_tests.coffee28
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee
index c84d513d..d9e7775f 100644
--- a/tests/dom_tests/dom_tests.coffee
+++ b/tests/dom_tests/dom_tests.coffee
@@ -8,12 +8,12 @@ mockKeyboardEvent = (keyChar) ->
event.charCode = (if keyCodes[keyChar] isnt undefined then keyCodes[keyChar] else keyChar.charCodeAt(0))
event.keyIdentifier = "U+00" + event.charCode.toString(16)
event.keyCode = event.charCode
- event.stopImmediatePropagation = (event) -> @suppressed = true
- event.preventDefault = (event) -> @suppressed = true
+ event.stopImmediatePropagation = -> @suppressed = true
+ event.preventDefault = -> @suppressed = true
event
# Some of these tests have side effects on the handler stack and mode. Therefore, we take backups and restore
-# them later.
+# them on tear down.
backupStackState = ->
Mode.backup = Mode.modes[..]
handlerStack.backup = handlerStack.stack[..]
@@ -197,6 +197,21 @@ context "Input focus",
assert.equal "third", document.activeElement.id
handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A")
+ # This is the same as above, but also verifies that focusInput activates insert mode.
+ should "focus the right element, and activate insert mode", ->
+ focusInput 1
+ assert.equal "first", document.activeElement.id
+ # deactivate the tabbing mode and its overlays
+ assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert"
+ handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A")
+ assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert"
+
+ focusInput 100
+ assert.equal "third", document.activeElement.id
+ assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert"
+ handlerStack.bubbleEvent 'keydown', mockKeyboardEvent("A")
+ assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert"
+
# TODO: these find prev/next link tests could be refactored into unit tests which invoke a function which has
# a tighter contract than goNext(), since they test minor aspects of goNext()'s link matching behavior, and we
# don't need to construct external state many times over just to test that.
@@ -262,13 +277,12 @@ createLinks = (n) ->
link.textContent = "test"
document.getElementById("test-div").appendChild link
-# For these tests, we use "m" as a mapped key, "p" ass a pass key, and "u" as an unmapped key.
+# For these tests, we use "m" as a mapped key, "p" as a pass key, and "u" as an unmapped key.
context "Normal mode",
setup ->
backupStackState()
refreshCompletionKeys
- completionKeys: [ "m" ]
- validFirstKeys: {}
+ completionKeys: "m"
tearDown ->
restoreStackState()
@@ -616,7 +630,7 @@ context "PostFindMode",
should "enter insert mode on immediate escape", ->
new PostFindMode @element
- assert.isTrue Mode.modes[Mode.modes.length-1].name != "insert"
+ assert.isTrue Mode.modes[Mode.modes.length-1].name == "post-find"
handlerStack.bubbleEvent "keydown", @escape
assert.isTrue Mode.modes[Mode.modes.length-1].name == "insert"