]> git.gir.st - VimFx.git/blob - extension/test/test-api-frame.coffee
Fix tests in Firefox Nightly
[VimFx.git] / extension / test / test-api-frame.coffee
1 ###
2 # Copyright Simon Lydell 2016.
3 #
4 # This file is part of VimFx.
5 #
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
18 ###
19
20 assert = require('./assert')
21 testUtils = require('./utils')
22 createConfigAPI = require('../lib/api-frame')
23
24 exports['test exports'] = ($vim) ->
25 vimfx = createConfigAPI($vim)
26
27 assert.equal(typeof vimfx.listen, 'function', 'listen')
28 assert.equal(typeof vimfx.setHintMatcher, 'function', 'setHintMatcher')
29 assert.equal(typeof vimfx.getMarkerElement, 'function', 'getMarkerElement')
30
31 exports['test vimfx.listen'] = ($vim, teardown) ->
32 shutdownHandlers = []
33 onShutdown = (fn) -> shutdownHandlers.push(fn)
34 vimfx = createConfigAPI($vim, onShutdown)
35
36 resets = []
37 teardown(->
38 reset() for reset in resets
39 return
40 )
41
42 messageManager = new testUtils.MockMessageManager()
43 for name, fn of messageManager when typeof fn == 'function'
44 resets.push(
45 testUtils.stub(FRAME_SCRIPT_ENVIRONMENT, name, fn.bind(messageManager))
46 )
47
48 vimfx.listen('message', ->)
49 assert.equal(messageManager.sendAsyncMessageCalls, 0)
50 assert.equal(messageManager.addMessageListenerCalls, 1)
51 assert.equal(messageManager.removeMessageListenerCalls, 0)
52
53 assert.equal(shutdownHandlers.length, 1)
54 shutdownHandlers[0]()
55 assert.equal(messageManager.sendAsyncMessageCalls, 0)
56 assert.equal(messageManager.addMessageListenerCalls, 1)
57 assert.equal(messageManager.removeMessageListenerCalls, 1)
58
59 exports['test vimfx.setHintMatcher'] = ($vim) ->
60 shutdownHandlers = []
61 onShutdown = (fn) -> shutdownHandlers.push(fn)
62 vimfx = createConfigAPI($vim, onShutdown)
63
64 assert.ok(not $vim.hintMatcher)
65
66 hintMatcher = ->
67 vimfx.setHintMatcher(hintMatcher)
68 assert.equal($vim.hintMatcher, hintMatcher)
69
70 assert.equal(shutdownHandlers.length, 1)
71 shutdownHandlers[0]()
72 assert.ok(not $vim.hintMatcher)
73
74 exports['test vimfx.getMarkerElement'] = ($vim, teardown) ->
75 teardown(->
76 $vim.state.markerElements = []
77 )
78
79 vimfx = createConfigAPI($vim)
80 element = {}
81 $vim.state.markerElements = [{element}]
82
83 assert.equal(vimfx.getMarkerElement(0), element)
84 assert.equal(vimfx.getMarkerElement(1), null)
85 assert.equal(vimfx.getMarkerElement(null), null)
86
87 $vim.state.markerElements = []
88 assert.equal(vimfx.getMarkerElement(0), null)
89
90 exports['test vimfx.listen errors'] = ($vim) ->
91 vimfx = createConfigAPI($vim)
92
93 assert.throws(/message string/i, 'undefined', ->
94 vimfx.listen()
95 )
96
97 assert.throws(/message string/i, 'false', ->
98 vimfx.listen(false)
99 )
100
101 assert.throws(/listener function/i, 'undefined', ->
102 vimfx.listen('message')
103 )
104
105 assert.throws(/listener function/i, 'false', ->
106 vimfx.listen('message', false)
107 )
108
109 exports['test vimfx.setHintMatcher errors'] = ($vim) ->
110 vimfx = createConfigAPI($vim)
111
112 assert.throws(/function/i, 'undefined', ->
113 vimfx.setHintMatcher()
114 )
115
116 assert.throws(/function/i, 'false', ->
117 vimfx.setHintMatcher(false)
118 )
Imprint / Impressum