File: max_shown_results.spec.coffee

package info (click to toggle)
libjs-chosen 1.8.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 756 kB
  • sloc: sh: 28; makefile: 13
file content (64 lines) | stat: -rw-r--r-- 2,375 bytes parent folder | download | duplicates (2)
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
describe "search", ->
  it "should display only matching items when entering a search term", ->
    tmpl = "
          <select data-placeholder='Choose a Country...'>
            <option value=''></option>
            <option value='United States'>United States</option>
            <option value='United Kingdom'>United Kingdom</option>
            <option value='Afghanistan'>Afghanistan</option>
          </select>
        "
    div = $("<div>").html(tmpl)
    select = div.find("select")
    select.chosen()

    container = div.find(".chosen-container")
    container.trigger("mousedown") # open the drop
    # Expect all results to be shown
    results = div.find(".active-result")
    expect(results.length).toBe(3)

    # Enter some text in the search field.
    search_field = div.find(".chosen-search input").first()
    search_field.val("Afgh")
    search_field.trigger('keyup')

    # Expect to only have one result: 'Afghanistan'.
    results = div.find(".active-result")
    expect(results.length).toBe(1)
    expect(results.first().text()).toBe "Afghanistan"

  it "should only show max_shown_results items in results", ->
    tmpl = "
          <select data-placeholder='Choose a Country...'>
            <option value=''></option>
            <option value='United States'>United States</option>
            <option value='United Kingdom'>United Kingdom</option>
            <option value='Afghanistan'>Afghanistan</option>
          </select>
        "
    div = $("<div>").html(tmpl)
    select = div.find("select")
    select.chosen({max_shown_results: 1 })

    container = div.find(".chosen-container")
    container.trigger("mousedown") # open the drop
    results = div.find(".active-result")
    expect(results.length).toBe(1)

    # Enter some text in the search field.
    search_field = div.find(".chosen-search input").first()
    search_field.val("United")
    search_field.trigger("keyup")

    # Showing only one result: the one that occurs first.
    results = div.find(".active-result")
    expect(results.length).toBe(1)
    expect(results.first().text()).toBe "United States"

    # Showing still only one result, but not the first one.
    search_field.val("United Ki")
    search_field.trigger("keyup")
    results = div.find(".active-result")
    expect(results.length).toBe(1)
    expect(results.first().text()).toBe "United Kingdom"