-
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathExtn-Tabbar-integ-test.js
More file actions
2934 lines (2469 loc) · 122 KB
/
Extn-Tabbar-integ-test.js
File metadata and controls
2934 lines (2469 loc) · 122 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
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . 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, beforeAll, afterAll, beforeEach, afterEach, awaitsFor, awaitsForDone, awaits, jsPromise */
define(function (require, exports, module) {
const SpecRunnerUtils = require("spec/SpecRunnerUtils");
describe("integration:TabBar", function () {
let testWindow,
PreferencesManager,
$,
FileSystem,
MainViewManager,
CommandManager,
Commands,
DocumentManager,
Strings;
let testFilePath, testFilePath2, testFilePath3, testDuplicateDir1, testDuplicateDir2, testDuplicateName;
/**
* Helper function to create multiple test files
* @param {number} count - Number of files to create
* @param {string} prefix - Prefix for the file names
* @param {string} content - Content template for the files (will be appended with file index)
* @returns {Promise<string[]>} - Array of file paths
*/
async function createTestFiles(count, prefix, content) {
const testFiles = [];
for (let i = 0; i < count; i++) {
const filePath = SpecRunnerUtils.getTempDirectory() + `/${prefix}-${i}.js`;
testFiles.push(filePath);
await jsPromise(
SpecRunnerUtils.createTextFile(
filePath,
content ? `${content} ${i}` : `// ${prefix} test file ${i}`,
FileSystem
)
);
}
return testFiles;
}
/**
* Helper function to open multiple files
* @param {string[]} filePaths - Array of file paths to open
* @param {string} [paneId] - Optional pane ID to open the files in
* @returns {Promise<void>}
*/
async function openTestFiles(filePaths, paneId) {
for (const filePath of filePaths) {
const options = { fullPath: filePath };
if (paneId) {
options.paneId = paneId;
}
await awaitsForDone(
CommandManager.execute(Commands.FILE_OPEN, options),
`Open file ${filePath}${paneId ? ` in ${paneId}` : ""}`
);
}
}
/**
* Helper function to wait for tabs to appear
* @param {string[]} filePaths - Array of file paths to wait for
* @param {string} [paneId] - Optional pane ID to check for tabs
* @returns {Promise<void>}
*/
async function waitForTabs(filePaths, paneId) {
if (paneId) {
// Wait for tabs to appear in the specified pane
await awaitsFor(
function () {
return getPaneTabCount(paneId) >= filePaths.length;
},
`All tabs to appear in ${paneId}`
);
} else if (filePaths.length === 1) {
// Wait for a single tab to appear
await awaitsFor(
function () {
return tabExists(filePaths[0]);
},
`Tab for ${filePaths[0]} to appear`
);
} else {
// Wait for multiple tabs to appear
await awaitsFor(
function () {
return getTabCount() >= filePaths.length && filePaths.every((path) => tabExists(path));
},
"All tabs to appear"
);
}
}
/**
* Helper function to cancel the save dialog
* @returns {void}
*/
function cancelSaveDialog() {
testWindow.brackets.test.Dialogs.cancelModalDialogIfOpen(
testWindow.brackets.test.DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
testWindow.brackets.test.DefaultDialogs.DIALOG_BTN_DONTSAVE
);
}
/**
* Helper function to close files
* @param {string[]} filePaths - Array of file paths to close
* @param {string} [paneId] - Optional pane ID to close the files from
* @returns {Promise<void>}
*/
async function closeTestFiles(filePaths, paneId) {
for (const filePath of filePaths) {
const fileToClose = FileSystem.getFileForPath(filePath);
const options = { file: fileToClose };
if (paneId) {
options.paneId = paneId;
}
const promise = CommandManager.execute(Commands.FILE_CLOSE, options);
cancelSaveDialog();
await awaitsForDone(promise, `Close file ${filePath}`);
}
}
/**
* Helper function to simulate drag and drop between tabs
* @param {string} sourceFilePath - Path of the source file to drag
* @param {string} targetFilePath - Path of the target file to drop onto
* @param {boolean} [dropBefore=true] - Whether to drop before the target (true) or after (false)
* @returns {Promise<void>}
*/
async function simulateTabDragAndDrop(sourceFilePath, targetFilePath, dropBefore = true) {
// Get the source and target tabs
const sourceTab = getTab(sourceFilePath);
const targetTab = getTab(targetFilePath);
// Simulate drag start on the source tab
const dragStartEvent = $.Event("dragstart", {
originalEvent: {
dataTransfer: {
setData: function () {},
effectAllowed: "move"
}
}
});
sourceTab.trigger(dragStartEvent);
// Simulate dragenter on the target tab
const dragEnterEvent = $.Event("dragenter");
targetTab.trigger(dragEnterEvent);
// Simulate drag over on the target tab
const targetRect = targetTab[0].getBoundingClientRect();
const dropX = dropBefore
? targetRect.left + 5 // Position near the left edge to drop before
: targetRect.right - 5; // Position near the right edge to drop after
const dragOverEvent = $.Event("dragover", {
originalEvent: {
dataTransfer: {
dropEffect: "move"
},
clientX: dropX
},
preventDefault: function () {}
});
targetTab.trigger(dragOverEvent);
// Simulate drop on the target tab
const dropEvent = $.Event("drop", {
originalEvent: {
dataTransfer: {},
clientX: dropX
},
preventDefault: function () {},
stopPropagation: function () {}
});
targetTab.trigger(dropEvent);
// Simulate dragend to complete the operation
const dragEndEvent = $.Event("dragend");
sourceTab.trigger(dragEndEvent);
}
/**
* Helper function to check if the tab bar for a specific pane is visible
* @param {string} paneId - The pane ID ("first-pane" or "second-pane")
* @returns {boolean} - True if the tab bar is visible, false otherwise
*/
function isTabBarVisible(paneId) {
const tabBarId = paneId === "first-pane" ? "#phoenix-tab-bar" : "#phoenix-tab-bar-2";
return $(tabBarId).is(":visible");
}
/**
* Helper function to get the tab count for a specific pane
* @param {string} paneId - The pane ID ("first-pane" or "second-pane")
* @returns {number} - The number of tabs in the pane
*/
function getPaneTabCount(paneId) {
const tabBarId = paneId === "first-pane" ? "#phoenix-tab-bar" : "#phoenix-tab-bar-2";
return $(tabBarId).find(".tab").length;
}
/**
* Helper function to check if a tab for a specific file exists in a specific pane
* @param {string} filePath - The path of the file to check
* @param {string} paneId - The pane ID ("first-pane" or "second-pane")
* @returns {boolean} - True if the tab exists in the pane, false otherwise
*/
function tabExistsInPane(filePath, paneId) {
const tabBarId = paneId === "first-pane" ? "#phoenix-tab-bar" : "#phoenix-tab-bar-2";
return $(tabBarId).find(`.tab[data-path="${filePath}"]`).length > 0;
}
beforeAll(async function () {
// Create the test window
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
// Get reference to all the required modules
$ = testWindow.$;
PreferencesManager = testWindow.brackets.test.PreferencesManager;
FileSystem = testWindow.brackets.test.FileSystem;
MainViewManager = testWindow.brackets.test.MainViewManager;
CommandManager = testWindow.brackets.test.CommandManager;
Commands = testWindow.brackets.test.Commands;
DocumentManager = testWindow.brackets.test.DocumentManager;
Strings = testWindow.Strings;
// Create test files
testFilePath = SpecRunnerUtils.getTempDirectory() + "/tabbar-test.js";
testFilePath2 = SpecRunnerUtils.getTempDirectory() + "/tabbar-test2.js";
testFilePath3 = SpecRunnerUtils.getTempDirectory() + "/tabbar-test3.js";
// Create files with the same name in different directories for testing duplicate name handling
testDuplicateDir1 = SpecRunnerUtils.getTempDirectory() + "/dir1";
testDuplicateDir2 = SpecRunnerUtils.getTempDirectory() + "/dir2";
testDuplicateName = "duplicate.js";
await SpecRunnerUtils.createTempDirectory();
await SpecRunnerUtils.ensureExistsDirAsync(testDuplicateDir1);
await SpecRunnerUtils.ensureExistsDirAsync(testDuplicateDir2);
await jsPromise(SpecRunnerUtils.createTextFile(testFilePath, "// Test file 1 for TabBar", FileSystem));
await jsPromise(SpecRunnerUtils.createTextFile(testFilePath2, "// Test file 2 for TabBar", FileSystem));
await jsPromise(SpecRunnerUtils.createTextFile(testFilePath3, "// Test file 3 for TabBar", FileSystem));
await jsPromise(
SpecRunnerUtils.createTextFile(
testDuplicateDir1 + "/" + testDuplicateName,
"// Duplicate file 1",
FileSystem
)
);
await jsPromise(
SpecRunnerUtils.createTextFile(
testDuplicateDir2 + "/" + testDuplicateName,
"// Duplicate file 2",
FileSystem
)
);
// Open the first test file
await awaitsForDone(
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath }),
"Open test file"
);
}, 5000);
afterAll(async function () {
// Close all files without prompting to save
await testWindow.closeAllFiles();
testWindow = null;
await SpecRunnerUtils.closeTestWindow();
await SpecRunnerUtils.removeTempDirectory();
}, 5000);
/**
* Helper function to check if a tab for a specific file exists in the tab bar
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab exists, false otherwise
*/
function tabExists(filePath) {
return $(`.tab[data-path="${filePath}"]`).length > 0;
}
/**
* Helper function to count the number of tabs in the tab bar
* @returns {number} - The number of tabs
*/
function getTabCount() {
return $(".tab").length;
}
/**
* Helper function to check if a tab for a specific file is active
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab is active, false otherwise
*/
function isTabActive(filePath) {
return $(`.tab[data-path="${filePath}"].active`).length > 0;
}
/**
* Helper function to get the tab element for a specific file
* @param {string} filePath - The path of the file
* @returns {jQuery} - The tab element
*/
function getTab(filePath) {
return $(`.tab[data-path="${filePath}"]`);
}
/**
* Helper function to check if a tab has a dirty indicator
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab has a dirty indicator, false otherwise
*/
function isTabDirty(filePath) {
return getTab(filePath).hasClass("dirty");
}
/**
* Helper function to get the tab name element for a specific file
* @param {string} filePath - The path of the file
* @returns {jQuery} - The tab name element
*/
function getTabName(filePath) {
return getTab(filePath).find(".tab-name");
}
/**
* Helper function to check if a tab has a directory name displayed
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab has a directory name, false otherwise
*/
function hasDirectoryName(filePath) {
return getTab(filePath).find(".tab-dirname").length > 0;
}
/**
* Helper function to get the directory name displayed in a tab
* @param {string} filePath - The path of the file
* @returns {string} - The directory name or empty string if not found
*/
function getDirectoryName(filePath) {
const $dirName = getTab(filePath).find(".tab-dirname");
return $dirName.length ? $dirName.text() : "";
}
/**
* Helper function to check if a tab has a file icon
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab has a file icon, false otherwise
*/
function hasFileIcon(filePath) {
return getTab(filePath).find(".tab-icon i").length > 0;
}
/**
* Helper function to check if a tab has a git status indicator
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab has a git status indicator, false otherwise
*/
function hasGitStatus(filePath) {
return getTab(filePath).hasClass("git-new") || getTab(filePath).hasClass("git-modified");
}
/**
* Helper function to get the tooltip (title attribute) of a tab
* @param {string} filePath - The path of the file
* @returns {string} - The tooltip text
*/
function getTabTooltip(filePath) {
return getTab(filePath).attr("title") || "";
}
/**
* Helper function to check if a tab has a close button
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab has a close button, false otherwise
*/
function hasCloseButton(filePath) {
return getTab(filePath).find(".tab-close").length > 0;
}
/**
* Helper function to check if the overflow button is visible
* @returns {boolean} - True if the overflow button is visible, false otherwise
*/
function isOverflowButtonVisible() {
return $("#overflow-button").is(":visible");
}
/**
* Helper function to get the overflow button element
* @returns {jQuery} - The overflow button element
*/
function getOverflowButton() {
return $("#overflow-button");
}
/**
* Helper function to check if a tab is visible in the tab bar (not hidden by overflow)
* @param {string} filePath - The path of the file to check
* @returns {boolean} - True if the tab is visible, false otherwise
*/
function isTabVisible(filePath) {
const $tab = getTab(filePath);
if (!$tab.length) {
return false;
}
const $tabBar = $("#phoenix-tab-bar");
const tabBarRect = $tabBar[0].getBoundingClientRect();
const tabRect = $tab[0].getBoundingClientRect();
// A tab is considered visible if it is completely within the tab bar's visible area
// with a small margin of error (2px)
return tabRect.left >= tabBarRect.left && tabRect.right <= tabBarRect.right + 2;
}
/**
* Helper function to get the overflow dropdown menu
* @returns {jQuery} - The overflow dropdown menu element
*/
function getOverflowDropdown() {
return $(".dropdown-overflow-menu");
}
/**
* Helper function to get the items in the overflow dropdown
* @returns {jQuery} - The overflow dropdown items
*/
function getOverflowDropdownItems() {
return $(".dropdown-overflow-menu .dropdown-tab-item");
}
/**
* Helper function to get a specific item in the overflow dropdown by file path
* @param {string} filePath - The path of the file to find
* @returns {jQuery} - The dropdown item element
*/
function getOverflowDropdownItem(filePath) {
return $(`.dropdown-overflow-menu .dropdown-tab-item[data-tab-path="${filePath}"]`);
}
describe("Visibility", function () {
it("should show tab bar when the feature is enabled", async function () {
// Enable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
// Wait for the tab bar to become visible
await awaitsFor(
function () {
return $("#phoenix-tab-bar").is(":visible");
},
"Tab bar to become visible"
);
});
it("should hide tab bar when the feature is disabled", async function () {
// Disable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: false, numberOfTabs: -1 });
// Wait for the tab bar to become hidden
await awaitsFor(
function () {
return !$("#phoenix-tab-bar").is(":visible");
},
"Tab bar to become hidden"
);
});
it("should show working set when the option is enabled", async function () {
// Enable the working set feature
PreferencesManager.set("showWorkingSet", true);
// Wait for the working set to become visible
await awaitsFor(
function () {
return !$("#working-set-list-container").hasClass("working-set-hidden");
},
"Working set to become visible"
);
});
it("should hide working set when the option is disabled", async function () {
// Disable the working set feature
PreferencesManager.set("showWorkingSet", false);
// Wait for the working set to become hidden
await awaitsFor(
function () {
return $("#working-set-list-container").hasClass("working-set-hidden");
},
"Working set to become hidden"
);
});
});
describe("Configure Working Set Button", function () {
it("should have a working set configuration button in the sidebar", function () {
// Verify the button exists
const $configButton = $(".working-set-splitview-btn");
expect($configButton.length).toBe(1);
});
it("should open a menu with 'Show working set' and 'Show file tab bar' options when clicked", async function () {
// Click the configure working set button
const $configButton = $(".working-set-splitview-btn");
$configButton.click();
// Wait for the menu to appear
await awaitsFor(
function () {
return $(".dropdown-menu:visible").length > 0;
},
"Context menu to appear"
);
// Verify the menu contains the expected options
const $menu = $(".dropdown-menu:visible");
const showWorkingSetItem = $menu.find("li a[id$='cmd.toggleShowWorkingSet']");
const showFileTabsItem = $menu.find("li a[id$='cmd.toggleShowFileTabs']");
expect(showWorkingSetItem.length).toBe(1);
expect(showFileTabsItem.length).toBe(1);
// Clean up - close the menu
$("body").click();
});
it("should toggle working set visibility when 'Show working set' option is clicked", async function () {
// First, ensure working set is visible
PreferencesManager.set("showWorkingSet", true);
await awaitsFor(
function () {
return !$("#working-set-list-container").hasClass("working-set-hidden");
},
"Working set to become visible"
);
// Click the configure working set button
const $configButton = $(".working-set-splitview-btn");
$configButton.click();
// Wait for the menu to appear
await awaitsFor(
function () {
return $(".dropdown-menu:visible").length > 0;
},
"Context menu to appear"
);
// Click the "Show working set" option
const $menu = $(".dropdown-menu:visible");
const showWorkingSetItem = $menu.find("li a[id$='cmd.toggleShowWorkingSet']");
showWorkingSetItem.click();
// Wait for the working set to become hidden
await awaitsFor(
function () {
return $("#working-set-list-container").hasClass("working-set-hidden");
},
"Working set to become hidden"
);
// Click the configure working set button again
$configButton.click();
// Wait for the menu to appear
await awaitsFor(
function () {
return $(".dropdown-menu:visible").length > 0;
},
"Context menu to appear"
);
// Click the "Show working set" option again
const $menu2 = $(".dropdown-menu:visible");
const showWorkingSetItem2 = $menu2.find("li a[id$='cmd.toggleShowWorkingSet']");
showWorkingSetItem2.click();
// Wait for the working set to become visible
await awaitsFor(
function () {
return !$("#working-set-list-container").hasClass("working-set-hidden");
},
"Working set to become visible"
);
});
it("should toggle tab bar visibility when 'Show file tab bar' option is clicked", async function () {
// First, ensure tab bar is visible
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
await awaitsFor(
function () {
return $("#phoenix-tab-bar").is(":visible");
},
"Tab bar to become visible"
);
// Click the configure working set button
const $configButton = $(".working-set-splitview-btn");
$configButton.click();
// Wait for the menu to appear
await awaitsFor(
function () {
return $(".dropdown-menu:visible").length > 0;
},
"Context menu to appear"
);
// Click the "Show file tab bar" option
const $menu = $(".dropdown-menu:visible");
const showFileTabsItem = $menu.find("li a[id$='cmd.toggleShowFileTabs']");
showFileTabsItem.click();
// Wait for the tab bar to become hidden
await awaitsFor(
function () {
return !$("#phoenix-tab-bar").is(":visible");
},
"Tab bar to become hidden"
);
// Click the configure working set button again
$configButton.click();
// Wait for the menu to appear
await awaitsFor(
function () {
return $(".dropdown-menu:visible").length > 0;
},
"Context menu to appear"
);
// Click the "Show file tab bar" option again
const $menu2 = $(".dropdown-menu:visible");
const showFileTabsItem2 = $menu2.find("li a[id$='cmd.toggleShowFileTabs']");
showFileTabsItem2.click();
// Wait for the tab bar to become visible
await awaitsFor(
function () {
return $("#phoenix-tab-bar").is(":visible");
},
"Tab bar to become visible"
);
});
});
describe("Drag and Drop", function () {
beforeEach(async function () {
// Close all files and reset to single pane
await testWindow.closeAllFiles();
MainViewManager.setLayoutScheme(1, 1);
// Wait for cleanup to complete
await awaitsFor(
function () {
return MainViewManager.getPaneCount() === 1 && getTabCount() === 0;
},
"Cleanup to complete with single pane and no tabs"
);
});
it("should allow dragging and dropping a tab to the beginning of the tab bar", async function () {
// Enable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
// Close all files to start with a clean state
await testWindow.closeAllFiles();
// Create and open multiple test files to work with
const testFiles = await createTestFiles(3, "drag-drop-test", "// Drag drop test file");
await openTestFiles(testFiles);
await waitForTabs(testFiles);
// Verify initial tab order
const initialWorkingSet = MainViewManager.getWorkingSet("first-pane");
expect(initialWorkingSet.length).toBe(testFiles.length);
expect(initialWorkingSet[0].fullPath).toBe(testFiles[0]);
expect(initialWorkingSet[1].fullPath).toBe(testFiles[1]);
expect(initialWorkingSet[2].fullPath).toBe(testFiles[2]);
// Simulate drag and drop from first tab to last tab
await simulateTabDragAndDrop(testFiles[0], testFiles[2], true);
// Wait for the working set to update
await awaitsFor(
function () {
const currentWorkingSet = MainViewManager.getWorkingSet("first-pane");
// Check if the first file has moved to before the last file
return (
currentWorkingSet.length === testFiles.length &&
currentWorkingSet[1].fullPath === testFiles[0]
);
},
"Working set to update after drag and drop"
);
// Verify the new tab order
const finalWorkingSet = MainViewManager.getWorkingSet("first-pane");
expect(finalWorkingSet.length).toBe(testFiles.length);
expect(finalWorkingSet[0].fullPath).toBe(testFiles[1]);
expect(finalWorkingSet[1].fullPath).toBe(testFiles[0]);
expect(finalWorkingSet[2].fullPath).toBe(testFiles[2]);
// Clean up - close all the test files
await closeTestFiles(testFiles);
});
it("should allow dragging and dropping a tab in between other tabs", async function () {
// Enable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
// Close all files to start with a clean state
await testWindow.closeAllFiles();
// Create and open multiple test files to work with
const testFiles = await createTestFiles(3, "drag-between-test", "// Drag between test file");
await openTestFiles(testFiles);
await waitForTabs(testFiles);
// Verify initial tab order
const initialWorkingSet = MainViewManager.getWorkingSet("first-pane");
expect(initialWorkingSet.length).toBe(testFiles.length);
expect(initialWorkingSet[0].fullPath).toBe(testFiles[0]);
expect(initialWorkingSet[1].fullPath).toBe(testFiles[1]);
expect(initialWorkingSet[2].fullPath).toBe(testFiles[2]);
// Simulate drag and drop from last tab to before the middle tab
await simulateTabDragAndDrop(testFiles[2], testFiles[1], true);
// Wait for the working set to update
await awaitsFor(
function () {
const currentWorkingSet = MainViewManager.getWorkingSet("first-pane");
// Check if the last file has moved to between the first and second files
return (
currentWorkingSet.length === testFiles.length &&
currentWorkingSet[1].fullPath === testFiles[2]
);
},
"Working set to update after drag and drop"
);
// Verify the new tab order
const finalWorkingSet = MainViewManager.getWorkingSet("first-pane");
expect(finalWorkingSet.length).toBe(testFiles.length);
expect(finalWorkingSet[0].fullPath).toBe(testFiles[0]);
expect(finalWorkingSet[1].fullPath).toBe(testFiles[2]); // Last tab should now be in the middle
expect(finalWorkingSet[2].fullPath).toBe(testFiles[1]); // Middle tab should now be last
// Clean up - close all the test files
await closeTestFiles(testFiles);
});
it("should allow dragging a tab from one pane to another non-empty pane", async function () {
// Enable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
// Close all files to start with a clean state
await testWindow.closeAllFiles();
// Set up a horizontal split view (two columns)
MainViewManager.setLayoutScheme(1, 2);
// Create test files for both panes
const firstPaneFiles = await createTestFiles(2, "first-pane-test", "// First pane test file");
const secondPaneFiles = await createTestFiles(2, "second-pane-test", "// Second pane test file");
// Open files in both panes
await openTestFiles(firstPaneFiles, "first-pane");
await openTestFiles(secondPaneFiles, "second-pane");
// Wait for all tabs to appear in both panes
await waitForTabs(firstPaneFiles, "first-pane");
await waitForTabs(secondPaneFiles, "second-pane");
// Verify initial tab counts
expect(getPaneTabCount("first-pane")).toBe(firstPaneFiles.length);
expect(getPaneTabCount("second-pane")).toBe(secondPaneFiles.length);
// Get the source tab from the first pane and target tab from the second pane
const sourceTab = $(`.tab[data-path="${firstPaneFiles[0]}"]`);
const targetTab = $(`.tab[data-path="${secondPaneFiles[0]}"]`);
// Simulate drag start on the source tab
const dragStartEvent = $.Event("dragstart", {
originalEvent: {
dataTransfer: {
setData: function () {},
effectAllowed: "move"
}
}
});
sourceTab.trigger(dragStartEvent);
// Simulate dragenter on the target tab
const dragEnterEvent = $.Event("dragenter");
targetTab.trigger(dragEnterEvent);
// Simulate drag over on the target tab
const dragOverEvent = $.Event("dragover", {
originalEvent: {
dataTransfer: {
dropEffect: "move"
},
clientX: targetTab[0].getBoundingClientRect().left + 5 // Position near the left edge
},
preventDefault: function () {}
});
targetTab.trigger(dragOverEvent);
// Simulate drop on the target tab
const dropEvent = $.Event("drop", {
originalEvent: {
dataTransfer: {},
clientX: targetTab[0].getBoundingClientRect().left + 5 // Position near the left edge
},
preventDefault: function () {},
stopPropagation: function () {}
});
targetTab.trigger(dropEvent);
// Simulate dragend to complete the operation
const dragEndEvent = $.Event("dragend");
sourceTab.trigger(dragEndEvent);
// Wait for the tab to move to the second pane
await awaitsFor(
function () {
return (
!tabExistsInPane(firstPaneFiles[0], "first-pane") &&
tabExistsInPane(firstPaneFiles[0], "second-pane")
);
},
"Tab to move from first pane to second pane"
);
// Verify the tab counts after the drag and drop
expect(getPaneTabCount("first-pane")).toBe(firstPaneFiles.length - 1);
expect(getPaneTabCount("second-pane")).toBe(secondPaneFiles.length + 1);
// Clean up - close all files and reset to single pane
await testWindow.closeAllFiles();
MainViewManager.setLayoutScheme(1, 1);
});
it("should allow dragging a tab to an empty pane", async function () {
// Enable the tab bar feature
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
// Close all files to start with a clean state
await testWindow.closeAllFiles();
// Set up a horizontal split view (two columns)
MainViewManager.setLayoutScheme(1, 2);
// Wait for layout to settle
await awaitsFor(
function () {
return MainViewManager.getPaneCount() === 2;
},
"Layout to settle with two panes"
);
// Verify both panes are empty
expect(MainViewManager.getWorkingSet("first-pane").length).toBe(0);
expect(MainViewManager.getWorkingSet("second-pane").length).toBe(0);
// Create test files for the first pane
const firstPaneFiles = await createTestFiles(
2,
"first-pane-empty-test",
"// First pane empty test file"
);
// Open files in the first pane only
await openTestFiles(firstPaneFiles, "first-pane");
// Wait for all tabs to appear in the first pane
await waitForTabs(firstPaneFiles, "first-pane");
// Verify initial state: first pane has tabs, second pane is empty
expect(getPaneTabCount("first-pane")).toBe(firstPaneFiles.length);
// If the second pane has tabs, log what they are and close them
if (getPaneTabCount("second-pane") > 0) {
const secondPaneWorkingSet = MainViewManager.getWorkingSet("second-pane");
for (const file of secondPaneWorkingSet) {
await awaitsForDone(
CommandManager.execute(Commands.FILE_CLOSE, { file: file, paneId: "second-pane" }),
`Force close file ${file.fullPath} in second pane`
);
}
// Wait for the second pane to be empty
await awaitsFor(
function () {
return getPaneTabCount("second-pane") === 0;
},
"Second pane to be empty after cleanup"
);
}
expect(getPaneTabCount("second-pane")).toBe(0);
expect(isTabBarVisible("second-pane")).toBe(false);
// Get the source tab from the first pane
const sourceTab = $(`.tab[data-path="${firstPaneFiles[0]}"]`);
expect(sourceTab.length).toBe(1, "Source tab should exist in the first pane");
// Get the empty pane content area as the drop target
const emptyPaneTarget = $("#second-pane .pane-content");
expect(emptyPaneTarget.length).toBe(1, "Empty pane target should exist");
// Simulate drag and drop
try {
// Simulate drag start
const dragStartEvent = $.Event("dragstart", {
originalEvent: {
dataTransfer: {
setData: function () {},
effectAllowed: "move"
}
}
});
sourceTab.trigger(dragStartEvent);
// Simulate dragenter
const dragEnterEvent = $.Event("dragenter");
emptyPaneTarget.trigger(dragEnterEvent);
// Simulate dragover
const dragOverEvent = $.Event("dragover", {
originalEvent: {
dataTransfer: {
dropEffect: "move"
}
},
preventDefault: function () {}
});
emptyPaneTarget.trigger(dragOverEvent);
// Simulate drop
const dropEvent = $.Event("drop", {
originalEvent: {
dataTransfer: {}
},
preventDefault: function () {},
stopPropagation: function () {}
});
emptyPaneTarget.trigger(dropEvent);
// Simulate dragend
const dragEndEvent = $.Event("dragend");
sourceTab.trigger(dragEndEvent);
} catch (e) {
console.error("Error during drag and drop simulation:", e);
throw e;
}
// Wait for the tab to move to the second pane
await awaitsFor(
function () {
return (
!tabExistsInPane(firstPaneFiles[0], "first-pane") &&
tabExistsInPane(firstPaneFiles[0], "second-pane") &&
isTabBarVisible("second-pane")
);
},
"Tab to move from first pane to second pane and tab bar to appear"
);
// Verify the tab counts after the drag and drop
expect(getPaneTabCount("first-pane")).toBe(firstPaneFiles.length - 1);
expect(getPaneTabCount("second-pane")).toBe(1);