-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
52 lines (40 loc) · 1.39 KB
/
test.js
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
import test from 'tape'
import sortBy from 'lodash/sortBy.js'
import {autocomplete} from './index.js'
test('autocomplete returns an array', (t) => {
t.plan(2)
t.ok(Array.isArray(autocomplete('', 3)))
t.ok(Array.isArray(autocomplete('foo', 3)))
})
test('autocomplete returns an empty array for an empty query', (t) => {
t.plan(1)
const results = autocomplete('', 3)
t.equal(results.length, 0)
})
test('autocomplete sorts by score', (t) => {
t.plan(1)
const results = autocomplete('berli', 3)
t.deepEqual(results, sortBy(results, 'score').reverse())
})
// todo: fails with tokenize-db-station-name@2
test.skip('autocomplete limits the number of results', (t) => {
t.plan(1)
t.equal(autocomplete('Hbf', 1).length, 1)
})
test('gives reasonable results', (t) => {
const r0 = autocomplete('Münch', 3)
const münchenHbf = r0.find(({id}) => id === '8000261')
t.ok(münchenHbf, 'missing "München Hbf"')
const münchenOst = r0.find(({id}) => id === '8000262')
t.ok(münchenOst, 'missing "München Ost"')
const r1 = autocomplete('Berlin', 3)
const berlinGesundbrunnen = r1.find(({id}) => id === '8011102')
t.ok(berlinGesundbrunnen, 'missing "Berlin Gesundbrunnen"')
const r3 = autocomplete('Karlsruhe', 1, true, false)[0]
t.ok(r3)
t.equal((r3 || {}).id, '8000191') // Karlsruhe
const r4 = autocomplete('Wedding', 1)[0]
t.ok(r4)
t.equal((r4 || {}).id, '8089131') // Berlin Wedding
t.end()
})