|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Affero General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +/*global describe, path, it, expect, awaitsForDone, beforeAll, afterAll */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + |
| 26 | + |
| 27 | + // Load dependent modules |
| 28 | + let DocumentManager, // loaded from brackets.test |
| 29 | + EditorManager, // loaded from brackets.test |
| 30 | + MainViewManager, // loaded from brackets.test |
| 31 | + CommandManager, |
| 32 | + Commands, |
| 33 | + SpecRunnerUtils = require("spec/SpecRunnerUtils"); |
| 34 | + |
| 35 | + |
| 36 | + describe("integration:Misc", function () { |
| 37 | + |
| 38 | + let testWindow, |
| 39 | + _$; |
| 40 | + |
| 41 | + beforeAll(async function () { |
| 42 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 43 | + _$ = testWindow.$; |
| 44 | + |
| 45 | + // Load module instances from brackets.test |
| 46 | + DocumentManager = testWindow.brackets.test.DocumentManager; |
| 47 | + EditorManager = testWindow.brackets.test.EditorManager; |
| 48 | + MainViewManager = testWindow.brackets.test.MainViewManager; |
| 49 | + CommandManager = testWindow.brackets.test.CommandManager; |
| 50 | + Commands = testWindow.brackets.test.Commands; |
| 51 | + }, 30000); |
| 52 | + |
| 53 | + afterAll(async function () { |
| 54 | + await SpecRunnerUtils.parkProject(true); |
| 55 | + testWindow = null; |
| 56 | + DocumentManager = null; |
| 57 | + EditorManager = null; |
| 58 | + MainViewManager = null; |
| 59 | + CommandManager = null; |
| 60 | + Commands = null; |
| 61 | + await SpecRunnerUtils.closeTestWindow(); |
| 62 | + }, 30000); |
| 63 | + |
| 64 | + async function _openProjectFile(fileName, paneID) { |
| 65 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles([fileName], paneID), "opening "+ fileName); |
| 66 | + } |
| 67 | + |
| 68 | + async function _closeCurrentFile() { |
| 69 | + await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE)); |
| 70 | + } |
| 71 | + |
| 72 | + async function _reopenClosedFile() { |
| 73 | + await awaitsForDone(CommandManager.execute(Commands.FILE_REOPEN_CLOSED)); |
| 74 | + } |
| 75 | + |
| 76 | + describe("reopen closed files test", function () { |
| 77 | + let currentProjectPath; |
| 78 | + beforeAll(async function () { |
| 79 | + // Working set behavior is sensitive to whether file lives in the project or outside it, so make |
| 80 | + // the project root a known quantity. |
| 81 | + currentProjectPath = await SpecRunnerUtils.getTempTestDirectory("/spec/DocumentCommandHandlers-test-files"); |
| 82 | + await SpecRunnerUtils.loadProjectInTestWindow(currentProjectPath); |
| 83 | + }); |
| 84 | + |
| 85 | + afterAll(async function () { |
| 86 | + MainViewManager.setLayoutScheme(1, 1); |
| 87 | + await SpecRunnerUtils.parkProject(true); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should reopen be disabled at first and then enabled on closing a file", async function () { |
| 91 | + const testFilePath = "test.js"; |
| 92 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 93 | + await _openProjectFile(testFilePath); |
| 94 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 95 | + await _closeCurrentFile(); |
| 96 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 97 | + await _reopenClosedFile(); |
| 98 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 99 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 100 | + .toEqual(path.join(currentProjectPath, testFilePath)); |
| 101 | + }); |
| 102 | + |
| 103 | + it("should reopen multiple files", async function () { |
| 104 | + const testFilePath = "test.js", testFilePath2 = "couz.png"; |
| 105 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 106 | + await _openProjectFile(testFilePath); |
| 107 | + await _openProjectFile(testFilePath2); |
| 108 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 109 | + await _closeCurrentFile(); // couz.png is closed |
| 110 | + await _closeCurrentFile(); // test.js - closed. so the reopen order is js then png |
| 111 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 112 | + await _reopenClosedFile(); |
| 113 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 114 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 115 | + .toEqual(path.join(currentProjectPath, testFilePath)); |
| 116 | + await _reopenClosedFile(); |
| 117 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 118 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 119 | + .toEqual(path.join(currentProjectPath, testFilePath2)); |
| 120 | + }); |
| 121 | + |
| 122 | + it("should reopen multiple files in multiple panes", async function () { |
| 123 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 124 | + const test = "test.js", test2 = "couz.png"; |
| 125 | + const couz = "couz.png", couz2 = "couz2.png"; |
| 126 | + MainViewManager.setLayoutScheme(1, 2); |
| 127 | + await _openProjectFile(test, MainViewManager.FIRST_PANE); |
| 128 | + await _openProjectFile(couz, MainViewManager.FIRST_PANE); |
| 129 | + await _openProjectFile(test2, MainViewManager.SECOND_PANE); |
| 130 | + await _openProjectFile(couz2, MainViewManager.SECOND_PANE); |
| 131 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 132 | + MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE); |
| 133 | + await _closeCurrentFile(); // couz.png is closed |
| 134 | + MainViewManager.setActivePaneId(MainViewManager.SECOND_PANE); |
| 135 | + await _closeCurrentFile(); // couz2.png is closed. so the reopen order is couz2 then couz |
| 136 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 137 | + MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE); |
| 138 | + await _reopenClosedFile(); |
| 139 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 140 | + expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.SECOND_PANE); |
| 141 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 142 | + .toEqual(path.join(currentProjectPath, couz2)); |
| 143 | + await _reopenClosedFile(); |
| 144 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 145 | + expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.FIRST_PANE); |
| 146 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 147 | + .toEqual(path.join(currentProjectPath, couz)); |
| 148 | + }); |
| 149 | + |
| 150 | + it("should reopen multiple files even if multiple panes collapses into single", async function () { |
| 151 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 152 | + const test = "test.js", test2 = "couz.png"; |
| 153 | + const couz = "couz.png", couz2 = "couz2.png"; |
| 154 | + MainViewManager.setLayoutScheme(1, 2); |
| 155 | + await _openProjectFile(test, MainViewManager.FIRST_PANE); |
| 156 | + await _openProjectFile(couz, MainViewManager.FIRST_PANE); |
| 157 | + await _openProjectFile(test2, MainViewManager.SECOND_PANE); |
| 158 | + await _openProjectFile(couz2, MainViewManager.SECOND_PANE); |
| 159 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 160 | + MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE); |
| 161 | + await _closeCurrentFile(); // couz.png is closed |
| 162 | + MainViewManager.setActivePaneId(MainViewManager.SECOND_PANE); |
| 163 | + await _closeCurrentFile(); // couz2.png is closed. so the reopen order is couz2 then couz |
| 164 | + // now we move to a single pane layout from multi pane. reopen should still work |
| 165 | + MainViewManager.setLayoutScheme(1, 1); |
| 166 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 167 | + await _reopenClosedFile(); |
| 168 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeTrue(); |
| 169 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 170 | + .toEqual(path.join(currentProjectPath, couz2)); |
| 171 | + await _reopenClosedFile(); |
| 172 | + expect(CommandManager.get(Commands.FILE_REOPEN_CLOSED).getEnabled()).toBeFalse(); |
| 173 | + expect(MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE)) |
| 174 | + .toEqual(path.join(currentProjectPath, couz)); |
| 175 | + }); |
| 176 | + }); |
| 177 | + }); |
| 178 | +}); |
0 commit comments