Skip to content

Creates tests for new network page feature WIP #33

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import eslint from '@eslint/js';
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint';
import globals from 'globals';

Expand Down
3 changes: 2 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export default defineConfig({
reportSlowTests: null,
fullyParallel: true, // otherwise, tests in the same file are not run in parallel
globalSetup: './global.setup', // clean leftovers of previous test runs on start, runs only once
snapshotPathTemplate: screenshotFolder + '/{testName}/{arg}-{platform}{ext}',
// eslint-disable-next-line prefer-template
snapshotPathTemplate: screenshotFolder + '/{testName}/{arg}-{platform}{text}',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make this screenshotFolder part of a templated string (with backtick?) I guess ts complains about the testName and others being there, but without the $ sign?

});
1 change: 0 additions & 1 deletion tests/automation/input_validations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import {
[
{
testName: 'No name',
// This currently fails - displays wrong error message
displayName: ' ',
expectedError: englishStrippedStr('displayNameErrorDescription').toString(),
},
Expand Down
1 change: 1 addition & 0 deletions tests/automation/landing_page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-cycle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need to be addressed, eventually

import { test_Alice_2W } from './setup/sessionTest';
import { compareScreenshot, waitForElement } from './utilities/utils';

Expand Down
64 changes: 64 additions & 0 deletions tests/automation/network_page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { englishStrippedStr } from '../locale/localizedString';
import { test_Alice_1W } from './setup/sessionTest';
import {
checkModalStrings,
clickOnTestIdWithText,
grabTextFromElement,
waitForElement,
waitForLoadingAnimationToFinish,
waitForTestIdWithText,
} from './utilities/utils';

/* Waiting for test id to be fixed
// Links to test are:
- Learn more Network link
- Learn more staking link
- How to create wallet link
*/
Comment on lines +12 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are we about those test ids?


test_Alice_1W('Learn more network link', async ({ aliceWindow1 }) => {
await clickOnTestIdWithText(aliceWindow1, 'settings-section');
await clickOnTestIdWithText(
aliceWindow1,
'session-network-settings-menu-item',
);
await waitForLoadingAnimationToFinish(aliceWindow1, 'loading-spinner');
await clickOnTestIdWithText(aliceWindow1, 'learn-more-network-link');
await checkModalStrings(
aliceWindow1,
englishStrippedStr('urlOpen').toString(),
englishStrippedStr('urlOpenDescription').toString(),
);
const el = await waitForElement(
aliceWindow1,
'data-testid',
'open-url-confirm-button',
);
const href = await el.getAttribute('href');
console.log('href', href);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to log this?

});

test_Alice_1W('Refreshing page works', async ({ aliceWindow1 }) => {
// TODO Add string in once crowdin has been updated
// const expectedText = englishStrippedStr('updated')
// .withArgs({ relative_time: '0m' })
// .toString();
Comment on lines +42 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have those been added yet?

const expectedText = 'Last updated 0m ago';
await clickOnTestIdWithText(aliceWindow1, 'settings-section');
await clickOnTestIdWithText(
aliceWindow1,
'session-network-settings-menu-item',
);
await waitForLoadingAnimationToFinish(aliceWindow1, 'loading-spinner');
await clickOnTestIdWithText(aliceWindow1, 'refresh-button');
await waitForLoadingAnimationToFinish(aliceWindow1, 'loading-spinner');
await waitForTestIdWithText(aliceWindow1, 'last-updated-timestamp');
const returnedText = await grabTextFromElement(
aliceWindow1,
'data-testid',
'last-updated-timestamp',
);
if (returnedText !== expectedText) {
throw new Error(`Expected text: ${expectedText}, but got: ${returnedText}`);
}
});
1 change: 1 addition & 0 deletions tests/automation/setup/new_user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Page } from '@playwright/test';
import chalk from 'chalk';
import { User } from '../types/testing';
// eslint-disable-next-line import/no-cycle
import {
checkPathLight,
clickOnTestIdWithText,
Expand Down
2 changes: 2 additions & 0 deletions tests/automation/setup/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import chalk from 'chalk';
import { isEmpty } from 'lodash';
import { join } from 'path';
import { v4 } from 'uuid';
import dotenv from 'dotenv';

dotenv.config();
export const NODE_ENV = 'production';
export const MULTI_PREFIX = 'test-integration-';
const multisAvailable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Expand Down
15 changes: 12 additions & 3 deletions tests/automation/setup/recovery_using_seed.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Page } from '@playwright/test';
// eslint-disable-next-line import/no-cycle
import {
clickOnTestIdWithText,
doesElementExist,
typeIntoInput,
waitForLoadingAnimationToFinish,
} from '../utilities/utils';

export async function recoverFromSeed(window: Page, recoveryPhrase: string) {
export async function recoverFromSeed(
window: Page,
recoveryPhrase: string,
createDisplayName?: boolean,
) {
Comment on lines +10 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this createDisplayname used anywhere currently? I feel like recoverFromSeed should fail, if the displayName isn't found, and not blindly offer the option to use "Alice" as one. Why was this needed?

await clickOnTestIdWithText(window, 'existing-account-button');
await typeIntoInput(window, 'recovery-phrase-input', recoveryPhrase);
await clickOnTestIdWithText(window, 'continue-button');
Expand All @@ -17,8 +22,12 @@ export async function recoverFromSeed(window: Page, recoveryPhrase: string) {
'display-name-input',
);
if (displayName) {
throw new Error(`Display name was not found when restoring from seed`);
if (createDisplayName) {
await typeIntoInput(window, 'display-name-input', 'Alice');
await clickOnTestIdWithText(window, 'continue-button');
} else {
throw new Error(`Display name was not found when restoring from seed`);
}
}

return { window };
}
24 changes: 24 additions & 0 deletions tests/automation/setup/sessionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Page, TestInfo, test } from '@playwright/test';
import { Group, User } from '../types/testing';
// eslint-disable-next-line import/no-cycle
import { linkedDevice } from '../utilities/linked_device';
import { forceCloseAllWindows } from './closeWindows';
import { createGroup } from './create_group';
Expand Down Expand Up @@ -222,6 +223,29 @@ export function test_Alice_1W_no_network(
},
);
}
// Need a test for one window with network, mainly for Network Page
export function test_Alice_1W(
testname: string,
testCallback: (
details: WithAlice & WithAliceWindow1,
testInfo: TestInfo,
) => Promise<void>,
) {
return sessionTestGeneric(
testname,
1,
{ waitForNetwork: true },
({ mainWindows, users }, testInfo) => {
return testCallback(
{
alice: users[0],
aliceWindow1: mainWindows[0],
},
testInfo,
);
},
);
}

/**
* Setup the test with 1 user and 2 windows total:
Expand Down
6 changes: 5 additions & 1 deletion tests/automation/types/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,8 @@ export type DataTestId =
| 'error-message'
| 'group-members'
| 'session-confirm-cancel-button'
| 'session-recovery-password';
| 'session-recovery-password'
| 'session-network-settings-menu-item'
| 'learn-more-network-link'
| 'refresh-button'
| 'last-updated-timestamp';
2 changes: 1 addition & 1 deletion tests/automation/utilities/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function waitForTestIdWithText(
const found = await window.waitForSelector(builtSelector, {
timeout: maxWait,
});
// console.info('found selector', builtSelector);
console.info('found selector', builtSelector);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want this commited?


return found;
}
Expand Down