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

Create tests for Disabled context menu items for unsaved files / #12806 #13134 #13178

Merged
merged 2 commits into from
Mar 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion test/spec/Menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

/*global describe, it, expect, runs, beforeFirst, afterLast */
/*global describe, it, expect, runs, beforeFirst, afterLast, waitsForDone, spyOn*/

define(function (require, exports, module) {
"use strict";
Expand All @@ -30,6 +30,7 @@ define(function (require, exports, module) {
Commands, // Load from brackets.test
KeyBindingManager, // Load from brackets.test
Menus, // Load from brackets.test
FileSystem, // Load from brackets.test
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
KeyEvent = require("utils/KeyEvent");

Expand All @@ -52,6 +53,7 @@ define(function (require, exports, module) {
Commands = testWindow.brackets.test.Commands;
KeyBindingManager = testWindow.brackets.test.KeyBindingManager;
Menus = testWindow.brackets.test.Menus;
FileSystem = testWindow.brackets.test.FileSystem;
}, testWindowOptions);
});

Expand Down Expand Up @@ -299,6 +301,55 @@ define(function (require, exports, module) {
isOpen = cmenu.isOpen();
expect(isOpen).toBe(false);
});

it("it should disable context menu items when file doesn't exist ", function () {
runs(function () {
// runs create a new file
var promise = CommandManager.execute(Commands.FILE_NEW_UNTITLED);
waitsForDone(promise, "FILE_NEW_UNTITLED");

// opens context menu
var cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU);
cmenu.open({pageX: 0, pageY: 0});

// checks that all the relevant items are disabled
var notVisible = [Commands.FILE_RENAME, Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS];
notVisible.forEach(function (item) { expect(CommandManager.get(item).getEnabled()).toBe(false); });

//close menu and new file
cmenu.close();

});
});

it("it should enable context menu items when file does exist ", function () {
var testPath = SpecRunnerUtils.getTempDirectory();
var newFilePath = testPath + "/contextMenuTest.js";
runs(function () {
// runs create a new file and saves it
SpecRunnerUtils.createTempDirectory();
SpecRunnerUtils.loadProjectInTestWindow(testPath);
var promise = CommandManager.execute(Commands.FILE_NEW_UNTITLED);

waitsForDone(promise, "FILE_NEW_UNTITLED");

spyOn(FileSystem, 'showSaveDialog').andCallFake(function (dialogTitle, initialPath, proposedNewName, callback) {
callback(undefined, newFilePath);
});

promise = CommandManager.execute(Commands.FILE_SAVE);
waitsForDone(promise, "Provide new filename", 5000);
});
runs(function () {
// opens context menu
var cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU);
cmenu.open({pageX: 0, pageY: 0});

// checks that all the items are enabled
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];
visible.forEach(function (item) { expect(CommandManager.get(item).getEnabled()).toBe(true); });
});
});
});
});

Expand Down