1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai = require("chai");
|
19 | const quick_input_service_1 = require("./quick-input-service");
|
20 | const expect = chai.expect;
|
21 | describe('quick-input-service', () => {
|
22 | describe('#findMatches', () => {
|
23 | it('should return the proper highlights when matches are found', () => {
|
24 | expect((0, quick_input_service_1.findMatches)('abc', 'a')).deep.equal([{ start: 0, end: 1 }]);
|
25 | expect((0, quick_input_service_1.findMatches)('abc', 'ab')).deep.equal([{ start: 0, end: 1 }, { start: 1, end: 2 }]);
|
26 | expect((0, quick_input_service_1.findMatches)('abc', 'ac')).deep.equal([{ start: 0, end: 1 }, { start: 2, end: 3 }]);
|
27 | expect((0, quick_input_service_1.findMatches)('abc', 'abc')).deep.equal([{ start: 0, end: 1 }, { start: 1, end: 2 }, { start: 2, end: 3 }]);
|
28 | });
|
29 | it('should fail when out of order', () => {
|
30 | expect((0, quick_input_service_1.findMatches)('abc', 'ba')).equal(undefined);
|
31 | });
|
32 | it('should return `undefined` when no matches are found', () => {
|
33 | expect((0, quick_input_service_1.findMatches)('abc', 'f')).equal(undefined);
|
34 | });
|
35 | it('should return `undefined` when no filter is present', () => {
|
36 | expect((0, quick_input_service_1.findMatches)('abc', '')).equal(undefined);
|
37 | });
|
38 | });
|
39 | describe('#filterItems', () => {
|
40 | let items = [];
|
41 | beforeEach(() => {
|
42 | items = [
|
43 | { label: 'a' },
|
44 | { label: 'abc', description: 'v' },
|
45 | { label: 'def', description: 'd', detail: 'y' },
|
46 | { label: 'z', description: 'z', detail: 'z' }
|
47 | ];
|
48 | });
|
49 | it('should return the full list when no filter is present', () => {
|
50 | const result = (0, quick_input_service_1.filterItems)(items, '');
|
51 | expect(result).deep.equal(items);
|
52 | });
|
53 | it('should filter items based on the label', () => {
|
54 | var _a, _b;
|
55 | const expectation = {
|
56 | label: 'abc',
|
57 | highlights: {
|
58 | label: [
|
59 | { start: 0, end: 1 },
|
60 | { start: 1, end: 2 },
|
61 | { start: 2, end: 3 }
|
62 | ]
|
63 | }
|
64 | };
|
65 | const result = (0, quick_input_service_1.filterItems)(items, 'abc').filter(quick_input_service_1.QuickPickItem.is);
|
66 | expect(result).length(1);
|
67 | expect(result[0].label).equal(expectation.label);
|
68 | expect((_a = result[0].highlights) === null || _a === void 0 ? void 0 : _a.label).deep.equal((_b = expectation.highlights) === null || _b === void 0 ? void 0 : _b.label);
|
69 | });
|
70 | it('should filter items based on `description` if `label` does not match', () => {
|
71 | var _a, _b, _c;
|
72 | const expectation = {
|
73 | label: 'abc',
|
74 | description: 'v',
|
75 | highlights: {
|
76 | description: [
|
77 | { start: 0, end: 1 }
|
78 | ]
|
79 | }
|
80 | };
|
81 | const result = (0, quick_input_service_1.filterItems)(items, 'v').filter(quick_input_service_1.QuickPickItem.is);
|
82 | expect(result).length(1);
|
83 | expect(result[0].label).equal(expectation.label);
|
84 | expect(result[0].description).equal(expectation.description);
|
85 | expect((_a = result[0].highlights) === null || _a === void 0 ? void 0 : _a.label).equal(undefined);
|
86 | expect((_b = result[0].highlights) === null || _b === void 0 ? void 0 : _b.description).deep.equal((_c = expectation.highlights) === null || _c === void 0 ? void 0 : _c.description);
|
87 | });
|
88 | it('should filter items based on `detail` if `label` and `description` does not match', () => {
|
89 | var _a, _b, _c, _d;
|
90 | const expectation = {
|
91 | label: 'def',
|
92 | description: 'd',
|
93 | detail: 'y',
|
94 | highlights: {
|
95 | detail: [
|
96 | { start: 0, end: 1 }
|
97 | ]
|
98 | }
|
99 | };
|
100 | const result = (0, quick_input_service_1.filterItems)(items, 'y').filter(quick_input_service_1.QuickPickItem.is);
|
101 | expect(result).length(1);
|
102 | expect(result[0].label).equal(expectation.label);
|
103 | expect(result[0].description).equal(expectation.description);
|
104 | expect(result[0].detail).equal(expectation.detail);
|
105 | expect((_a = result[0].highlights) === null || _a === void 0 ? void 0 : _a.label).equal(undefined);
|
106 | expect((_b = result[0].highlights) === null || _b === void 0 ? void 0 : _b.description).equal(undefined);
|
107 | expect((_c = result[0].highlights) === null || _c === void 0 ? void 0 : _c.detail).deep.equal((_d = expectation.highlights) === null || _d === void 0 ? void 0 : _d.detail);
|
108 | });
|
109 | it('should return multiple highlights if it matches multiple properties', () => {
|
110 | var _a, _b, _c, _d, _e, _f;
|
111 | const expectation = {
|
112 | label: 'z',
|
113 | description: 'z',
|
114 | detail: 'z',
|
115 | highlights: {
|
116 | label: [
|
117 | { start: 0, end: 1 }
|
118 | ],
|
119 | description: [
|
120 | { start: 0, end: 1 }
|
121 | ],
|
122 | detail: [
|
123 | { start: 0, end: 1 }
|
124 | ]
|
125 | }
|
126 | };
|
127 | const result = (0, quick_input_service_1.filterItems)(items, 'z').filter(quick_input_service_1.QuickPickItem.is);
|
128 | expect(result).length(1);
|
129 | expect(result[0].label).equal(expectation.label);
|
130 | expect(result[0].description).equal(expectation.description);
|
131 | expect(result[0].detail).equal(expectation.detail);
|
132 | expect((_a = result[0].highlights) === null || _a === void 0 ? void 0 : _a.label).deep.equal((_b = expectation.highlights) === null || _b === void 0 ? void 0 : _b.label);
|
133 | expect((_c = result[0].highlights) === null || _c === void 0 ? void 0 : _c.description).deep.equal((_d = expectation.highlights) === null || _d === void 0 ? void 0 : _d.description);
|
134 | expect((_e = result[0].highlights) === null || _e === void 0 ? void 0 : _e.detail).deep.equal((_f = expectation.highlights) === null || _f === void 0 ? void 0 : _f.detail);
|
135 | });
|
136 | it('should reset highlights upon subsequent searches', () => {
|
137 | var _a, _b, _c;
|
138 | const expectation = {
|
139 | label: 'abc',
|
140 | highlights: {
|
141 | label: [
|
142 | { start: 0, end: 1 },
|
143 | { start: 1, end: 2 },
|
144 | { start: 2, end: 3 }
|
145 | ]
|
146 | }
|
147 | };
|
148 | let result = (0, quick_input_service_1.filterItems)(items, 'abc').filter(quick_input_service_1.QuickPickItem.is);
|
149 | expect(result).length(1);
|
150 | expect(result[0].label).equal(expectation.label);
|
151 | expect((_a = result[0].highlights) === null || _a === void 0 ? void 0 : _a.label).deep.equal((_b = expectation.highlights) === null || _b === void 0 ? void 0 : _b.label);
|
152 | result = (0, quick_input_service_1.filterItems)(items, '').filter(quick_input_service_1.QuickPickItem.is);
|
153 | expect((_c = result[0].highlights) === null || _c === void 0 ? void 0 : _c.label).equal(undefined);
|
154 | });
|
155 | it('should return an empty list when no matches are found', () => {
|
156 | expect((0, quick_input_service_1.filterItems)(items, 'yyy')).deep.equal([]);
|
157 | });
|
158 | });
|
159 | });
|
160 |
|
\ | No newline at end of file |