Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(update): add common commands for keybinds #626

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading