Skip to content

Commit 5541327

Browse files
authored
Merge pull request #628 from Satellite-im/luis/settings-keybinds
test(add): add tests for changing and restoring keybinds
2 parents efc735d + ca2ff05 commit 5541327

File tree

3 files changed

+109
-6
lines changed

3 files changed

+109
-6
lines changed

tests/helpers/commands.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import {
1818
const { readFileSync, rmSync, writeFileSync } = require("fs");
1919
const { execSync } = require("child_process");
2020
const fsp = require("fs").promises;
21-
const { clipboard, keyboard, Key, mouse, Button } = require("@nut-tree/nut-js");
21+
const { clipboard, keyboard, mouse, Button } = require("@nut-tree/nut-js");
2222
const createOrImport = new CreateOrImportScreen();
2323
let createPin = new CreatePinScreen();
2424
let createUser = new CreateUserScreen();
2525
let friendsScreen = new FriendsScreen();
2626
const saveRecoverySeed = new SaveRecoverySeedScreen();
2727
let welcomeScreen = new WelcomeScreen();
2828

29+
export type MyKey = keyof typeof CustomKey;
30+
2931
// Users cache helper functions
3032

3133
export async function deleteCache() {
@@ -505,15 +507,28 @@ export async function getUplinkWindowHandle() {
505507
// Key Combinations Commands
506508

507509
export async function keyboardShortcutPaste() {
508-
await keyboard.type(Key.LeftControl, Key.V);
510+
await keyboard.type(4, 66);
509511
}
510512

511513
export async function keyboardShiftEnter() {
512-
await keyboard.pressKey(Key.LeftShift);
513-
await keyboard.type(Key.Enter);
514-
await keyboard.releaseKey(Key.LeftShift);
514+
await keyboard.pressKey(7);
515+
await keyboard.type(101);
516+
await keyboard.releaseKey(7);
515517
}
516518

517519
export async function pressEscKey() {
518-
await keyboard.type(Key.Escape);
520+
await keyboard.type(1);
521+
}
522+
523+
export async function sendCustomKeybinds(...keys: number[]) {
524+
// To find the number associated for each key to send on keybind, refer to node_modules/@nut-tree/nut-js/dist/lib/key.enum.d.ts
525+
for (let i = 0; i < keys.length - 1; i++) {
526+
await keyboard.pressKey(keys[i]);
527+
}
528+
529+
await keyboard.type(keys[keys.length - 1]);
530+
531+
for (let i = keys.length - 2; i >= 0; i--) {
532+
await keyboard.releaseKey(keys[i]);
533+
}
519534
}

tests/screenobjects/settings/SettingsKeybindsScreen.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,20 @@ export default class SettingsKeybindsScreen extends SettingsBaseScreen {
478478
const revertButton = await this.toggleMuteResetKeybindButton;
479479
await revertButton.click();
480480
}
481+
482+
// Edit Keybinds
483+
async editKeybind(section: Keybinds) {
484+
let sectionToEdit;
485+
const currentDriver = await this.getCurrentDriver();
486+
if (currentDriver === MACOS_DRIVER) {
487+
sectionToEdit = await $(`~${section}-section`).$(
488+
SELECTORS.KEYBIND_SECTION_KEYS,
489+
);
490+
} else if (currentDriver === WINDOWS_DRIVER) {
491+
sectionToEdit = await $(`[name="${section}-section"]`).$(
492+
SELECTORS.KEYBIND_SECTION_KEYS,
493+
);
494+
}
495+
await sectionToEdit?.click();
496+
}
481497
}

tests/specs/18-settings-keybinds.spec.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require("module-alias/register");
2+
import { sendCustomKeybinds } from "@helpers/commands";
23
import { MACOS_DRIVER } from "@helpers/constants";
34
import SettingsExtensionsScreen from "@screenobjects/settings/SettingsExtensionsScreen";
45
import SettingsKeybindsScreen from "@screenobjects/settings/SettingsKeybindsScreen";
@@ -119,4 +120,75 @@ export default async function settingsKeybindsTests() {
119120
await settingsKeybinds.getKeybinds("hide-focus-uplink");
120121
await expect(hideFocusUplinkKeybind).toEqual(["CONTROL", "SHIFT", "U"]);
121122
});
123+
124+
it("Settings Keyboards Shortcuts - Change Increase Font Size Keybind", async () => {
125+
// Type Ctrl + Shift + =
126+
await sendCustomKeybinds(4, 7, 73);
127+
await settingsKeybinds.editKeybind("increase-font-size");
128+
// Type Ctrl + A
129+
await sendCustomKeybinds(4, 45);
130+
131+
const increaseFontSizeKeybind =
132+
await settingsKeybinds.getKeybinds("increase-font-size");
133+
await expect(increaseFontSizeKeybind).toEqual(["CONTROL", "A"]);
134+
});
135+
136+
it("Settings Keyboards Shortcuts - Reset Increase Font Size Keybind", async () => {
137+
await settingsKeybinds.clickOnRevertIncreaseFontSize();
138+
const increaseFontSizeKeybind =
139+
await settingsKeybinds.getKeybinds("increase-font-size");
140+
await expect(increaseFontSizeKeybind).toEqual(["CONTROL", "SHIFT", "="]);
141+
});
142+
143+
it("Settings Keyboards Shortcuts - User can update more than one keybind", async () => {
144+
// Change at least two different keybinds. First, change Decrease Font Size Keybind, by typing Ctrl + Shift + -
145+
await sendCustomKeybinds(4, 7, 72);
146+
// Edit Decrease Font Size Keybind to Ctrl + B
147+
await settingsKeybinds.editKeybind("decrease-font-size");
148+
await sendCustomKeybinds(4, 46);
149+
150+
// Validate change was applied correctly to Decrease Font Size Keybind
151+
const decreaseFontSizeKeybind =
152+
await settingsKeybinds.getKeybinds("decrease-font-size");
153+
await expect(decreaseFontSizeKeybind).toEqual(["CONTROL", "B"]);
154+
155+
// Now, change Hide/Focus Uplink Keybind by typing Ctrl + Shift + U
156+
await sendCustomKeybinds(4, 7, 65);
157+
await settingsKeybinds.editKeybind("hide-focus-uplink");
158+
// Type Alt + Ctrl + Shift + P
159+
await sendCustomKeybinds(3, 4, 7, 60);
160+
161+
// Validate change was applied correctly to Hide/Focus Uplink Keybind
162+
const hideFocusUplinkKeybind =
163+
await settingsKeybinds.getKeybinds("hide-focus-uplink");
164+
await expect(hideFocusUplinkKeybind).toEqual([
165+
"ALT",
166+
"CONTROL",
167+
"SHIFT",
168+
"P",
169+
]);
170+
});
171+
172+
it("Settings Keyboards Shortcuts - User can revert all Keybinds to Default Values", async () => {
173+
// Click on Revert all keybinds
174+
await settingsKeybinds.clickOnRevertAllKeybinds();
175+
176+
// Validate default keys are assigned for Decrease Font Size Keybind (Ctrl + Shift + -)
177+
const decreaseFontSizeKeybindDefault =
178+
await settingsKeybinds.getKeybinds("decrease-font-size");
179+
await expect(decreaseFontSizeKeybindDefault).toEqual([
180+
"CONTROL",
181+
"SHIFT",
182+
"-",
183+
]);
184+
185+
// Validate default keys are assigned for Hide/Show Uplink Keybind (Ctrl + Shift + U)
186+
const hideFocusUplinkKeybindDefault =
187+
await settingsKeybinds.getKeybinds("hide-focus-uplink");
188+
await expect(hideFocusUplinkKeybindDefault).toEqual([
189+
"CONTROL",
190+
"SHIFT",
191+
"U",
192+
]);
193+
});
122194
}

0 commit comments

Comments
 (0)