Skip to content

Commit

Permalink
feat(e2e): Migrated rest of t1b1 onboarding tests (#16067)
Browse files Browse the repository at this point in the history
  • Loading branch information
HajekOndrej authored Dec 20, 2024
1 parent c0bdf14 commit 6365662
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 239 deletions.
12 changes: 12 additions & 0 deletions packages/suite-desktop-core/e2e/support/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { BackupActions } from './pageActions/backupActions';
import { DevicePromptActions } from './pageActions/devicePromptActions';
import { AnalyticsActions } from './pageActions/analyticsActions';
import { IndexedDbFixture } from './indexedDb';
import { RecoverActions } from './pageActions/recoverActions';
import { WordInputActions } from './pageActions/wordInputActions';

type Fixtures = {
startEmulator: boolean;
Expand All @@ -38,6 +40,8 @@ type Fixtures = {
backupPage: BackupActions;
analyticsPage: AnalyticsActions;
devicePrompt: DevicePromptActions;
recoverPage: RecoverActions;
wordInputPage: WordInputActions;
analytics: AnalyticsFixture;
indexedDb: IndexedDbFixture;
};
Expand Down Expand Up @@ -157,6 +161,14 @@ const test = base.extend<Fixtures>({
const devicePromptActions = new DevicePromptActions(page);
await use(devicePromptActions);
},
recoverPage: async ({ page }, use) => {
const recoverPage = new RecoverActions(page);
await use(recoverPage);
},
wordInputPage: async ({ page }, use) => {
const wordinputPage = new WordInputActions(page);
await use(wordinputPage);
},
analytics: async ({ page }, use) => {
const analytics = new AnalyticsFixture(page);
await use(analytics);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Locator, Page } from '@playwright/test';

export class RecoverActions {
readonly selectBasicRecoveryButton: Locator;

constructor(private page: Page) {
this.selectBasicRecoveryButton = page.getByTestId('@recover/select-type/basic');
}

async selectWordCount(number: number) {
await this.page.getByTestId(`@recover/select-count/${number}`).click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Locator, Page } from '@playwright/test';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';

export class WordInputActions {
readonly wordSelectInput: Locator;

constructor(private page: Page) {
this.wordSelectInput = page.getByTestId('@word-input-select/input');
}

async inputWord(word: string) {
await this.wordSelectInput.type(word);
await this.page.getByTestId(`@word-input-select/option/${word}`).click();
}

async inputMnemonicT1B1(mnemonic: string[]) {
for (let i = 0; i < 24; i++) {
await this.page.waitForTimeout(400);
const state = await TrezorUserEnvLink.getDebugState();
const position = state.recovery_word_pos - 1;
await this.inputWord(mnemonic[position]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { test, expect } from '../../../support/fixtures';

test.describe('Onboarding - recover wallet T1B1', { tag: ['@group=device-management'] }, () => {
test.use({
emulatorStartConf: { model: 'T1B1', version: '1-latest', wipe: true },
setupEmulator: false,
});

test.beforeEach(async ({ onboardingPage }) => {
await onboardingPage.disableFirmwareHashCheck();
});

test('Incomplete run of advanced recovery', async ({
onboardingPage,
analyticsPage,
devicePrompt,
page,
trezorUserEnvLink,
}) => {
// Navigate through onboarding steps
await analyticsPage.passThroughAnalytics();
await onboardingPage.firmwareContinueButton.click();
await onboardingPage.recoverWalletButton.click();

// Select advanced recovery
await page.getByTestId('@recover/select-count/24').click();
await page.getByTestId('@recover/select-type/advanced').click();
await page.getByTestId('@onboarding/confirm-on-device').waitFor({ state: 'visible' });
await trezorUserEnvLink.pressYes();

// Simulate user input
for (let i = 0; i <= 4; i++) {
await page.getByTestId('@recovery/word-input-advanced/1').click({ force: true });
}

// Simulate device disconnection due to lack of cancel button
await page.waitForTimeout(501);
await trezorUserEnvLink.stopEmu();
await devicePrompt.confirmOnDevicePromptIsShown();

// Restart emulator
await trezorUserEnvLink.startEmu({ model: 'T1B1', version: '1-latest' });

// Retry recovery with basic type
await onboardingPage.retryRecoveryButton.click();
await page.getByTestId('@recover/select-count/12').click();
await page.getByTestId('@recover/select-type/basic').click();

// Confirm on device
await page.getByTestId('@onboarding/confirm-on-device').waitFor({ state: 'visible' });
await trezorUserEnvLink.pressYes();

// Ensure input field for basic recovery is visible
await expect(page.getByTestId('@word-input-select/input')).toBeVisible();

// Note: Completion of reading device data requires support in trezor-user-env
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test } from '../../../support/fixtures';

test.describe('Onboarding - recover wallet T1B1', { tag: ['@group=device-management'] }, () => {
test.use({
emulatorStartConf: { model: 'T1B1', version: '1-latest', wipe: true },
setupEmulator: false,
});

test.beforeEach(async ({ onboardingPage }) => {
await onboardingPage.disableFirmwareHashCheck();
});

test('Device disconnected during recovery offers retry', async ({
onboardingPage,
analyticsPage,
recoverPage,
devicePrompt,
trezorUserEnvLink,
}) => {
await analyticsPage.passThroughAnalytics();

// Start wallet recovery process
await onboardingPage.firmwareContinueButton.click();
await onboardingPage.recoverWalletButton.click();
await recoverPage.selectWordCount(24);
await recoverPage.selectBasicRecoveryButton.click();
await devicePrompt.confirmOnDevicePromptIsShown();
await trezorUserEnvLink.pressYes();

// Disconnect the device
await trezorUserEnvLink.stopEmu();
await devicePrompt.connectDevicePromptIsShown();
await trezorUserEnvLink.startEmu({ model: 'T1B1', version: '1-latest', wipe: false });

// Retry recovery process
await onboardingPage.retryRecoveryButton.click();
await recoverPage.selectWordCount(24);
await recoverPage.selectBasicRecoveryButton.click();
await devicePrompt.confirmOnDevicePromptIsShown();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { test, expect } from '../../../support/fixtures';

const mnemonic = [
'nasty',
'answer',
'gentle',
'inform',
'unaware',
'abandon',
'regret',
'supreme',
'dragon',
'gravity',
'behind',
'lava',
'dose',
'pilot',
'garden',
'into',
'dynamic',
'outer',
'hard',
'speed',
'luxury',
'run',
'truly',
'armed',
];

test.describe('Onboarding - recover wallet T1B1', { tag: ['@group=device-management'] }, () => {
test.use({
emulatorStartConf: { model: 'T1B1', version: '1-latest', wipe: true },
setupEmulator: false,
});

test.beforeEach(async ({ onboardingPage }) => {
await onboardingPage.disableFirmwareHashCheck();
});

test('Successfully recovers wallet from mnemonic', async ({
page,
onboardingPage,
analyticsPage,
devicePrompt,
recoverPage,
wordInputPage,
trezorUserEnvLink,
}) => {
await analyticsPage.passThroughAnalytics();

// Start wallet recovery process
await onboardingPage.firmwareContinueButton.click();
await onboardingPage.recoverWalletButton.click();
await recoverPage.selectWordCount(24);
await recoverPage.selectBasicRecoveryButton.click();
await devicePrompt.confirmOnDevicePromptIsShown();
await page.waitForTimeout(1000);
await trezorUserEnvLink.pressYes();

// Input mnemonic
await wordInputPage.inputMnemonicT1B1(mnemonic);

// Finalize recovery, skip pin, and verify success
await onboardingPage.continueRecoveryButton.click();
await onboardingPage.skipPin();
await onboardingPage.continueCoinsButton.click();
await expect(onboardingPage.finalTitle).toBeVisible();
await expect(onboardingPage.finalTitle).toContainText('Setup complete!');
});
});

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6365662

Please sign in to comment.