|
| 1 | +/* |
| 2 | + * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | + * copy of this software and associated documentation files (the "Software"), |
| 6 | + * to deal in the Software without restriction, including without limitation |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | + * Software is furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | + * DEALINGS IN THE SOFTWARE. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */ |
| 25 | +/*global define, describe, it, expect, beforeFirst, afterLast, beforeEach, afterEach, runs, brackets, waitsFor, waitsForDone, spyOn */ |
| 26 | + |
| 27 | +define(function (require, exports, module) { |
| 28 | + "use strict"; |
| 29 | + |
| 30 | + var SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"), |
| 31 | + FileUtils = brackets.getModule("file/FileUtils"), |
| 32 | + KeyEvent = brackets.getModule("utils/KeyEvent"), |
| 33 | + _ = brackets.getModule("thirdparty/lodash"); |
| 34 | + |
| 35 | + describe("Recent Projects", function () { |
| 36 | + var extensionPath = FileUtils.getNativeModuleDirectoryPath(module), |
| 37 | + testWindow, |
| 38 | + $, |
| 39 | + CommandManager, |
| 40 | + PreferencesManager; |
| 41 | + |
| 42 | + beforeFirst(function () { |
| 43 | + runs(function () { |
| 44 | + SpecRunnerUtils.createTestWindowAndRun(this, function (w) { |
| 45 | + testWindow = w; |
| 46 | + $ = testWindow.$; |
| 47 | + CommandManager = testWindow.brackets.test.CommandManager; |
| 48 | + PreferencesManager = testWindow.brackets.test.PreferencesManager; |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + afterLast(function () { |
| 54 | + testWindow = null; |
| 55 | + SpecRunnerUtils.closeTestWindow(); |
| 56 | + }); |
| 57 | + |
| 58 | + function openRecentProjectDropDown() { |
| 59 | + var flag = false; |
| 60 | + CommandManager.execute("recentProjects.toggle"); |
| 61 | + testWindow.setTimeout(function () { |
| 62 | + flag = true; |
| 63 | + }, 100); |
| 64 | + |
| 65 | + waitsFor(function () { return flag; }); |
| 66 | + } |
| 67 | + |
| 68 | + function setupRecentProjectsSpy(howManyProjects) { |
| 69 | + spyOn(PreferencesManager, "getViewState").andCallFake(function (prefId) { |
| 70 | + if (prefId === "recentProjects") { |
| 71 | + // return howManyProjects recent projects |
| 72 | + return _.map(_.range(1, howManyProjects + 1), function (num) { return extensionPath + "/Test-Project-" + num; }); |
| 73 | + } else { |
| 74 | + return []; |
| 75 | + } |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + describe("UI", function () { |
| 80 | + it("should open the recent projects list with only the getting started project", function () { |
| 81 | + runs(function () { |
| 82 | + openRecentProjectDropDown(); |
| 83 | + }); |
| 84 | + |
| 85 | + runs(function () { |
| 86 | + var $dropDown = $("#project-dropdown"); |
| 87 | + expect($("#project-dropdown").is(":visible")).toEqual(true); |
| 88 | + expect($dropDown.children().length).toEqual(1); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + it("should open the recent project list and show 5 recent projects", function () { |
| 93 | + setupRecentProjectsSpy(5); |
| 94 | + |
| 95 | + runs(function () { |
| 96 | + openRecentProjectDropDown(); |
| 97 | + }); |
| 98 | + |
| 99 | + runs(function () { |
| 100 | + var $dropDown = $("#project-dropdown"); |
| 101 | + expect($dropDown.is(":visible")).toEqual(true); |
| 102 | + expect($dropDown.find(".recent-folder-link").length).toEqual(5); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + it("should delete one project from recent project list when delete key is pressed on", function () { |
| 107 | + setupRecentProjectsSpy(5); |
| 108 | + |
| 109 | + runs(function () { |
| 110 | + openRecentProjectDropDown(); |
| 111 | + }); |
| 112 | + |
| 113 | + runs(function () { |
| 114 | + var $dropDown = $("#project-dropdown"); |
| 115 | + SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_DOWN, "keydown", $dropDown[0]); |
| 116 | + SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_DELETE, "keydown", $dropDown[0]); |
| 117 | + }); |
| 118 | + |
| 119 | + runs(function () { |
| 120 | + var $dropDown = $("#project-dropdown"); |
| 121 | + expect($dropDown.is(":visible")).toEqual(true); |
| 122 | + expect($dropDown.find(".recent-folder-link").length).toEqual(4); |
| 123 | + }); |
| 124 | + }); |
| 125 | + }); |
| 126 | + }); |
| 127 | +}); |
0 commit comments