Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 8ddead0

Browse files
leeyiminpetetnt
authored andcommitted
Create tests for Disabled context menu items for unsaved files / #12806 #13134 (#13178)
* Add test case for disabled items in unsaved file * add saved file test case
1 parent 7372631 commit 8ddead0

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

test/spec/Menu-test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323

24-
/*global describe, it, expect, runs, beforeFirst, afterLast */
24+
/*global describe, it, expect, runs, beforeFirst, afterLast, waitsForDone, spyOn*/
2525

2626
define(function (require, exports, module) {
2727
"use strict";
@@ -30,6 +30,7 @@ define(function (require, exports, module) {
3030
Commands, // Load from brackets.test
3131
KeyBindingManager, // Load from brackets.test
3232
Menus, // Load from brackets.test
33+
FileSystem, // Load from brackets.test
3334
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
3435
KeyEvent = require("utils/KeyEvent");
3536

@@ -52,6 +53,7 @@ define(function (require, exports, module) {
5253
Commands = testWindow.brackets.test.Commands;
5354
KeyBindingManager = testWindow.brackets.test.KeyBindingManager;
5455
Menus = testWindow.brackets.test.Menus;
56+
FileSystem = testWindow.brackets.test.FileSystem;
5557
}, testWindowOptions);
5658
});
5759

@@ -299,6 +301,55 @@ define(function (require, exports, module) {
299301
isOpen = cmenu.isOpen();
300302
expect(isOpen).toBe(false);
301303
});
304+
305+
it("it should disable context menu items when file doesn't exist ", function () {
306+
runs(function () {
307+
// runs create a new file
308+
var promise = CommandManager.execute(Commands.FILE_NEW_UNTITLED);
309+
waitsForDone(promise, "FILE_NEW_UNTITLED");
310+
311+
// opens context menu
312+
var cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU);
313+
cmenu.open({pageX: 0, pageY: 0});
314+
315+
// checks that all the relevant items are disabled
316+
var notVisible = [Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS];
317+
notVisible.forEach(function (item) { expect(CommandManager.get(item).getEnabled()).toBe(false); });
318+
319+
//close menu and new file
320+
cmenu.close();
321+
322+
});
323+
});
324+
325+
it("it should enable context menu items when file does exist ", function () {
326+
var testPath = SpecRunnerUtils.getTempDirectory();
327+
var newFilePath = testPath + "/contextMenuTest.js";
328+
runs(function () {
329+
// runs create a new file and saves it
330+
SpecRunnerUtils.createTempDirectory();
331+
SpecRunnerUtils.loadProjectInTestWindow(testPath);
332+
var promise = CommandManager.execute(Commands.FILE_NEW_UNTITLED);
333+
334+
waitsForDone(promise, "FILE_NEW_UNTITLED");
335+
336+
spyOn(FileSystem, 'showSaveDialog').andCallFake(function (dialogTitle, initialPath, proposedNewName, callback) {
337+
callback(undefined, newFilePath);
338+
});
339+
340+
promise = CommandManager.execute(Commands.FILE_SAVE);
341+
waitsForDone(promise, "Provide new filename", 5000);
342+
});
343+
runs(function () {
344+
// opens context menu
345+
var cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU);
346+
cmenu.open({pageX: 0, pageY: 0});
347+
348+
// checks that all the items are enabled
349+
var visible = [Commands.FILE_SAVE, Commands.FILE_SAVE_AS, Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS, Commands.CMD_FIND_IN_SUBTREE, Commands.CMD_REPLACE_IN_SUBTREE, Commands.FILE_CLOSE];
350+
visible.forEach(function (item) { expect(CommandManager.get(item).getEnabled()).toBe(true); });
351+
});
352+
});
302353
});
303354
});
304355

0 commit comments

Comments
 (0)