forked from graphql/graphql-js
/
suggestionList-test.js
67 lines (54 loc) · 2.01 KB
/
suggestionList-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { suggestionList } from '../suggestionList';
function expectSuggestions(input: string, options: Array<string>) {
return expect(suggestionList(input, options));
}
describe('suggestionList', () => {
it('Returns results when input is empty', () => {
expectSuggestions('', ['a']).to.deep.equal(['a']);
});
it('Returns empty array when there are no options', () => {
expectSuggestions('input', []).to.deep.equal([]);
});
it('Returns options with small lexical distance', () => {
expectSuggestions('greenish', ['green']).to.deep.equal(['green']);
expectSuggestions('green', ['greenish']).to.deep.equal(['greenish']);
});
it('Rejects options with distance that exceeds threshold', () => {
expectSuggestions('aaaa', ['aaab']).to.deep.equal(['aaab']);
expectSuggestions('aaaa', ['aabb']).to.deep.equal(['aabb']);
expectSuggestions('aaaa', ['abbb']).to.deep.equal([]);
expectSuggestions('ab', ['ca']).to.deep.equal([]);
});
it('Returns options with different case', () => {
// cSpell:ignore verylongstring
expectSuggestions('verylongstring', ['VERYLONGSTRING']).to.deep.equal([
'VERYLONGSTRING',
]);
expectSuggestions('VERYLONGSTRING', ['verylongstring']).to.deep.equal([
'verylongstring',
]);
expectSuggestions('VERYLONGSTRING', ['VeryLongString']).to.deep.equal([
'VeryLongString',
]);
});
it('Returns options with transpositions', () => {
expectSuggestions('agr', ['arg']).to.deep.equal(['arg']);
expectSuggestions('214365879', ['123456789']).to.deep.equal(['123456789']);
});
it('Returns options sorted based on lexical distance', () => {
expectSuggestions('abc', ['a', 'ab', 'abc']).to.deep.equal([
'abc',
'ab',
'a',
]);
});
it('Returns options with the same lexical distance sorted lexicographically', () => {
expectSuggestions('a', ['az', 'ax', 'ay']).to.deep.equal([
'ax',
'ay',
'az',
]);
});
});