forked from adobe/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittests.js
More file actions
856 lines (698 loc) · 36.2 KB
/
unittests.js
File metadata and controls
856 lines (698 loc) · 36.2 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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
/*
* 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, expect, beforeEach, afterEach, beforeFirst, afterLast, waitsFor, runs, brackets, waitsForDone */
define(function (require, exports, module) {
"use strict";
// Modules from the SpecRunner window
var MasterDocumentManager = brackets.getModule("document/DocumentManager"),
MasterMainViewManager = brackets.getModule("view/MainViewManager"),
FileUtils = brackets.getModule("file/FileUtils"),
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
UrlCodeHints = require("main");
describe("Url Code Hinting", function () {
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testHtmlPath = extensionPath + "/testfiles/test.html",
testCssPath = extensionPath + "/testfiles/subfolder/test.css",
testScssPath = extensionPath + "/testfiles/subfolder/test.scss",
testDocument,
testEditor,
hintsObj;
// IMPORTANT: By default, Mac sorts folder contents differently from other OS's,
// so the files and folders in the "testfiles" and "subfolder" folder are named
// strategically so that they sort the same on all OS's (i.e. folders are listed
// first, and then files), but this is not true for UrlCodeHints folder.
var testfilesDirHints = [ "subfolder/", "test.html"],
subfolderDirHints = [ "chevron.png", "test.css", "test.js", "test.scss"],
UrlCodeHintsDirHintsMac = [ "../data.json", "../main.js", "../testfiles/", "../unittests.js"],
UrlCodeHintsDirHints = [ "../testfiles/", "../data.json", "../main.js", "../unittests.js"];
/**
* Returns an Editor suitable for use in isolation, given a Document.
*
* @param {Document} doc - the document to be contained by the new Editor
* @return {Editor} - the mock editor object
*/
function createMockEditor(doc) {
return SpecRunnerUtils.createMockEditorForDocument(doc);
}
function setupTests(testFilePath) {
runs(function () {
MasterDocumentManager.getDocumentForPath(testFilePath).done(function (doc) {
testDocument = doc;
});
});
waitsFor(function () {
return (testDocument);
}, "Unable to open test document", 2000);
// create Editor instance (containing a CodeMirror instance)
runs(function () {
testEditor = createMockEditor(testDocument);
MasterMainViewManager._edit(MasterMainViewManager.ACTIVE_PANE, testDocument);
});
}
function tearDownTests() {
runs(function () {
// The following call ensures that the document is reloaded
// from disk before each test
MasterMainViewManager._closeAll(MasterMainViewManager.ALL_PANES);
SpecRunnerUtils.destroyMockEditor(testDocument);
testEditor = null;
testDocument = null;
hintsObj = null;
});
}
// Helper method to ask provider for hints at current cursor position.
// Provider returns either an array of hints, or a deferred promise.
// If a promise is returned, wait for it to resolve.
//
// Since this may be async, it cannot return the hints list, so it depends
// on the hintsObj variable (with module scope) to exist.
function expectAsyncHints(provider) {
runs(function () {
expect(provider.hasHints(testEditor, null)).toBe(true);
hintsObj = provider.getHints();
expect(hintsObj).toBeTruthy();
});
runs(function () {
if (hintsObj instanceof Object && hintsObj.hasOwnProperty("done")) {
hintsObj.done(function (resolvedHintsObj) {
hintsObj = resolvedHintsObj;
});
}
});
waitsFor(function () {
return (!hintsObj || hintsObj.hints);
}, "Unable to resolve hints", 2000);
}
// Ask provider for hints at current cursor position; expect it NOT to return any
function expectNoHints(provider) {
expect(provider.hasHints(testEditor, null)).toBeFalsy();
}
// Expect hintList to contain folder and file names.
function verifyUrlHints(hintList, expectedHints) {
expect(hintList).toEqual(expectedHints);
}
describe("HTML Url Code Hints", function () {
beforeFirst(function () {
setupTests(testHtmlPath);
});
afterLast(function () {
tearDownTests();
});
it("should hint for href attribute", function () {
runs(function () {
testEditor.setCursorPos({ line: 14, ch: 12 });
// Must reset hintsObj before every call to expectAsyncHints()
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should hint for src attribute", function () {
runs(function () {
testEditor.setCursorPos({ line: 15, ch: 13 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should not hint for type attribute", function () {
runs(function () {
testEditor.setCursorPos({ line: 15, ch: 21 });
expectNoHints(UrlCodeHints.hintProvider);
});
});
it("should not hint in query part of url", function () {
runs(function () {
testEditor.setCursorPos({ line: 20, ch: 31 });
expectNoHints(UrlCodeHints.hintProvider);
});
});
it("should hint up 1 folder for '../'", function () {
runs(function () {
testEditor.setCursorPos({ line: 21, ch: 14 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
var expectedHints = (brackets.platform !== "win") ? UrlCodeHintsDirHintsMac : UrlCodeHintsDirHints;
verifyUrlHints(hintsObj.hints, expectedHints);
});
});
});
describe("CSS Url Code Hints", function () {
beforeFirst(function () {
setupTests(testHtmlPath);
});
afterLast(function () {
tearDownTests();
});
it("should hint for @import url()", function () {
runs(function () {
testEditor.setCursorPos({ line: 4, ch: 12 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should hint for background-image: url()", function () {
runs(function () {
testEditor.setCursorPos({ line: 6, ch: 24 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should hint for border-image: url('')", function () {
runs(function () {
testEditor.setCursorPos({ line: 7, ch: 21 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should hint for list-style-image: url(\"\")", function () {
runs(function () {
testEditor.setCursorPos({ line: 8, ch: 25 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, testfilesDirHints);
});
});
it("should not hint for @import outside of url()", function () {
runs(function () {
testEditor.setCursorPos({ line: 4, ch: 15 });
expectNoHints(UrlCodeHints.hintProvider);
});
});
it("should not hint for background-image outside of url()", function () {
runs(function () {
testEditor.setCursorPos({ line: 11, ch: 20 });
expectNoHints(UrlCodeHints.hintProvider);
});
});
});
describe("Url Code Hints in a subfolder", function () {
afterEach(function () {
tearDownTests();
});
it("should hint for background-image: url() in CSS", function () {
setupTests(testCssPath);
runs(function () {
testEditor.setCursorPos({ line: 3, ch: 26 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, subfolderDirHints);
});
});
it("should hint for background-image: url() in SCSS", function () {
setupTests(testScssPath);
runs(function () {
testEditor.setCursorPos({ line: 4, ch: 34 });
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
verifyUrlHints(hintsObj.hints, subfolderDirHints);
});
});
});
describe("Project root relative Url Code Hints", function () {
var testWindow,
brackets,
workingSet = [],
CodeHintManager,
CommandManager,
Commands,
DocumentManager,
MainViewManager,
EditorManager;
it("should hint site root '/'", function () {
runs(function () {
SpecRunnerUtils.createTestWindowAndRun(this, function (w) {
testWindow = w;
brackets = testWindow.brackets;
CodeHintManager = brackets.test.CodeHintManager;
CommandManager = brackets.test.CommandManager;
Commands = brackets.test.Commands;
DocumentManager = brackets.test.DocumentManager;
EditorManager = brackets.test.EditorManager;
MainViewManager = brackets.test.MainViewManager;
});
});
runs(function () {
SpecRunnerUtils.loadProjectInTestWindow(extensionPath);
});
runs(function () {
workingSet.push(testHtmlPath);
waitsForDone(SpecRunnerUtils.openProjectFiles(workingSet), "openProjectFiles");
});
runs(function () {
DocumentManager.getDocumentForPath(testHtmlPath).done(function (doc) {
testDocument = doc;
});
});
waitsFor(function () {
return (testDocument);
}, "Unable to open test document", 2000);
runs(function () {
MainViewManager._edit(MainViewManager.ACTIVE_PANE, testDocument);
testEditor = EditorManager.getCurrentFullEditor();
testEditor.setCursorPos({ line: 22, ch: 12 });
CommandManager.execute(Commands.SHOW_CODE_HINTS);
});
runs(function () {
var hintList = CodeHintManager._getCodeHintList();
expect(hintList).toBeTruthy();
expect(hintList.hints).toBeTruthy();
expect(hintList.hints).toContain("/testfiles/");
});
// cleanup
runs(function () {
testEditor = null;
testDocument = null;
testWindow = null;
brackets = null;
CodeHintManager = null;
CommandManager = null;
Commands = null;
DocumentManager = null;
EditorManager = null;
MainViewManager = null;
SpecRunnerUtils.closeTestWindow();
});
});
});
describe("Url Insertion", function () {
// These tests edit doc, so we need to setup/tear-down for each test
beforeEach(function () {
setupTests(testHtmlPath);
});
afterEach(function () {
tearDownTests();
});
it("should handle unclosed url(", function () {
var pos1 = { line: 11, ch: 20 },
pos2 = { line: 11, ch: 24 },
pos3 = { line: 11, ch: 34 };
runs(function () {
testEditor.setCursorPos(pos1);
testDocument.replaceRange("url(", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[1]).toBe("test.html");
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[1])).toBe(false);
// hint was added with closing paren
expect(testDocument.getRange(pos1, pos3)).toEqual("url(test.html)");
// Cursor was moved past closing paren
expect(testEditor.getCursorPos()).toEqual(pos3);
});
});
it("should handle unclosed url( with unclosed single-quote", function () {
var pos1 = { line: 11, ch: 20 },
pos2 = { line: 11, ch: 25 },
pos3 = { line: 11, ch: 36 };
runs(function () {
testEditor.setCursorPos(pos1);
testDocument.replaceRange("url('", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[1]).toBe("test.html");
// False indicates hints were closed after insertion
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[1])).toBe(false);
// Hint was added with closing single-quote and closing paren
expect(testDocument.getRange(pos1, pos3)).toEqual("url('test.html')");
// Cursor was moved past closing single-quote and closing paren
expect(testEditor.getCursorPos()).toEqual(pos3);
});
});
it("should keep hints open after inserting folder in HTML", function () {
var pos1 = { line: 18, ch: 12 },
pos2 = { line: 18, ch: 22 },
pos3 = { line: 18, ch: 33 },
pos4 = { line: 18, ch: 34 };
runs(function () {
testEditor.setCursorPos(pos1);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Hint was added with closing double-quote and closing paren
expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/");
// Cursor remains inside quote
expect(testEditor.getCursorPos()).toEqual(pos2);
// Get hints of inserted folder
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
// Complete path is displayed
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
// False indicates hints were closed after insertion
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false);
// Hint was added
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/chevron.png");
// Cursor was moved past closing double-quote and closing paren
expect(testEditor.getCursorPos()).toEqual(pos4);
});
});
it("should keep hints open after inserting folder in CSS", function () {
var pos1 = { line: 11, ch: 20 },
pos2 = { line: 11, ch: 25 },
pos3 = { line: 11, ch: 35 },
pos4 = { line: 11, ch: 37 },
pos5 = { line: 11, ch: 48 };
runs(function () {
testEditor.setCursorPos(pos1);
testDocument.replaceRange('url("', pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Hint was added with closing double-quote and closing paren
expect(testDocument.getRange(pos1, pos4)).toEqual('url("subfolder/")');
// Cursor remains inside double-quote and closing paren
expect(testEditor.getCursorPos()).toEqual(pos3);
// Get hints of inserted folder
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
// Complete path is displayed
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
// False indicates hints were closed after insertion
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false);
// Hint was added
expect(testDocument.getRange(pos1, pos5)).toEqual('url("subfolder/chevron.png")');
// Cursor was moved past closing double-quote and closing paren
expect(testEditor.getCursorPos()).toEqual(pos5);
});
});
it("should insert folder and replace file in HTML", function () {
var pos1 = { line: 23, ch: 11 },
pos2 = { line: 23, ch: 21 },
pos3 = { line: 23, ch: 31 },
pos4 = { line: 23, ch: 32 };
runs(function () {
testEditor.setCursorPos(pos1);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Folder was inserted (i.e. filename was not removed)
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/test2.html");
// Cursor is at end of inserted folder
expect(testEditor.getCursorPos()).toEqual(pos2);
// Get hints of inserted folder
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
// Complete path is displayed
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
// False indicates hints were closed after insertion
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false);
// Filename was replaced
expect(testDocument.getRange(pos1, pos4)).toEqual("subfolder/chevron.png");
});
});
it("should insert filtered folder in HTML", function () {
var pos1 = { line: 23, ch: 11 },
pos2 = { line: 23, ch: 14 },
pos3 = { line: 23, ch: 31 };
runs(function () {
testDocument.replaceRange("sub", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("subfolder/");
// Partially existing folder was inserted correctly
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/test2.html");
});
});
it("should replace filtered file in HTML", function () {
var pos1 = { line: 23, ch: 11 },
pos2 = { line: 23, ch: 14 },
pos3 = { line: 23, ch: 21 };
runs(function () {
testDocument.replaceRange("tes", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("test.html");
// Partially existing file was replaced correctly
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
expect(testDocument.getRange(pos1, pos3)).toEqual("test.html'");
});
});
it("should insert folder and replace file in CSS", function () {
var pos1 = { line: 10, ch: 24 },
pos2 = { line: 10, ch: 34 },
pos3 = { line: 10, ch: 43 },
pos4 = { line: 10, ch: 45 };
runs(function () {
testEditor.setCursorPos(pos1);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Folder was inserted (i.e. filename was not removed)
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/dummy.jpg");
// Cursor is at end of inserted folder
expect(testEditor.getCursorPos()).toEqual(pos2);
// Get hints of inserted folder
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(subfolderDirHints.length);
// Complete path is displayed
expect(hintsObj.hints[0]).toBe("subfolder/chevron.png");
// False indicates hints were closed after insertion
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false);
// Filename was replaced
expect(testDocument.getRange(pos1, pos4)).toEqual("subfolder/chevron.png");
});
});
it("should insert filtered folder in CSS", function () {
var pos1 = { line: 10, ch: 24 },
pos2 = { line: 10, ch: 27 },
pos3 = { line: 10, ch: 43 };
runs(function () {
testDocument.replaceRange("sub", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("subfolder/");
// Partially existing folder was inserted correctly
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/dummy.jpg");
});
});
it("should replace filtered file in CSS", function () {
var pos1 = { line: 10, ch: 24 },
pos2 = { line: 10, ch: 27 },
pos3 = { line: 10, ch: 34 };
runs(function () {
testDocument.replaceRange("tes", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("test.html");
// Partially existing file was replaced correctly
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
expect(testDocument.getRange(pos1, pos3)).toEqual("test.html)");
});
});
it("should collapse consecutive path separators when inserting folder in HTML", function () {
var pos1 = { line: 22, ch: 11 },
pos2 = { line: 22, ch: 22 };
runs(function () {
testEditor.setCursorPos(pos1);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Folder was inserted and there's only 1 slash afterwards
expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/'");
});
});
it("should collapse consecutive path separators when inserting folder in CSS", function () {
var pos1 = { line: 9, ch: 15 },
pos2 = { line: 9, ch: 26 };
runs(function () {
testEditor.setCursorPos(pos1);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(2);
expect(hintsObj.hints[0]).toBe("subfolder/");
// True indicates hints were remain open after insertion of folder
// (i.e. showing contents of inserted folder)
expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true);
// Folder was inserted and there's only 1 slash afterwards
expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/\"");
});
});
it("should show & insert case insensitive hints in HTML", function () {
var pos1 = { line: 18, ch: 12 },
pos2 = { line: 18, ch: 13 },
pos3 = { line: 18, ch: 21 };
runs(function () {
// Insert letter that matches filename, but with different case
testDocument.replaceRange("T", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("test.html");
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
// Filename case from list was inserted (overriding case inserted in page)
expect(testDocument.getRange(pos1, pos3)).toEqual("test.html");
});
});
it("should show & insert case insensitive hints in CSS", function () {
var pos1 = { line: 6, ch: 24 },
pos2 = { line: 6, ch: 25 },
pos3 = { line: 6, ch: 33 };
runs(function () {
// Insert letter that matches filename, but with different case
testDocument.replaceRange("T", pos1, pos1);
testEditor.setCursorPos(pos2);
hintsObj = null;
expectAsyncHints(UrlCodeHints.hintProvider);
});
runs(function () {
expect(hintsObj).toBeTruthy();
expect(hintsObj.hints).toBeTruthy();
expect(hintsObj.hints.length).toBe(1);
expect(hintsObj.hints[0]).toBe("test.html");
UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]);
// Filename case from list was inserted (overriding case inserted in page)
expect(testDocument.getRange(pos1, pos3)).toEqual("test.html");
});
});
});
}); // describe("Url Code Hinting"
});