Skip to content

Commit

Permalink
Merge pull request #626 from Satellite-im/luis/update-keybinds
Browse files Browse the repository at this point in the history
test(update): add common commands for keybinds
  • Loading branch information
luisecm authored Feb 9, 2024
2 parents 4756222 + 335154a commit 9bc3d68
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
18 changes: 17 additions & 1 deletion tests/helpers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
const { readFileSync, rmSync, writeFileSync } = require("fs");
const { execSync } = require("child_process");
const fsp = require("fs").promises;
const { clipboard, mouse, Button } = require("@nut-tree/nut-js");
const { clipboard, keyboard, Key, mouse, Button } = require("@nut-tree/nut-js");
const createOrImport = new CreateOrImportScreen();
let createPin = new CreatePinScreen();
let createUser = new CreateUserScreen();
Expand Down Expand Up @@ -501,3 +501,19 @@ export async function getUplinkWindowHandle() {
}
}
}

// Key Combinations Commands

export async function keyboardShortcutPaste() {
await keyboard.type(Key.LeftControl, Key.V);
}

export async function keyboardShiftEnter() {
await keyboard.pressKey(Key.LeftShift);
await keyboard.type(Key.Enter);
await keyboard.releaseKey(Key.LeftShift);
}

export async function pressEscKey() {
await keyboard.type(Key.Escape);
}
7 changes: 3 additions & 4 deletions tests/screenobjects/chats/CreateGroupChat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { keyboard, Key } = require("@nut-tree/nut-js");
require("module-alias/register");
import { getClipboardMacOS } from "@helpers/commands";
import { getClipboardMacOS, keyboardShortcutPaste } from "@helpers/commands";
import { MACOS_DRIVER, WINDOWS_DRIVER } from "@helpers/constants";
import UplinkMainScreen from "@screenobjects/UplinkMainScreen";

Expand Down Expand Up @@ -238,9 +237,9 @@ export default class CreateGroupChat extends UplinkMainScreen {
} else if (currentDriver === WINDOWS_DRIVER) {
await driver.touchAction([{ action: "press", element: groupNameInput }]);
// If driver is windows, then click on status input to place cursor there and simulate a control + v
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
await driver.touchAction([{ action: "press", element: locator }]);
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}
}

Expand Down
5 changes: 0 additions & 5 deletions tests/screenobjects/chats/EmojiSuggestions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require("module-alias/register");
import { MACOS_DRIVER, WINDOWS_DRIVER } from "@helpers/constants";
import UplinkMainScreen from "@screenobjects/UplinkMainScreen";
const { keyboard, Key } = require("@nut-tree/nut-js");
let SELECTORS = {};

const SELECTORS_COMMON = {};
Expand Down Expand Up @@ -91,10 +90,6 @@ export default class EmojiSuggestions extends UplinkMainScreen {
return results;
}

async pressEscKey() {
await keyboard.type(Key.Escape);
}

async validateEmojiSuggestionsContainerIsShown() {
await this.emojiSuggestionsContainer.waitForDisplayed();
}
Expand Down
9 changes: 4 additions & 5 deletions tests/screenobjects/chats/InputBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ require("module-alias/register");
import { faker } from "@faker-js/faker";
import { MACOS_DRIVER, WINDOWS_DRIVER } from "@helpers/constants";
import {
keyboardShiftEnter,
keyboardShortcutPaste,
getUplinkWindowHandle,
selectFileOnMacos,
selectFileOnWindows,
} from "@helpers/commands";
import UplinkMainScreen from "@screenobjects/UplinkMainScreen";
const { keyboard, Key } = require("@nut-tree/nut-js");
let SELECTORS = {};

const SELECTORS_COMMON = {
Expand Down Expand Up @@ -184,7 +185,7 @@ export default class InputBar extends UplinkMainScreen {
const inputText = await this.inputText;
await inputText.click();
await inputText.clearValue();
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}

async pressEnterKeyOnInputBar() {
Expand Down Expand Up @@ -215,9 +216,7 @@ export default class InputBar extends UplinkMainScreen {
if (inputTextValueLanguage.includes("```" + language) === false) {
await this.typeCodeOnInputBar(language, codeToType);
} else {
await keyboard.pressKey(Key.LeftShift);
await keyboard.type(Key.Enter);
await keyboard.releaseKey(Key.LeftShift);
await keyboardShiftEnter();
await inputText.addValue(codeToType);
let inputTextValueCode = await inputText.getText();
inputTextValueCode += " ";
Expand Down
7 changes: 3 additions & 4 deletions tests/screenobjects/friends/FriendsScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import UplinkMainScreen from "@screenobjects/UplinkMainScreen";

import {
getClipboardMacOS,
keyboardShortcutPaste,
rightClickOnMacOS,
rightClickOnWindows,
} from "@helpers/commands";

const { keyboard, Key } = require("@nut-tree/nut-js");

let SELECTORS = {};

const SELECTORS_COMMON = {
Expand Down Expand Up @@ -429,7 +428,7 @@ export default class FriendsScreen extends UplinkMainScreen {
await copyIdButton.click();
const addSomeoneInput = await this.addSomeoneInput;
await addSomeoneInput.clearValue();
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}
}

Expand Down Expand Up @@ -731,7 +730,7 @@ export default class FriendsScreen extends UplinkMainScreen {
const addSomeoneInput = await this.addSomeoneInput;
await addSomeoneInput.click();
await addSomeoneInput.clearValue();
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/screenobjects/settings/SettingsProfileScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getUplinkWindowHandle,
hoverOnMacOS,
hoverOnWindows,
keyboardShortcutPaste,
rightClickOnMacOS,
rightClickOnWindows,
selectFileOnMacos,
Expand All @@ -12,7 +13,6 @@ import {
import { MACOS_DRIVER, WINDOWS_DRIVER } from "@helpers/constants";
import SettingsBaseScreen from "@screenobjects/settings/SettingsBaseScreen";

const { keyboard, Key } = require("@nut-tree/nut-js");
let SELECTORS = {};

const SELECTORS_COMMON = {
Expand Down Expand Up @@ -462,7 +462,7 @@ export default class SettingsProfileScreen extends SettingsBaseScreen {
await browser.pause(1000);
await statusInput.click();
await statusInput.clearValue();
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}
await statusInput.waitUntil(
async () => {
Expand Down Expand Up @@ -490,7 +490,7 @@ export default class SettingsProfileScreen extends SettingsBaseScreen {
await browser.pause(1000);
await statusInput.click();
await statusInput.clearValue();
await keyboard.type(Key.LeftControl, Key.V);
await keyboardShortcutPaste();
}
await statusInput.waitUntil(
async () => {
Expand Down

0 comments on commit 9bc3d68

Please sign in to comment.