-
-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy pathKeyboard-nav-integ-test.js
More file actions
221 lines (192 loc) · 9.17 KB
/
Keyboard-nav-integ-test.js
File metadata and controls
221 lines (192 loc) · 9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global describe, it, expect, beforeAll, afterAll, awaitsFor, awaitsForDone, awaits */
define(function (require, exports, module) {
// Recommended to avoid reloading the integration test window Phoenix instance for each test.
const SpecRunnerUtils = require("spec/SpecRunnerUtils"),
Keys = require("command/Keys");
const testPath = SpecRunnerUtils.getTestPath("/spec/JSUtils-test-files");
let FileViewController, // loaded from brackets.test
ProjectManager, // loaded from brackets.test;
MainViewManager,
CommandManager,
Commands,
testWindow,
brackets;
describe("mainview:Keyboard navigation overlay integ tests tests", function () {
beforeAll(async function () {
// do not use force option in brackets core integration tests. Tests are assumed to reuse the existing
// test window instance for fast runs.
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
brackets = testWindow.brackets;
FileViewController = brackets.test.FileViewController;
ProjectManager = brackets.test.ProjectManager;
MainViewManager = brackets.test.MainViewManager;
CommandManager = brackets.test.CommandManager;
Commands = brackets.test.Commands;
await SpecRunnerUtils.loadProjectInTestWindow(testPath);
}, 30000);
afterAll(async function () {
MainViewManager.setLayoutScheme(1, 1);
FileViewController = null;
ProjectManager = null;
testWindow = null;
brackets = null;
// comment out below line if you want to debug the test window post running tests
await SpecRunnerUtils.closeTestWindow();
}, 30000);
function tripleControlEvent() {
keyboardType(Keys.KEY.CONTROL);
keyboardType(Keys.KEY.CONTROL, "keyup");
keyboardType(Keys.KEY.CONTROL);
keyboardType(Keys.KEY.CONTROL, "keyup");
keyboardType(Keys.KEY.CONTROL);
}
function tripleControlContinuousEvent() {
keyboardType(Keys.KEY.CONTROL);
keyboardType(Keys.KEY.CONTROL);
keyboardType(Keys.KEY.CONTROL);
}
function keyboardType(key, type) {
const ctrlEvent = new KeyboardEvent(type || "keydown", {
key: key,
bubbles: true, // Event bubbles up through the DOM
cancelable: true, // Event can be canceled,
code: key
});
testWindow.$("#Phoenix-Main")[0].dispatchEvent(ctrlEvent);
}
/**
*
* @param path
* @param {string?} paneID
* @return {Promise<void>}
*/
async function openAnyFile(path = "/simple.js", paneID) {
await awaitsForDone(
FileViewController.openAndSelectDocument(
testPath + path,
FileViewController.PROJECT_MANAGER,
paneID
));
const selected = ProjectManager.getSelectedItem();
expect(selected.fullPath).toBe(testPath + path);
}
async function _openUiNavMode() {
await awaitsForDone(CommandManager.execute(Commands.CMD_KEYBOARD_NAV_UI_OVERLAY));
await awaitsFor(()=>{
return testWindow.$('#ctrl-nav-overlay').is(":visible");
}, "overlay to be shown");
}
it("Should show overlay on triple control and exit on escape", async function () {
MainViewManager.setLayoutScheme(1, 1);
await openAnyFile();
tripleControlEvent();
await awaitsFor(()=>{
return testWindow.$('#ctrl-nav-overlay').is(":visible");
}, "overlay to be shown");
// escape should exit
keyboardType(Keys.KEY.ESCAPE);
await awaitsFor(()=>{
return !testWindow.$('#ctrl-nav-overlay').is(":visible");
}, "overlay to be closed");
});
it("Should not show overlay on triple control continuous press", async function () {
MainViewManager.setLayoutScheme(1, 1);
await openAnyFile();
await awaitsFor(()=>{
return !testWindow.$('#ctrl-nav-overlay').is(":visible");
}, "overlay to be not visible");
tripleControlContinuousEvent();
await awaits(20); // give some time so that we are sure that the overlay didn't come up.
expect(testWindow.$('#ctrl-nav-overlay').is(":visible")).toBeFalse();
});
async function _verifyMenuNav() {
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_UP);
await awaitsFor(()=>{
return testWindow.$('#titlebar .dropdown.open').length === 1;
}, "menu to open");
keyboardType(Keys.KEY.ESCAPE);
}
it("Should navigate to top menu on up arrow press", async function () {
MainViewManager.setLayoutScheme(1, 1);
await openAnyFile();
await _verifyMenuNav();
});
it("Should navigate vertical split panes on left and right arrow key press", async function () {
MainViewManager.setLayoutScheme(1, 2);
await openAnyFile("/edit.js", MainViewManager.SECOND_PANE);
await openAnyFile("/simple.js", MainViewManager.FIRST_PANE);
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
await _verifyMenuNav();
MainViewManager.setActivePaneId(MainViewManager.SECOND_PANE);
await _verifyMenuNav();
// right arrow to switch to right pane
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_RIGHT);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.SECOND_PANE);
// left arrow to switch to left pane
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_LEFT);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.FIRST_PANE);
});
it("Should navigate horizontal split panes on up and down arrow key press", async function () {
MainViewManager.setLayoutScheme(2, 1);
await openAnyFile("/edit.js", MainViewManager.SECOND_PANE);
await openAnyFile("/simple.js", MainViewManager.FIRST_PANE);
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
await _verifyMenuNav();
// right arrow to switch to right pane
MainViewManager.setActivePaneId(MainViewManager.SECOND_PANE);
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_UP);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.FIRST_PANE);
// left arrow to switch to left pane
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_DOWN);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.SECOND_PANE);
});
it("Should navigate be able to focus on a pane with no editor", async function () {
MainViewManager.setLayoutScheme(1, 2);
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE_ALL, { _forceClose: true }),
"closing all file");
await openAnyFile("/simple.js", MainViewManager.FIRST_PANE);
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
// right arrow to switch to right pane
MainViewManager.setActivePaneId(MainViewManager.FIRST_PANE);
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_RIGHT);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.SECOND_PANE);
// left arrow to switch to left pane
await _openUiNavMode();
keyboardType(Keys.KEY.ARROW_LEFT);
keyboardType(Keys.KEY.ENTER);
expect(MainViewManager.getActivePaneId()).toBe(MainViewManager.FIRST_PANE);
});
});
});