This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathunittests.js
More file actions
660 lines (553 loc) · 33.5 KB
/
unittests.js
File metadata and controls
660 lines (553 loc) · 33.5 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, describe, it, xit, expect, beforeEach, afterEach, $, brackets */
define(function (require, exports, module) {
"use strict";
var SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
CodeHintManager = brackets.getModule("editor/CodeHintManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
FileUtils = brackets.getModule("file/FileUtils"),
testContentCSS = require("text!unittest-files/regions.css"),
testContentHTML = require("text!unittest-files/region-template.html"),
CSSCodeHints = require("main");
describe("CSS Code Hinting", function () {
var defaultContent = "@media screen { \n" +
" body { \n" +
" }\n" +
"} \n" +
".selector { \n" +
" \n" +
" b\n" +
" bord\n" +
" border-\n" +
" border-colo\n" +
" border-color: red;\n" + // line: 10
" d\n" +
" disp\n" +
" display: \n" +
" display: in\n" +
" bordborder: \n" +
" color\n" +
"} \n";
var testDocument, testEditor;
/*
* Create a mockup editor with the given content and language id.
*
* @param {string} content - content for test window
* @param {string} languageId
*/
function setupTest(content, languageId) {
var mock = SpecRunnerUtils.createMockEditor(content, languageId);
testDocument = mock.doc;
testEditor = mock.editor;
}
function tearDownTest() {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
}
// Ask provider for hints at current cursor position; expect it to return some
function expectHints(provider, implicitChar) {
expect(provider.hasHints(testEditor, implicitChar)).toBe(true);
var hintsObj = provider.getHints();
expect(hintsObj).toBeTruthy();
return hintsObj.hints; // return just the array of hints
}
// Ask provider for hints at current cursor position; expect it NOT to return any
function expectNoHints(provider, implicitChar) {
expect(provider.hasHints(testEditor, implicitChar)).toBe(false);
}
function verifyAttrHints(hintList, expectedFirstHint) {
expect(hintList.indexOf("div")).toBe(-1);
expect(hintList[0]).toBe(expectedFirstHint);
}
function selectHint(provider, expectedHint, implicitChar) {
var hintList = expectHints(provider, implicitChar);
expect(hintList.indexOf(expectedHint)).not.toBe(-1);
return provider.insertHint(expectedHint);
}
// Helper function for testing cursor position
function expectCursorAt(pos) {
var selection = testEditor.getSelection();
expect(selection.start).toEqual(selection.end);
expect(selection.start).toEqual(pos);
}
// Helper function to
// a) ensure the hintList and the list with the available values have the same size
// b) ensure that all possible values are mentioned in the hintList
function verifyAllValues(hintList, values) {
expect(hintList.length).toBe(values.length);
expect(hintList.sort().toString()).toBe(values.sort().toString());
}
describe("CSS properties in general (selection of correct property based on input)", function () {
beforeEach(function () {
// create Editor instance (containing a CodeMirror instance)
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "css");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should list all prop-name hints right after curly bracket", function () {
testEditor.setCursorPos({ line: 4, ch: 11 }); // after {
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "align-content"); // filtered on "empty string"
});
it("should list all prop-name hints in new line", function () {
testEditor.setCursorPos({ line: 5, ch: 1 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "align-content"); // filtered on "empty string"
});
it("should list all prop-name hints starting with 'b' in new line", function () {
testEditor.setCursorPos({ line: 6, ch: 2 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "backface-visibility"); // filtered on "b"
});
it("should list all prop-name hints starting with 'bord' ", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 6, ch: 2 });
testEditor.setCursorPos({ line: 7, ch: 5 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "border"); // filtered on "bord"
});
it("should list all prop-name hints starting with 'border-' ", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 7, ch: 5 });
testEditor.setCursorPos({ line: 8, ch: 8 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "border-bottom"); // filtered on "border-"
});
it("should list only prop-name hint border-color", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 8, ch: 8 });
testEditor.setCursorPos({ line: 9, ch: 12 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "border-color"); // filtered on "border-color"
expect(hintList.length).toBe(1);
});
it("should list prop-name hints at end of property-value finished by ;", function () {
testEditor.setCursorPos({ line: 10, ch: 19 }); // after ;
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "align-content"); // filtered on "empty string"
});
it("should NOT list prop-name hints right before curly bracket", function () {
testEditor.setCursorPos({ line: 4, ch: 10 }); // inside .selector, before {
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
it("should NOT list prop-name hints after declaration of mediatype", function () {
testEditor.setCursorPos({ line: 0, ch: 15 }); // after {
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
it("should NOT list prop-name hints if previous property is not closed properly", function () {
testEditor.setCursorPos({ line: 16, ch: 6 }); // cursor directly after color
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
it("should NOT list prop-name hints in media type declaration", function () {
testEditor.setCursorPos({ line: 0, ch: 1 });
expect(CSSCodeHints.cssPropHintProvider.hasHints(testEditor, 'm')).toBe(false);
});
});
describe("CSS property hint insertion", function () {
beforeEach(function () {
// create Editor instance (containing a CodeMirror instance)
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "css");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should insert colon prop-name selected", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 6, ch: 2 });
testEditor.setCursorPos({ line: 7, ch: 5 }); // cursor after 'bord'
selectHint(CSSCodeHints.cssPropHintProvider, "border");
expect(testDocument.getLine(7)).toBe(" border: ");
expectCursorAt({ line: 7, ch: 9 });
});
it("should not insert semicolon after prop-value selected", function () {
testDocument.replaceRange(";", { line: 12, ch: 5 });
testEditor.setCursorPos({ line: 13, ch: 10 }); // cursor after 'display: '
selectHint(CSSCodeHints.cssPropHintProvider, "block");
expect(testDocument.getLine(13)).toBe(" display: block");
});
it("should insert prop-name directly after semicolon", function () {
testEditor.setCursorPos({ line: 10, ch: 19 }); // cursor after red;
selectHint(CSSCodeHints.cssPropHintProvider, "align-content");
expect(testDocument.getLine(10)).toBe(" border-color: red;align-content: ");
});
it("should insert nothing but the closure(semicolon) if prop-value is fully written", function () {
testDocument.replaceRange(";", { line: 15, ch: 13 }); // insert text ;
testEditor.setCursorPos({ line: 16, ch: 6 }); // cursor directly after color
selectHint(CSSCodeHints.cssPropHintProvider, "color");
expect(testDocument.getLine(16)).toBe(" color: ");
expectCursorAt({ line: 16, ch: 8 });
});
it("should insert prop-name before an existing one", function () {
testEditor.setCursorPos({ line: 10, ch: 1 }); // cursor before border-color:
selectHint(CSSCodeHints.cssPropHintProvider, "float");
expect(testDocument.getLine(10)).toBe(" float: border-color: red;");
expectCursorAt({ line: 10, ch: 8 });
});
it("should insert prop-name before an existing one when invoked with an implicit character", function () {
testDocument.replaceRange("f", { line: 10, ch: 1 }); // insert "f" before border-color:
testEditor.setCursorPos({ line: 10, ch: 2 }); // set cursor before border-color:
selectHint(CSSCodeHints.cssPropHintProvider, "float", "f");
expect(testDocument.getLine(10)).toBe(" float: border-color: red;");
expectCursorAt({ line: 10, ch: 8 });
});
it("should replace the existing prop-value with the new selection", function () {
testDocument.replaceRange(";", { line: 12, ch: 5 });
testDocument.replaceRange("block", { line: 13, ch: 10 });
testEditor.setCursorPos({ line: 13, ch: 10 }); // cursor before block
selectHint(CSSCodeHints.cssPropHintProvider, "none");
expect(testDocument.getLine(13)).toBe(" display: none");
expectCursorAt({ line: 13, ch: 14 });
});
xit("should start new hinting whenever there is a whitespace last stringliteral", function () {
// topic: multi-value properties
// this needs to be discussed, whether or not this behaviour is aimed for
// if so, changes to CSSUtils.getInfoAt need to be done imho to classify this
testDocument.replaceRange(" ", { line: 16, ch: 6 }); // insert whitespace after color
testEditor.setCursorPos({ line: 16, ch: 7 }); // cursor one whitespace after color
selectHint(CSSCodeHints.cssPropHintProvider, "color");
expect(testDocument.getLine(16)).toBe(" color color:");
expectCursorAt({ line: 16, ch: 13 });
});
});
describe("CSS prop-value hints", function () {
beforeEach(function () {
// create Editor instance (containing a CodeMirror instance)
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "css");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should list all prop-values for 'display' after colon", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 12, ch: 5 });
testEditor.setCursorPos({ line: 13, ch: 9 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "block"); // filtered after "display:"
});
it("should list all prop-values for 'display' after colon and whitespace", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 12, ch: 5 });
testEditor.setCursorPos({ line: 13, ch: 10 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "block"); // filtered after "display: "
});
it("should list all prop-values starting with 'in' for 'display' after colon and whitespace", function () {
// insert semicolon after previous rule to avoid incorrect tokenizing
testDocument.replaceRange(";", { line: 13, ch: 10 });
testEditor.setCursorPos({ line: 14, ch: 12 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "inherit"); // filtered after "display: in"
});
it("should NOT list prop-value hints for unknown prop-name", function () {
testEditor.setCursorPos({ line: 15, ch: 12 }); // at bordborder:
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
});
describe("CSS hint provider inside mixed htmlfiles", function () {
var defaultContent = "<html> \n" +
"<head><style>.selector{display: none;}</style></head> \n" +
"<body> <style> \n" +
" body { \n" +
" background-color: red; \n" +
" \n" +
"} \n" +
"</style>\n" +
"<div class='selector'></div>\n" +
"<style> .foobar { \n" +
" colo </style>\n" +
"</body></html>";
beforeEach(function () {
// create dummy Document for the Editor
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "html");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should list prop-name hints right after curly bracket", function () {
testEditor.setCursorPos({ line: 3, ch: 7 }); // inside body-selector, after {
expectHints(CSSCodeHints.cssPropHintProvider);
});
it("should list prop-name hints inside single-line styletags at start", function () {
testEditor.setCursorPos({ line: 1, ch: 23 }); // inside style, after {
expectHints(CSSCodeHints.cssPropHintProvider);
});
it("should list prop-name hints inside single-line styletags after semicolon", function () {
testEditor.setCursorPos({ line: 1, ch: 37 }); // inside style, after ;
expectHints(CSSCodeHints.cssPropHintProvider);
});
it("should list prop-name hints inside multi-line styletags with cursor in first line", function () {
testEditor.setCursorPos({ line: 9, ch: 18 }); // inside style, after {
expectHints(CSSCodeHints.cssPropHintProvider);
});
it("should list prop-name hints inside multi-line styletags with cursor in last line", function () {
testEditor.setCursorPos({ line: 10, ch: 5 }); // inside style, after colo
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "color"); // filtered on "colo"
expect(hintList.length).toBe(1);
});
it("should NOT list prop-name hints between closed styletag and new opening styletag", function () {
testEditor.setCursorPos({ line: 8, ch: 0 }); // right before <div
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
it("should NOT list hints right before curly bracket", function () {
testEditor.setCursorPos({ line: 3, ch: 6 }); // inside body-selector, before {
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
it("should NOT list hints inside head-tag", function () {
testEditor.setCursorPos({ line: 1, ch: 6 }); // between <head> and </head> {
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
});
describe("CSS hint provider in other filecontext (e.g. javascript)", function () {
var defaultContent = "function foobar (args) { \n " +
" /* do sth */ \n" +
" return 1; \n" +
"} \n";
beforeEach(function () {
// create dummy Document for the Editor
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "javascript");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should NOT list hints after function declaration", function () {
testEditor.setCursorPos({ line: 0, ch: 24 }); // after { after function declaration
expectNoHints(CSSCodeHints.cssPropHintProvider);
});
});
describe("CSS hint provider cursor placement inside value functions", function () {
var defaultContent = ".selector { \n" + // line 0
"shape-inside:\n" + // line 1
"}\n"; // line 2
beforeEach(function () {
// create dummy Document for the Editor
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "css");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should should place the cursor between the parens of the value function", function () {
var expectedString = "shape-inside:polygon()";
testEditor.setCursorPos({ line: 1, ch: 15 }); // after shape-inside
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
selectHint(CSSCodeHints.cssPropHintProvider, "polygon()");
expect(testDocument.getLine(1).length).toBe(expectedString.length);
expect(testDocument.getLine(1)).toBe(expectedString);
expectCursorAt({ line: 1, ch: expectedString.length - 1 });
});
});
describe("CSS hint provider for regions and exclusions", function () {
var defaultContent = ".selector { \n" + // line 0
" shape-inside: \n;" + // line 1
" shape-outside: \n;" + // line 2
" region-fragment: \n;" + // line 3
" region-break-after: \n;" + // line 4
" region-break-inside: \n;" + // line 5
" region-break-before: \n;" + // line 6
" -ms-region\n;" + // line 7
" -webkit-region\n;" + // line 8
" flow-from: \n;" + // line 9
" flow-into: \n;" + // line 10
"}\n"; // line 11
beforeEach(function () {
// create dummy Document for the Editor
var mock = SpecRunnerUtils.createMockEditor(defaultContent, "css");
testEditor = mock.editor;
testDocument = mock.doc;
});
afterEach(function () {
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
});
it("should list 7 value-name hints for shape-inside", function () {
testEditor.setCursorPos({ line: 1, ch: 15 }); // after shape-inside
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "auto"); // first hint should be auto
verifyAllValues(hintList, ["auto", "circle()", "ellipse()", "inherit", "outside-shape", "polygon()", "rectangle()"]);
});
it("should list 6 value-name hints for shape-outside", function () {
testEditor.setCursorPos({ line: 2, ch: 16 }); // after shape-outside
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "auto"); // first hint should be auto
verifyAllValues(hintList, ["auto", "rectangle()", "circle()", "ellipse()", "polygon()", "inherit"]);
});
it("should list 2 value-name hints for region-fragment", function () {
testEditor.setCursorPos({ line: 3, ch: 18 }); // after region-fragment
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "auto"); // first hint should be auto
verifyAllValues(hintList, ["auto", "break"]);
});
it("should list 11 value-name hints for region-break-after", function () {
testEditor.setCursorPos({ line: 4, ch: 21 }); // after region-break-after
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "always"); // first hint should be always
verifyAllValues(hintList, ["always", "auto", "avoid", "avoid-column", "avoid-page", "avoid-region", "column", "left", "page", "region", "right"]);
});
it("should list 5 value-name hints for region-break-inside", function () {
testEditor.setCursorPos({ line: 5, ch: 22 }); // after region-break-inside
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "auto"); // first hint should be auto
verifyAllValues(hintList, ["auto", "avoid", "avoid-column", "avoid-page", "avoid-region"]);
});
it("should list 11 value-name hints for region-break-before", function () {
testEditor.setCursorPos({ line: 6, ch: 23 }); // after region-break-before
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "always"); // first hint should be always
verifyAllValues(hintList, ["always", "auto", "avoid", "avoid-column", "avoid-page", "avoid-region", "column", "left", "page", "region", "right"]);
});
// TODO: Need to add vendor prefixed properties for CSS code hint provider.
xit("should list 4 value-name hints for vendor prefixed region-* properties", function () {
testEditor.setCursorPos({ line: 7, ch: 16 }); // after -ms-region
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "region-break-after"); // first hint should be region-break-after
verifyAllValues(hintList, ["region-break-after", "region-break-before", "region-break-inside", "region-fragment"]);
testEditor.setCursorPos({ line: 8, ch: 20 }); // after -webkit-region
hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "region-break-after"); // first hint should be region-break-after
verifyAllValues(hintList, ["region-break-after", "region-break-before", "region-break-inside", "region-fragment"]);
});
it("should list 2 value-name hints for flow-from", function () {
testEditor.setCursorPos({ line: 9, ch: 12 }); // after flow-from
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "inherit"); // first hint should be inherit
verifyAllValues(hintList, ["inherit", "none"]);
});
it("should list 1 value-name hint for flow-into", function () {
testEditor.setCursorPos({ line: 10, ch: 12 }); // after flow-into
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "none"); // first hint should be none
verifyAllValues(hintList, ["none"]);
});
});
describe("Named flow hints for flow-into and flow-from properties in a CSS file", function () {
beforeEach(function () {
setupTest(testContentCSS, "css");
});
afterEach(function () {
tearDownTest();
});
it("should list more than 2 value hints for flow-from", function () {
testEditor.setCursorPos({ line: 66, ch: 15 }); // after flow-from
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "edge-code_now_shipping"); // first hint should be edge-code_now_shipping
verifyAllValues(hintList, ["edge-code_now_shipping", "inherit", "jeff", "lim", "main", "none", "randy"]);
});
it("should list more than 1 value hint for flow-into", function () {
testEditor.setCursorPos({ line: 77, ch: 4 });
selectHint(CSSCodeHints.cssPropHintProvider, "flow-into");
expect(testDocument.getLine(77)).toBe(" flow-into: ");
expectCursorAt({ line: 77, ch: 15 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "edge-code_now_shipping"); // first hint should be edge-code_now_shipping
verifyAllValues(hintList, ["edge-code_now_shipping", "jeff", "lim", "main", "none", "randy"]);
});
it("should NOT include partially entered named flow value in hint list", function () {
// Insert a letter for a new named flow after flow-from: on line 66
testDocument.replaceRange("m", { line: 66, ch: 15 });
testEditor.setCursorPos({ line: 66, ch: 16 }); // after flow-from: m
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAllValues(hintList, ["main"]);
});
});
describe("Named flow hints inside a style block of an HTML", function () {
beforeEach(function () {
setupTest(testContentHTML, "html");
});
afterEach(function () {
tearDownTest();
});
it("should include only 2 named flows available in the style block for flow-from", function () {
testEditor.setCursorPos({ line: 28, ch: 21 }); // after flow-from
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "article"); // first hint should be article
verifyAllValues(hintList, ["article", "inherit", "none", "regionC"]);
});
it("should include only 2 named flows available in the style block for flow-into", function () {
testEditor.setCursorPos({ line: 34, ch: 21 });
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAttrHints(hintList, "article"); // first hint should be article
verifyAllValues(hintList, ["article", "none", "regionC"]);
});
it("should NOT include partially entered named flow value in hint list", function () {
// Insert a letter for a new named flow after flow-from: on line 28
testDocument.replaceRange("m", { line: 28, ch: 21 });
testEditor.setCursorPos({ line: 28, ch: 22 }); // after flow-from: m
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
verifyAllValues(hintList, []);
});
it("should NOT show named flow available inisde HTML text", function () {
// Insert a letter for a new named flow after flow-from: on line 28
testDocument.replaceRange("some", { line: 28, ch: 21 });
testEditor.setCursorPos({ line: 28, ch: 25 }); // after flow-from: some
var hintList = expectHints(CSSCodeHints.cssPropHintProvider);
// some-named-flow should not be in the hint list since it is inside HTML text
verifyAllValues(hintList, []);
});
});
describe("Should not invoke CSS hints on space key", function () {
beforeEach(function () {
setupTest(testContentHTML, "html");
});
afterEach(function () {
tearDownTest();
});
it("should not trigger CSS property name hints with space key", function () {
testEditor.setCursorPos({ line: 25, ch: 11 }); // after {
expectNoHints(CSSCodeHints.cssPropHintProvider, " ");
});
it("should not trigger CSS property value hints with space key", function () {
testEditor.setCursorPos({ line: 28, ch: 21 }); // after flow-from
expectNoHints(CSSCodeHints.cssPropHintProvider, " ");
});
});
});
});