forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSSInlineEdit-integ-test.js
More file actions
836 lines (615 loc) · 41.7 KB
/
CSSInlineEdit-integ-test.js
File metadata and controls
836 lines (615 loc) · 41.7 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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2014 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global describe, it, expect, beforeEach, afterEach, awaitsForDone, beforeAll, afterAll, spyOn */
define(function (require, exports, module) {
var SpecRunnerUtils = require("spec/SpecRunnerUtils"),
Strings = require("strings");
var testPath = SpecRunnerUtils.getTestPath("/spec/CSSInlineEdit-test-files");
// TODO: overlaps a lot with MultiRangeInlineEditor-test integration suite
describe("LegacyInteg:CSS Inline Edit", function () {
var testWindow,
brackets,
$,
EditorManager,
CommandManager,
DocumentManager,
PreferencesManager,
Commands,
FileSystem,
Dialogs;
beforeAll(async function () {
testWindow = await SpecRunnerUtils.createTestWindowAndRun({forceReload: true});
$ = testWindow.$;
brackets = testWindow.brackets;
EditorManager = brackets.test.EditorManager;
CommandManager = brackets.test.CommandManager;
FileSystem = brackets.test.FileSystem;
Dialogs = brackets.test.Dialogs;
DocumentManager = brackets.test.DocumentManager;
PreferencesManager = brackets.test.PreferencesManager;
Commands = brackets.test.Commands;
await SpecRunnerUtils.loadProjectInTestWindow(testPath);
}, 30000);
afterAll(async function () {
EditorManager = null;
CommandManager = null;
DocumentManager = null;
PreferencesManager = null;
Commands = null;
Dialogs = null;
FileSystem = null;
testWindow = null;
await SpecRunnerUtils.closeTestWindow();
}, 30000);
function dropdownButton() {
return $(".btn.btn-dropdown.btn-mini.stylesheet-button");
}
function dropdownMenu() {
return $(".dropdown-menu.dropdownbutton-popup");
}
function getInlineEditorWidgets() {
return EditorManager.getCurrentFullEditor().getInlineWidgets();
}
function inlineEditorMessage(index) {
if (index === undefined) {
index = 0;
}
return getInlineEditorWidgets()[index].$messageDiv;
}
function inlineEditorFileName(inlineWidget) {
var name = inlineWidget.$header.find("a.filename")[0].text;
if (name[0] === "•") {
// remove dirty dot
name = name.slice(1);
}
return name;
}
function getRelatedFiles(inlineWidget) {
return inlineWidget.$relatedContainer.find(".related ul>li:not(.section-header)");
}
function getRuleListSections(inlineWidget) {
return inlineWidget.$relatedContainer.find("li.section-header");
}
function expectListItem($ruleListItem, ruleLabel, filename, lineNum) { // TODO: duplicated with MultiRangeInlineEditor-test
expect($ruleListItem.text()).toBe(ruleLabel + " :" + lineNum);
expect($ruleListItem.data("filename")).toBe(filename);
}
async function loadFile(file) {
var promise = SpecRunnerUtils.openProjectFiles([file]);
await awaitsForDone(promise);
}
async function closeFilesInTestWindow() {
var promise = CommandManager.execute(Commands.FILE_CLOSE_ALL);
await awaitsForDone(promise, "Close all open files in working set");
}
function checkAvailableStylesheets(availableFilesInDropdown) {
// LESS/SCSS files are sorted above all CSS files. Files are otherwise sorted by path & then filename.
expect(availableFilesInDropdown.length).toBe(6);
expect(availableFilesInDropdown[1].textContent).toEqual("test.less");
expect(availableFilesInDropdown[2].textContent).toEqual("test2.less");
expect(availableFilesInDropdown[3].textContent).toEqual("test.scss");
expect(availableFilesInDropdown[4].textContent).toEqual("test.css");
expect(availableFilesInDropdown[5].textContent).toEqual("test2.css");
}
function getInlineEditorContent(ranges) {
var document = ranges.textRange.document;
return document.getRange({line: ranges.textRange.startLine, ch: 0}, {line: ranges.textRange.endLine, ch: document.getLine(ranges.textRange.endLine).length});
}
describe("CSS", function () {
function resetCollapsedPrefs() {
PreferencesManager.setViewState("inlineEditor.collapsedFiles", {}, PreferencesManager.STATE_PROJECT_CONTEXT);
}
function makeInitiallyCollapsed(fullPath) {
var setting = PreferencesManager.getViewState("inlineEditor.collapsedFiles", PreferencesManager.STATE_PROJECT_CONTEXT) || {};
setting[fullPath] = true;
PreferencesManager.setViewState("inlineEditor.collapsedFiles", setting, PreferencesManager.STATE_PROJECT_CONTEXT);
}
beforeEach(async function () {
resetCollapsedPrefs();
await loadFile("index-css.html");
});
afterEach(async function () {
await closeFilesInTestWindow();
});
it("should open two inline editors and show the matching rules", async function () {
var inlineWidgets;
let editor = EditorManager.getCurrentFullEditor();
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(editor,
{line: 15, ch: 22});
var promise2 = SpecRunnerUtils.toggleQuickEditAtOffset(editor,
{line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor 1");
await awaitsForDone(promise2, "Open inline editor 2");
inlineWidgets = getInlineEditorWidgets();
// Check Inline Editor 1
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.css : 1");
var ranges = inlineWidgets[0]._ranges[0];
var document = ranges.textRange.document;
expect(document.getRange({line: ranges.textRange.startLine, ch: 0}, {line: ranges.textRange.endLine, ch: document.getLine(ranges.textRange.endLine).length})).toEqual(".standard {\n background-color: red;\n}");
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(2);
expectListItem(files.eq(0), ".standard", "test.css", 1);
expectListItem(files.eq(1), ".standard", "test2.css", 1);
// Check Inline Editor 2
expect(inlineEditorFileName(inlineWidgets[1])).toEqual("test.css : 8");
ranges = inlineWidgets[1]._ranges[0];
document = ranges.textRange.document;
expect(document.getRange({line: ranges.textRange.startLine, ch: 0}, {line: ranges.textRange.endLine, ch: document.getLine(ranges.textRange.endLine).length})).toEqual(".banner-new {\n background-color: blue;\n}");
files = getRelatedFiles(inlineWidgets[1]);
expect(files.length).toBe(2);
expectListItem(files.eq(0), ".banner-new", "test.css", 8);
expectListItem(files.eq(1), ".banner-new", "test2.css", 8);
}, 100000);
it("should show no matching rule in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 16, ch: 7});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
// verify New Rule dropdown contents
dropdownButton().click();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineWidget._getSelectedRange()).toBe(null);
expect(inlineWidget.editor).toBeNull();
expect(inlineEditorMessage().html()).toEqual(Strings.CSS_QUICK_EDIT_NO_MATCHES);
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(0); // rule list hidden
});
it("should show one matching rule in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 17, ch: 15});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(1);
// verify New Rule dropdown contents
dropdownButton().click();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineEditorFileName(inlineWidget)).toEqual("test.less : 5");
var range = inlineWidget._ranges[0].textRange;
var document = range.document;
expect(document.getRange({line: range.startLine, ch: 0}, {line: range.endLine, ch: document.getLine(range.endLine).length})).toEqual(".banner {\n background-color: red;\n}");
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(0); // rule list hidden
});
it("should show first matching rule of two files", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(2);
// verify New Rule dropdown contents
dropdownButton().click();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineEditorFileName(inlineWidget)).toEqual("test.css : 8");
var range = inlineWidget._ranges[0].textRange;
var document = range.document;
expect(document.getRange({line: range.startLine, ch: 0}, {line: range.endLine, ch: document.getLine(range.endLine).length})).toEqual(".banner-new {\n background-color: blue;\n}");
var files = getRelatedFiles(inlineWidget);
expect(files.length).toBe(2);
expectListItem(files.eq(0), ".banner-new", "test.css", 8);
expectListItem(files.eq(1), ".banner-new", "test2.css", 8);
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(1);
});
it("should collapse section without changing selection, and remember collapsed state", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(2);
expect(inlineEditorFileName(inlineWidget)).toEqual("test.css : 8");
var $ruleListSections = getRuleListSections(inlineWidget);
expect($ruleListSections.eq(0).text()).toBe("test.css (1)");
expect($ruleListSections.eq(1).text()).toBe("test2.css (1)");
expect($ruleListSections.eq(0).find(".disclosure-triangle.expanded").length).toBe(1); // test.css is expanded
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css is expanded
// Collapse test.css section (which contains the selection)
$ruleListSections.eq(0).click();
$ruleListSections = getRuleListSections(inlineWidget);
expect($ruleListSections.eq(0).text()).toBe("test.css (1)");
expect($ruleListSections.eq(1).text()).toBe("test2.css (1)");
expect($ruleListSections.eq(0).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test.css is now collapsed
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css is expanded
// File in collapsed section is still selected - selection unchanged
expect(inlineEditorFileName(inlineWidget)).toEqual("test.css : 8");
// Close the inline editor
await awaitsForDone(inlineWidget.close());
// Reopen it
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(2);
// Verify that collapsed section is still collapsed
var $ruleListSections = getRuleListSections(inlineWidget);
expect($ruleListSections.eq(0).text()).toBe("test.css (1)");
expect($ruleListSections.eq(1).text()).toBe("test2.css (1)");
expect($ruleListSections.eq(0).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test.css is still collapsed
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css is expanded
});
it("should initially select first non-collapsed result, and not change selection when expanding other groups", async function () {
makeInitiallyCollapsed(testPath + "/css/test.css");
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(2);
var $ruleListSections = getRuleListSections(inlineWidget);
expect($ruleListSections.eq(0).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test.css is collapsed
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css is expanded
expect(inlineEditorFileName(inlineWidget)).toEqual("test2.css : 8");
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(1);
// Opening a collapsed section shouldn't change the existing selection
$ruleListSections.eq(0).click();
expect($ruleListSections.eq(0).find(".disclosure-triangle.expanded").length).toBe(1); // test.css now expanded
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css still expanded
expect(inlineEditorFileName(inlineWidget)).toEqual("test2.css : 8");
});
it("should select nothing if all results collapsed with least 2 results, and auto-select a result on expand", async function () {
makeInitiallyCollapsed(testPath + "/css/test.css");
makeInitiallyCollapsed(testPath + "/css/test2.css");
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(2);
var $ruleListSections = getRuleListSections(inlineWidget);
expect($ruleListSections.eq(0).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test.css is collapsed
expect($ruleListSections.eq(1).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test2.css is collapsed
expect(inlineWidget._getSelectedRange()).toBe(null);
expect(inlineWidget.editor).toBeNull();
expect(inlineEditorMessage().html()).toEqual(Strings.INLINE_EDITOR_HIDDEN_MATCHES);
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(1); // rule list still visible though
// Opening a collapsed section should select its first result
$ruleListSections.eq(1).click();
expect($ruleListSections.eq(0).find(".disclosure-triangle:not(.expanded)").length).toBe(1); // test.css still collapsed
expect($ruleListSections.eq(1).find(".disclosure-triangle.expanded").length).toBe(1); // test2.css now expanded
expect(inlineWidget._getSelectedRange()).toBeTruthy();
expect(inlineEditorFileName(inlineWidget)).toEqual("test2.css : 8");
});
it("should select collapsed result anyway if there's only one result total", async function () {
makeInitiallyCollapsed(testPath + "/less/test.less");
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 17, ch: 15});
await awaitsForDone(promise, "Open inline editor");
var inlineWidget = getInlineEditorWidgets()[0];
expect(inlineWidget._ranges.length).toBe(1);
expect(inlineEditorFileName(inlineWidget)).toEqual("test.less : 5");
expect(inlineWidget.$htmlContent.find(".related-container").length).toBe(0); // rule list hidden
});
it("should add the css file to the working set when modified in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 48, ch: 25});
await awaitsForDone(promise, "Open inline editor");
spyOn(Dialogs, 'showModalDialog').and.callFake(function (dlgClass, title, message, buttons) {
return {done: function (callback) { callback(Dialogs.DIALOG_BTN_DONTSAVE); } };
});
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 57");
var document = inlineWidgets[0].editor.document;
// modify scss to add it to the working set
document.setText(".comment-scss-4 {\n background-color: black;\n}");
expect(DocumentManager.findInWorkingSet(testPath + "/scss/test.scss")).toBeGreaterThan(0);
});
});
describe("LESS", function () {
beforeEach(async function () {
await loadFile("index-less.html");
});
afterEach(async function () {
await closeFilesInTestWindow();
});
it("should show no matching rule in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 16, ch: 10});
await awaitsForDone(promise, "Open inline editor");
// open the dropdown
dropdownButton().click();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineEditorMessage().html()).toEqual(Strings.CSS_QUICK_EDIT_NO_MATCHES);
});
it("should show one matching rule in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 17, ch: 15});
await awaitsForDone(promise, "Open inline editor");
// open the dropdown
dropdownButton().click();
var inlineWidgets = getInlineEditorWidgets();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.less : 5");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".banner {\n background-color: red;\n}");
});
it("should show one matching rule in two files", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 20, ch: 25});
await awaitsForDone(promise, "Open inline editor");
// open the dropdown
dropdownButton().click();
var inlineWidgets = getInlineEditorWidgets();
var availableFilesInDropdown = dropdownMenu().children();
checkAvailableStylesheets(availableFilesInDropdown);
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.less : 9");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" &.banner-new2 {\n background-color: blue;\n }");
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(2);
expectListItem(files.eq(0), "div / &.banner-new2", "test.less", 9);
expectListItem(files.eq(1), ".banner-new2", "test2.less", 1);
});
describe("Check Rule appearance with matches in one LESS file", function () {
it("should return the nested rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 25, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 11");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" .level3 {\n color: red;\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".level1 / .level2 / .level3", "test2.less", 11);
});
it("should show matching rule with comment above containing delimiter chars", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 37, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 44");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".confuse1 {\n /* {this comment is special(;:,)} */\n .special {\n color: #ff8000;\n }\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".confuse1", "test2.less", 44);
});
it("should show matching rule without delimiting whitespace (compressed)", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 44, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 51");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".compressed{color:red}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".compressed", "test2.less", 51);
});
});
describe("Comments", function () {
it("should show matching sub rule with comment above containing delimiter chars", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 39, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 45");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" /* {this comment is special(;:,)} */\n .special {\n color: #ff8000;\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".confuse1 / .special", "test2.less", 45);
});
it("should show the single line block style comment above the matching rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 31, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 17");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("/* This is a single line block comment that should appear in the inline editor as first line */\n.comment1 {\n text-align: center;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".comment1", "test2.less", 17);
});
it("should show the single line inline comment above the matching rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 34, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 33");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("// This is a single line comment that should appear in the inline editor as first line\n.comment4 {\n text-align: center;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".comment4", "test2.less", 33);
});
it("should show the multi line block comment above the matching rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 32, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 22");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("/* This is a multiline block comment\n * that should appear in the inline editor\n */\n.comment2 {\n text-decoration: overline;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".comment2", "test2.less", 22);
});
it("should show the end of line comment after the matching rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 33, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 29");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".comment3 {\n text-decoration: underline; /* EOL comment {}(,;:) */\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".comment3", "test2.less", 29);
});
});
describe("Selector groups", function () {
it("should show matching selector group", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 49, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 55");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" .uno, .dos {\n color: red\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".uno, .dos", "test2.less", 55);
});
it("should show 1 matching rule of selector group", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 50, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 55");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" .uno, .dos {\n color: red\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(2);
expectListItem(files.eq(0), ".uno, .dos", "test2.less", 55);
expectListItem(files.eq(1), "#main / .dos", "test2.less", 59);
});
it("should show matching selector group with selectors on separate lines", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 54, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 65");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" .tres,\n .quattro {\n color: blue;\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".tres, .quattro", "test2.less", 65);
});
});
describe("Mixins", function () {
it("should show matching mixin rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 64, ch: 30});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 86");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".mixina-class {\n .a();\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".mixina-class", "test2.less", 86);
});
it("should show matching rule which includes mixin with default parameter", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 71, ch: 20});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 120");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("#header-mixin-paramterized-default {\n .border-radius;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), "#header-mixin-paramterized-default", "test2.less", 120);
});
it("should show matching rule which includes a parameterized mixin", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 73, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 126");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" #header-mixin-paramterized-custom-1 {\n .border-radius(20px);\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), "#header-mixin-paramterized-custom / #header-mixin-paramterized-custom-1", "test2.less", 126);
});
});
describe("Interpolation", function () {
// Verify https://github.com/adobe/brackets/issues/8865
it("should show a rule with variable interpolation in one of its property names", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 67, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test2.less : 109");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(".widget {\n @{property}: #0ee;\n background-@{property}: #999;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".widget", "test2.less", 109);
});
});
});
describe("SCSS", function () {
beforeEach(async function () {
await loadFile("index-css.html");
});
afterEach(async function () {
await closeFilesInTestWindow();
});
// The following tests will succeed, but once the issue is fixed they will fail
it("should show one matching rule in inline editor", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 25, ch: 10});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 5");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("p {\n $font-size: 12px;\n $line-height: 30px;\n font: #{$font-size}/#{$line-height};\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), "p", "test.scss", 5);
});
// https://github.com/adobe/brackets/issues/8875
it("should show one matching rule in inline editor which is defined after rule that uses variable interpolation as property value", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 28, ch: 20});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 11");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("#scss-1 {\n background-color: blue;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), "#scss-1", "test.scss", 11);
});
// https://github.com/adobe/brackets/issues/8895
it("should show one matching rule that is defined with parent selector", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 38, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 20");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual(" &-ok {\n background-image: url(\"ok.png\");\n }");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".button / &-ok", "test.scss", 20);
});
// https://github.com/adobe/brackets/issues/8851
it("should show matching rules that follow rules using variable interpolation in a selector", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 42, ch: 10});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 37");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("a {\n color: blue;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), "a", "test.scss", 37);
});
describe("Comments", function () {
it("should show single line comment above matching rule", async function () {
var promise = SpecRunnerUtils.toggleQuickEditAtOffset(EditorManager.getCurrentFullEditor(), {line: 45, ch: 25});
await awaitsForDone(promise, "Open inline editor");
var inlineWidgets = getInlineEditorWidgets();
expect(inlineEditorFileName(inlineWidgets[0])).toEqual("test.scss : 41");
var ranges = inlineWidgets[0]._ranges[0];
expect(getInlineEditorContent(ranges)).toEqual("// This is a single line comment\n.comment-scss-1 {\n background-color: red;\n}");
// It's not visible
var files = getRelatedFiles(inlineWidgets[0]);
expect(files.length).toBe(1);
expectListItem(files.eq(0), ".comment-scss-1", "test.scss", 41);
});
});
});
});
});