aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dom_tests/vomnibar_test.coffee
blob: b414fdfb90f6368d5485367bcca6f03a9ee3f5d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
context "Keep selection within bounds",

  setup ->
    @completions = []
    oldGetCompleter = Vomnibar.getCompleter.bind Vomnibar
    stub Vomnibar, 'getCompleter', (name) =>
      completer = oldGetCompleter name
      stub completer, 'filter', (query, callback) => callback(@completions)
      completer

  tearDown ->
    Vomnibar.vomnibarUI.hide()

  should "set selection to position -1 for omni completion by default", ->
    Vomnibar.activate()
    ui = Vomnibar.vomnibarUI

    @completions = []
    ui.update(true)
    assert.equal -1, ui.selection

    @completions = [{html:'foo',type:'tab',url:'http://example.com'}]
    ui.update(true)
    assert.equal -1, ui.selection

    @completions = []
    ui.update(true)
    assert.equal -1, ui.selection

  should "set selection to position 0 for bookmark completion if possible", ->
    Vomnibar.activateBookmarks()
    ui = Vomnibar.vomnibarUI

    @completions = []
    ui.update(true)
    assert.equal -1, ui.selection

    @completions = [{html:'foo',type:'bookmark',url:'http://example.com'}]
    ui.update(true)
    assert.equal 0, ui.selection

    @completions = []
    ui.update(true)
    assert.equal -1, ui.selection

  should "keep selection within bounds", ->
    Vomnibar.activate()
    ui = Vomnibar.vomnibarUI

    @completions = []
    ui.update(true)

    eventMock =
      preventDefault: ->
      stopImmediatePropagation: ->

    @completions = [{html:'foo',type:'tab',url:'http://example.com'}]
    ui.update(true)
    stub ui, "actionFromKeyEvent", -> "down"
    ui.onKeydown eventMock
    assert.equal 0, ui.selection

    @completions = []
    ui.update(true)
    assert.equal -1, ui.selection