Skip to content

Commit f794e58

Browse files
committed
fix: close tab context menu test
1 parent 0faeee1 commit f794e58

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

test/spec/Extn-Tabbar-integ-test.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ define(function (require, exports, module) {
2424
const SpecRunnerUtils = require("spec/SpecRunnerUtils");
2525

2626
describe("integration:TabBar", function () {
27-
let testWindow, PreferencesManager, $, FileSystem, MainViewManager, CommandManager, Commands, DocumentManager;
27+
let testWindow, PreferencesManager, $, FileSystem, MainViewManager, CommandManager, Commands, DocumentManager, Strings;
2828
let testFilePath, testFilePath2, testFilePath3, testDuplicateDir1, testDuplicateDir2, testDuplicateName;
2929

3030
beforeAll(async function () {
@@ -38,6 +38,7 @@ define(function (require, exports, module) {
3838
CommandManager = testWindow.brackets.test.CommandManager;
3939
Commands = testWindow.brackets.test.Commands;
4040
DocumentManager = testWindow.brackets.test.DocumentManager;
41+
Strings = testWindow.Strings;
4142

4243
// Create test files
4344
testFilePath = SpecRunnerUtils.getTempDirectory() + "/tabbar-test.js";
@@ -1388,32 +1389,45 @@ define(function (require, exports, module) {
13881389
});
13891390

13901391
it("should close the tab when selecting 'Close Tab' from context menu", async function () {
1391-
// Get the full working set before closing the file
1392-
const initialWorkingSet = MainViewManager.getWorkingSet(MainViewManager.ACTIVE_PANE);
1393-
1394-
// Verify the file is in the working set initially
1395-
expect(initialWorkingSet.some(file => file.fullPath === testFilePath)).toBe(true);
1392+
// Get the tab element
1393+
const $tab = getTab(testFilePath);
13961394

1397-
// Get the file object (not just the path)
1398-
const fileObj = FileSystem.getFileForPath(testFilePath);
1395+
// Right-click on the tab to open context menu
1396+
$tab.trigger("contextmenu", {
1397+
pageX: 100,
1398+
pageY: 100
1399+
});
13991400

1400-
// Close the file using FILE_CLOSE command with the full file object
1401-
await awaitsForDone(
1402-
CommandManager.execute(Commands.FILE_CLOSE, { file: fileObj }),
1403-
"Close file"
1401+
// Wait for context menu to appear
1402+
await awaitsFor(
1403+
function () {
1404+
return getContextMenu().length > 0;
1405+
},
1406+
"Context menu to appear",
1407+
1000
14041408
);
14051409

1410+
// Find and click the "Close Tab" option
1411+
const $closeTabOption = getContextMenu().find('a.stylesheet-link').filter(function() {
1412+
return $(this).text().trim() === Strings.CLOSE_TAB;
1413+
});
1414+
expect($closeTabOption.length).toBe(1);
1415+
$closeTabOption.click();
1416+
14061417
// Cancel the save dialog if it appears
14071418
testWindow.brackets.test.Dialogs.cancelModalDialogIfOpen(
14081419
testWindow.brackets.test.DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
14091420
testWindow.brackets.test.DefaultDialogs.DIALOG_BTN_DONTSAVE
14101421
);
14111422

1412-
// Get the full working set after closing
1413-
const finalWorkingSet = MainViewManager.getWorkingSet(MainViewManager.ACTIVE_PANE);
1414-
1415-
// Verify the file is removed from the working set
1416-
expect(finalWorkingSet.some(file => file.fullPath === testFilePath)).toBe(false);
1423+
// Verify the tab is closed
1424+
await awaitsFor(
1425+
function () {
1426+
return !tabExists(testFilePath);
1427+
},
1428+
"Tab to be closed",
1429+
1000
1430+
);
14171431
});
14181432
});
14191433
});

0 commit comments

Comments
 (0)