-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathPresetsSettingsPropertyCompletionProvider.spec.ts
161 lines (150 loc) · 4.72 KB
/
PresetsSettingsPropertyCompletionProvider.spec.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { describe, it, expect, assert, beforeEach } from 'vitest';
import { JSONLanguageService } from '../../JSONLanguageService';
import { DocumentManager } from '../../../documents';
import {
getRequestParams,
isCompletionList,
mockJSONLanguageService,
} from '../../test/test-helpers';
describe('Unit: PresetsSettingsPropertyCompletionProvider', () => {
const rootUri = 'file:///root/';
let jsonLanguageService: JSONLanguageService;
let documentManager: DocumentManager;
beforeEach(async () => {
documentManager = new DocumentManager(
undefined, // don't need a fs
undefined, // don't need a connection
undefined, // don't need client capabilities
async () => 'theme', // 'theme' mode
async () => false, // schema is invalid for tests
);
jsonLanguageService = mockJSONLanguageService(
rootUri,
documentManager,
async (uri: string) => ({
general: {
fake: 'Fake Setting',
},
}),
);
await jsonLanguageService.setup({
textDocument: {
completion: {
contextSupport: true,
completionItem: {
snippetSupport: true,
commitCharactersSupport: true,
documentationFormat: ['markdown'],
deprecatedSupport: true,
preselectSupport: true,
},
},
},
});
});
describe('valid schema', () => {
it('completes preset setting property when settings exist', async () => {
const source = `
{% schema %}
{
"settings": [
{"id": "custom-setting"},
{"id": "fake-setting"},
{},
],
"presets": [{
"settings": {
"█": "",
}
}]
}
{% endschema %}
`;
const params = getRequestParams(documentManager, 'blocks/block.liquid', source);
const completions = await jsonLanguageService.completions(params);
assert(isCompletionList(completions));
expect(completions.items).to.have.lengthOf(2);
expect(completions.items.map((item) => item.label)).to.include.members([
`"custom-setting"`,
`"fake-setting"`,
]);
});
it('offers no suggestions for preset setting property when there are no settings', async () => {
const source = `
{% schema %}
{
"presets": [{
"settings": {
"█": "",
}
}]
}
{% endschema %}
`;
const params = getRequestParams(documentManager, 'blocks/block.liquid', source);
const completions = await jsonLanguageService.completions(params);
assert(isCompletionList(completions));
expect(completions.items).to.have.lengthOf(0);
expect(completions.items.map((item) => item.label)).to.include.members([]);
});
it('offers presets setting completion with docs from setting.label', async () => {
const source = `
{% schema %}
{
"settings": [
{"id": "custom-setting", "label": "Custom Setting"},
{"id": "fake-setting", "label": "t:general.fake"},
],
"presets": [{
"settings": {
"█": "",
}
}]
}
{% endschema %}
`;
const params = getRequestParams(documentManager, 'blocks/block.liquid', source);
const completions = await jsonLanguageService.completions(params);
assert(isCompletionList(completions));
expect(completions.items).to.have.lengthOf(2);
expect(completions.items).toEqual(
expect.arrayContaining([
expect.objectContaining({
documentation: { kind: 'markdown', value: 'Custom Setting' },
}),
expect.objectContaining({
documentation: { kind: 'markdown', value: 'Fake Setting' },
}),
]),
);
});
});
describe('invalid schema', () => {
it('completes preset setting property when settings exist and schema has small errors', async () => {
const source = `
{% schema %}
{
"settings": [
{"id": "custom-setting"},
{"id": "fake-setting"},
{},
],
"presets": [{
"settings": {
"█"
}
}]
}
{% endschema %}
`;
const params = getRequestParams(documentManager, 'blocks/block.liquid', source);
const completions = await jsonLanguageService.completions(params);
assert(isCompletionList(completions));
expect(completions.items).to.have.lengthOf(2);
expect(completions.items.map((item) => item.label)).to.include.members([
`"custom-setting"`,
`"fake-setting"`,
]);
});
});
});