Skip to content

Commit 0faeee1

Browse files
committed
feat: write tests for context menu visibility
1 parent 3b43684 commit 0faeee1

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,5 +1309,112 @@ define(function (require, exports, module) {
13091309
expect(fileClosePathArg).toBe(testFilePath);
13101310
});
13111311
});
1312+
1313+
describe("Context Menu", function () {
1314+
beforeEach(async function () {
1315+
// Enable the tab bar feature
1316+
PreferencesManager.set("tabBar.options", { showTabBar: true, numberOfTabs: -1 });
1317+
1318+
// Close all files to start with a clean state
1319+
await testWindow.closeAllFiles();
1320+
1321+
// Open all three test files
1322+
await awaitsForDone(
1323+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath }),
1324+
"Open first test file"
1325+
);
1326+
await awaitsForDone(
1327+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath2 }),
1328+
"Open second test file"
1329+
);
1330+
await awaitsForDone(
1331+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: testFilePath3 }),
1332+
"Open third test file"
1333+
);
1334+
1335+
// Wait for all tabs to appear
1336+
await awaitsFor(
1337+
function () {
1338+
return tabExists(testFilePath) && tabExists(testFilePath2) && tabExists(testFilePath3);
1339+
},
1340+
"All tabs to appear",
1341+
1000
1342+
);
1343+
});
1344+
1345+
/**
1346+
* Helper function to get the context menu element
1347+
* @returns {jQuery} - The context menu element
1348+
*/
1349+
function getContextMenu() {
1350+
return $(".tabbar-context-menu");
1351+
}
1352+
1353+
it("should open context menu when right-clicking on a tab", async function () {
1354+
// Get the tab element
1355+
const $tab = getTab(testFilePath);
1356+
expect($tab.length).toBe(1);
1357+
1358+
// Simulate a right-click (contextmenu) event on the tab
1359+
$tab.trigger("contextmenu", {
1360+
pageX: 100,
1361+
pageY: 100
1362+
});
1363+
1364+
// Wait for the context menu to appear
1365+
await awaitsFor(
1366+
function () {
1367+
return getContextMenu().length > 0;
1368+
},
1369+
"Context menu to appear",
1370+
1000
1371+
);
1372+
1373+
// Verify the context menu is visible
1374+
expect(getContextMenu().length).toBe(1);
1375+
expect(getContextMenu().is(":visible")).toBe(true);
1376+
1377+
// Clean up - close the context menu by clicking elsewhere
1378+
$("body").click();
1379+
1380+
// Wait for the context menu to disappear
1381+
await awaitsFor(
1382+
function () {
1383+
return getContextMenu().length === 0;
1384+
},
1385+
"Context menu to disappear",
1386+
1000
1387+
);
1388+
});
1389+
1390+
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);
1396+
1397+
// Get the file object (not just the path)
1398+
const fileObj = FileSystem.getFileForPath(testFilePath);
1399+
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"
1404+
);
1405+
1406+
// Cancel the save dialog if it appears
1407+
testWindow.brackets.test.Dialogs.cancelModalDialogIfOpen(
1408+
testWindow.brackets.test.DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
1409+
testWindow.brackets.test.DefaultDialogs.DIALOG_BTN_DONTSAVE
1410+
);
1411+
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);
1417+
});
1418+
});
13121419
});
13131420
});

0 commit comments

Comments
 (0)