Skip to content

Commit

Permalink
Merge pull request #594 from Satellite-im/luis/import-account
Browse files Browse the repository at this point in the history
test(add): add test for import account screen
  • Loading branch information
luisecm authored Jan 17, 2024
2 parents 9937b5c + b635d0d commit 0afad3c
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 37 deletions.
1 change: 1 addition & 0 deletions config/wdio.windows.app.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const config: WebdriverIO.Config = {
},
],
],
specFileRetries: 1,
//
// =====
// Hooks
Expand Down
1 change: 1 addition & 0 deletions config/wdio.windows.ci.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const config: WebdriverIO.Config = {
},
],
],
specFileRetries: 1,
//
// =====
// Hooks
Expand Down
35 changes: 31 additions & 4 deletions tests/helpers/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,35 @@ export async function resetAndLoginWithCache(user: string) {
await loadTestUserData(user);
await launchApplication(MACOS_BUNDLE_ID, WINDOWS_APP);
await loginWithTestUser();
await maximizeWindow();
}

export async function saveUserRecoverySeed(username: string, data: string[]) {
// Save JSON file with keys
const currentDriver = process.env.DRIVER;
const target = "./tests/fixtures/users/" + currentDriver;
const filepath = target + "/" + username + "-seed.txt";
await fsp.mkdir(target, { recursive: true });
let recoverySeedWords = "";
for (let word of data) {
recoverySeedWords += word + " ";
}
recoverySeedWords = recoverySeedWords.slice(0, -1);
try {
await writeFileSync(filepath, recoverySeedWords, "utf8");
console.log("Recovery Seed successfully saved");
} catch (error) {
console.log("An error has occurred while saving recovery seed", error);
}
}

export async function getUserRecoverySeed(username: string) {
// Read user data from JSON file
const currentDriver = process.env.DRIVER;
const source =
"./tests/fixtures/users/" + currentDriver + "/" + username + "-seed.txt";
const file = await readFileSync(source, { encoding: "utf8", flag: "r" });
return file;
}

// Application Manage Functions
Expand Down Expand Up @@ -265,11 +294,9 @@ export async function closeSecondApplication() {

export async function maximizeWindow() {
if (process.env.DRIVER === WINDOWS_DRIVER) {
const button = await $('[name="square-button"]');
await button.click();
await $('[name="square-button"]').click();
} else if (process.env.DRIVER === MACOS_DRIVER) {
const button = await $("~_XCUI:FullScreenWindow");
await button.click();
(await $("~_XCUI:FullScreenWindow")).click();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SELECTORS_MACOS = {
CREATE_NEW_ACCOUNT_BUTTON: "~create-button",
CREATE_OR_RECOVER_LABEL: "~create-or-recover",
CREATE_OR_RECOVER_LABEL_TEXT: "-ios class chain:**/XCUIElementTypeStaticText",
IMPORT_ACCOUNT_BUTTON: "~recovery-button",
IMPORT_ACCOUNT_BUTTON: "~recover-button",
RECOVERY_LAYOUT: "~create-or-recover-layout",
RECOVERY_PARAGRAPH: "~create-or-recover-instructions",
RECOVERY_PARAGRAPH_TEXT: "-ios class chain:**/XCUIElementTypeStaticText",
Expand Down
17 changes: 15 additions & 2 deletions tests/screenobjects/account-creation/CreatePinScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export default class CreatePinScreen extends UplinkMainScreen {
}

async enterPin(pin: string) {
const pinInput = await this.pinInput;
await pinInput.setValue(pin);
(await this.pinInput).click();
await this.pinInput.setValue(pin);
}

async clickOnCreateAccount() {
Expand Down Expand Up @@ -136,4 +136,17 @@ export default class CreatePinScreen extends UplinkMainScreen {
await rightClickOnWindows(helpButton);
}
}

async waitUntilCreateAccountButtonIsEnabled() {
const createAccountButton = await this.createAccountButton;
await driver.waitUntil(
async () => {
return await createAccountButton.waitForEnabled();
},
{
timeout: 30000,
timeoutMsg: "Expected status was not changed to enabled after 30s",
},
);
}
}
13 changes: 13 additions & 0 deletions tests/screenobjects/account-creation/CreateUserScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,17 @@ export default class CreateUserScreen extends UplinkMainScreen {
}
return result.toString().toLowerCase();
}

async waitUntilCreateAccountButtonIsEnabled() {
const createAccountButton = await this.createAccountButton;
await driver.waitUntil(
async () => {
return await createAccountButton.waitForEnabled();
},
{
timeout: 30000,
timeoutMsg: "Expected status was not changed to enabled after 30s",
},
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ const SELECTORS_WINDOWS = {
GO_BACK_BUTTON: '[name="back-button"]',
RECOVER_ACCOUNT_BUTTON: '[name="recover-account-button"]',
RECOVERY_SEED_HELPER: '[name="instructions"]',
RECOVERY_SEED_HELPER_TEXT: "<Text>",
RECOVERY_SEED_HELPER_TEXT:
'//Text[contains(@Name, "Type your recovery seed")]',
RECOVERY_SEED_INPUT: '[name="recovery-seed-input"]',
RECOVERY_SEED_TITLE: '[name="enter-seed-words"]',
RECOVERY_SEED_TITLE_TEXT: "<Text>",
RECOVERY_SEED_TITLE_TEXT: '//Text[@Name="RECOVERY SEED"]',
};

const SELECTORS_MACOS = {
Expand All @@ -25,7 +26,7 @@ const SELECTORS_MACOS = {
RECOVERY_SEED_HELPER_TEXT: "-ios class chain:**/XCUIElementTypeStaticText",
RECOVERY_SEED_INPUT: "~recovery-seed-input",
RECOVERY_SEED_TITLE: "~enter-seed-words",
RECOVERY_SEED_TITLE_TEXT: "<Text>",
RECOVERY_SEED_TITLE_TEXT: "-ios class chain:**/XCUIElementTypeStaticText",
};

process.env.DRIVER === WINDOWS_DRIVER
Expand Down
2 changes: 1 addition & 1 deletion tests/screenobjects/friends/FriendsScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default class FriendsScreen extends UplinkMainScreen {
}

get contextMenuCopyDidKey() {
return $(SELECTORS.CONTEXT_MENU_COPY_DID_KEY);
return this.contextMenu.$(SELECTORS.CONTEXT_MENU_COPY_DID_KEY);
}

get contextMenuCopyId() {
Expand Down
6 changes: 5 additions & 1 deletion tests/specs/01-create-account.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("module-alias/register");
import { maximizeWindow } from "@helpers/commands";
import { maximizeWindow, saveUserRecoverySeed } from "@helpers/commands";
import CreateOrImportScreen from "@screenobjects/account-creation/CreateOrImportScreen";
import CreatePinScreen from "@screenobjects/account-creation/CreatePinScreen";
import CreateUserScreen from "@screenobjects/account-creation/CreateUserScreen";
Expand Down Expand Up @@ -110,6 +110,7 @@ export default async function createAccountTests() {

it("Enter Pin Screen - Enter a valid pin and continue creating a username", async () => {
await createPin.enterPin("1234");
await createPin.waitUntilCreateAccountButtonIsEnabled();
const statusOfButton = await createPin.getStatusOfCreateAccountButton();
await expect(statusOfButton).toEqual("true");
await createPin.clickOnCreateAccount();
Expand Down Expand Up @@ -154,6 +155,8 @@ export default async function createAccountTests() {
it("Save Recovery Seed Screen - User can click on I Saved It to continue", async () => {
// Click on I Saved It Button to continue to Enter Username Screen
await saveRecoverySeed.waitForIsShown(true);
const recoverySeed = await saveRecoverySeed.getSeedWords();
await saveUserRecoverySeed("Test123", recoverySeed);
await saveRecoverySeed.clickOnISavedItButton();
await createUser.waitForIsShown(true);
});
Expand Down Expand Up @@ -228,6 +231,7 @@ export default async function createAccountTests() {

it("Enter Username Screen - Enter valid username to continue", async () => {
await createUser.enterUsername("Test123");
await createUser.waitUntilCreateAccountButtonIsEnabled();
const statusOfButton = await createPin.getStatusOfCreateAccountButton();
await expect(statusOfButton).toEqual("true");
await createUser.clickOnCreateAccount();
Expand Down
47 changes: 47 additions & 0 deletions tests/specs/16-import-account.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require("module-alias/register");
import { getUserRecoverySeed, resetApp } from "@helpers/commands";
import CreateOrImportScreen from "@screenobjects/account-creation/CreateOrImportScreen";
import CreatePinScreen from "@screenobjects/account-creation/CreatePinScreen";
import EnterRecoverySeedScreen from "@screenobjects/account-creation/EnterRecoverySeedScreen";
import WelcomeScreen from "@screenobjects/welcome-screen/WelcomeScreen";
const createOrImport = new CreateOrImportScreen();
const createPin = new CreatePinScreen();
const enterRecoverySeed = new EnterRecoverySeedScreen();
const welcomeScreen = new WelcomeScreen();

export default async function importAccountTests() {
it("Enter Pin Screen - Clear cache, reset app and enter a valid pin", async () => {
// Clear cache and reset app
await resetApp();

// Validate Enter Pin Screen is displayed and enter a valid pin
await createPin.waitForIsShown(true);
await createPin.enterPin("1234");
await createPin.waitUntilCreateAccountButtonIsEnabled();
await createPin.clickOnCreateAccount();
});

it("Enter Recovery Seed - Validate Screen Contents", async () => {
// Validate Create or Import Account is displayed
await createOrImport.waitForIsShown(true);

// Click on Import Account
await createOrImport.clickOnImportAccount();

// Validate contents of Enter Recovery Seed Screen
await enterRecoverySeed.waitForIsShown(true);
const helperText = await enterRecoverySeed.recoverySeedHelperText;
const screenTitle = await enterRecoverySeed.recoverySeedTitleText;
await expect(helperText).toHaveTextContaining(
"Type your recovery seed here. You may either enter one word at a time or all at once separated by spaces.",
);
await expect(screenTitle).toHaveTextContaining("RECOVERY SEED");
});

it("Save Recovery Seed Screen - Enter valid recovery seed and continue", async () => {
const recoverySeed = await getUserRecoverySeed("Test123");
await enterRecoverySeed.typeOnRecoverySeedInput(recoverySeed);
await enterRecoverySeed.clickOnRecoverAccountButton();
await welcomeScreen.waitForIsShown(true);
});
}
2 changes: 2 additions & 0 deletions tests/suites/MainTests/01-UplinkTests.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import settingsAccessibilityTests from "@specs/10-settings-accessibility.spec";
import settingsAboutTests from "@specs/11-settings-about.spec";
import settingsLicensesTests from "@specs/12-settings-licenses.spec";
import settingsDeveloperTests from "@specs/13-settings-developer.spec";
import importAccountTests from "@specs/16-import-account.spec";

describe("MacOS Tests", function () {
describe("Create Pin and Account Tests", createAccountTests.bind(this));
Expand All @@ -35,4 +36,5 @@ describe("MacOS Tests", function () {
describe("Settings Licenses Tests", settingsLicensesTests.bind(this));
describe("Settings Developer Tests", settingsDeveloperTests.bind(this));
describe("Friends Screen Tests", friendsTests.bind(this));
describe("Import Account Tests", importAccountTests.bind(this));
});
58 changes: 33 additions & 25 deletions tests/suites/MainTests/02-UplinkWindows.suite.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
require("module-alias/register");
import createAccount from "@specs/01-create-account.spec";
import chats from "@specs/02-chats.spec";
import files from "@specs/03-files.spec";
import createAccountTests from "@specs/01-create-account.spec";
import chatsTests from "@specs/02-chats.spec";
import filesTests from "@specs/03-files.spec";
import settingsProfileTests from "@specs/05-settings-profile.spec";
import settingsGeneral from "@specs/06-settings-general.spec";
import settingsMessages from "@specs/15-settings-messages.spec";
import settingsAudio from "@specs/07-settings-audio.spec";
import settingsExtensions from "@specs/08-settings-extensions.spec";
import settingsNotifications from "@specs/09-settings-notifications.spec";
import settingsAccessibility from "@specs/10-settings-accessibility.spec";
import settingsAbout from "@specs/11-settings-about.spec";
import settingsLicenses from "@specs/12-settings-licenses.spec";
import settingsDeveloper from "@specs/13-settings-developer.spec";
import settingsGeneralTests from "@specs/06-settings-general.spec";
import settingsMessagesTests from "@specs/15-settings-messages.spec";
import settingsAudioTests from "@specs/07-settings-audio.spec";
import settingsExtensionsTests from "@specs/08-settings-extensions.spec";
import settingsNotificationsTests from "@specs/09-settings-notifications.spec";
import settingsAccessibilityTests from "@specs/10-settings-accessibility.spec";
import settingsAboutTests from "@specs/11-settings-about.spec";
import settingsLicensesTests from "@specs/12-settings-licenses.spec";
import settingsDeveloperTests from "@specs/13-settings-developer.spec";
import importAccountTests from "@specs/16-import-account.spec";

describe("Windows Tests", function () {
describe("Create Pin and Account Tests", createAccount.bind(this));
describe("Chats Main Screen Tests", chats.bind(this));
describe("Files Screen Tests", files.bind(this));
describe("MacOS Tests", function () {
describe("Create Pin and Account Tests", createAccountTests.bind(this));
describe("Chats Main Screen Tests", chatsTests.bind(this));
describe("Files Screen Tests", filesTests.bind(this));
describe("Settings Profile Tests", settingsProfileTests.bind(this));
describe("Settings General Tests", settingsGeneral.bind(this));
describe("Settings Messages Tests", settingsMessages.bind(this));
describe("Settings Audio Tests", settingsAudio.bind(this));
describe("Settings Extensions Tests", settingsExtensions.bind(this));
describe("Settings Accessibility Tests", settingsAccessibility.bind(this));
describe("Settings Notifications Tests", settingsNotifications.bind(this));
describe("Settings About Tests", settingsAbout.bind(this));
describe("Settings Licenses Tests", settingsLicenses.bind(this));
describe("Settings Developer Tests", settingsDeveloper.bind(this));
describe("Settings General Tests", settingsGeneralTests.bind(this));
describe("Settings Message Tests", settingsMessagesTests.bind(this));
describe("Settings Audio Tests", settingsAudioTests.bind(this));
describe("Settings Extensions Tests", settingsExtensionsTests.bind(this));
describe(
"Settings Accessibility Tests",
settingsAccessibilityTests.bind(this),
);
describe(
"Settings Notifications Tests",
settingsNotificationsTests.bind(this),
);
describe("Settings About Tests", settingsAboutTests.bind(this));
describe("Settings Licenses Tests", settingsLicensesTests.bind(this));
describe("Settings Developer Tests", settingsDeveloperTests.bind(this));
describe("Import Account Tests", importAccountTests.bind(this));
});

0 comments on commit 0afad3c

Please sign in to comment.