Skip to content

Commit

Permalink
Migrate metadata tests (#16583)
Browse files Browse the repository at this point in the history
* feat(e2e): Migrated more metadata tests

* feat(e2e): Migrated remembered device test

* feat(e2e): Fixed stopping mock server

* fix(e2e): Switched trezoruserenvlink import to fixture
  • Loading branch information
HajekOndrej authored Jan 24, 2025
1 parent b0cb779 commit 4dcc207
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 485 deletions.
13 changes: 4 additions & 9 deletions packages/e2e-utils/src/mocks/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export class GoogleMock {
if (req.method === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader(
'Access-Control-Allow-Headers',
'Content-Type, Authorization, dropbox-api-arg',
);
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Credentials', 'true');

return res.status(200).end();
Expand All @@ -65,10 +62,7 @@ export class GoogleMock {
// Handle normal requests
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.setHeader(
'Access-Control-Allow-Headers',
'Content-Type, Authorization, dropbox-api-arg',
);
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
this.requests.push(req.url);

if (this.nextResponse.length) {
Expand Down Expand Up @@ -156,7 +150,7 @@ export class GoogleMock {

app.get('/drive/v3/files/:id', express.json(), (req, res) => {
const { id } = req.params;
console.log('[mockGoogleDrive]: get', req.params.id);
console.log('[mockGoogleDrive]: get file by id', req.params.id);
const file = Object.values(this.files).find(f => f.id === id);
if (file) {
return res.send(file.data);
Expand All @@ -171,6 +165,7 @@ export class GoogleMock {
});

app.get('/drive/v3/files', express.json(), (_req, res) => {
console.log('[mockGoogleDrive]: get files');
res.json({
files: Object.values(this.files),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum OutputLabelId {
BitcoinDefault1 = '1d7a8556bb5bda4895596c52017b98c9af29eda10770865e845d3848aa222d1c',
BitcoinLegacy6 = 'b649a09e6d5d02b3cb4648a42511177efb6abf44366f30a51c1b202d52335d18',
BitcoinLegacy10 = '40242836cc07b635569688d12d63041935b86feb2db3fe575be80f2c44e5b4cb',
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,123 @@ import { MetadataProvider } from '../mocks/metadataProviderMock';
import { DevicePromptActions } from './devicePromptActions';
import { step } from '../common';

interface MetadataSubmitOptions {
useButton?: boolean;
}

export class MetadataActions {
private readonly metadataSubmitButton: Locator;
readonly metadataCancelButton: Locator;
readonly metadataInput: Locator;
readonly editLabelButton = (accountId: string) =>
readonly metadataModal: Locator;

readonly addAccountLabelButton = (accountId: string) =>
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/add-label-button`);
readonly editAccountLabelButton = (accountId: string) =>
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/edit-label-button`);
readonly successLabel = (accountId: string) =>
readonly successAccountLabel = (accountId: string) =>
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/success`);
readonly accountLabel = (accountId: string) =>
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/hover-container`);
readonly outputLabel = (outputId: string, txNumber: number) =>
this.page.getByTestId(`${this.getOutputLabelTestId(outputId, txNumber)}/hover-container`);
readonly outputDropdownCopyAddress = (outputId: string, txNumber: number) =>
this.page.getByTestId(
`${this.getOutputLabelTestId(outputId, txNumber)}/dropdown/copy-address`,
);
readonly outputDropdownEditLabel = (outputId: string, txNumber: number) =>
this.page.getByTestId(
`${this.getOutputLabelTestId(outputId, txNumber)}/dropdown/edit-label`,
);
readonly metadataProviderButton = (provider: MetadataProvider) =>
this.page.getByTestId(`@modal/metadata-provider/${provider}-button`);

constructor(
private readonly page: Page,
private readonly devicePrompt: DevicePromptActions,
) {
this.metadataSubmitButton = page.getByTestId('@metadata/submit');
this.metadataCancelButton = page.getByTestId('@metadata/cancel');
this.metadataInput = page.getByTestId('@metadata/input');
this.metadataModal = page.getByTestId('@modal/metadata-provider');
}

private getAccountLabelTestId(accountId: string): string {
return `@metadata/accountLabel/${accountId}`;
}

private getOutputLabelTestId(outputId: string, txNumber: number): string {
return `@metadata/outputLabel/${outputId}-${txNumber}`;
}

@step()
async passThroughInitMetadata(
provider: MetadataProvider,
options?: { skipVerification?: boolean },
) {
await this.devicePrompt.confirmOnDevicePromptIsShown();
await TrezorUserEnvLink.pressYes();
await this.page.getByTestId(`@modal/metadata-provider/${provider}-button`).click();
await this.metadataProviderButton(provider).click();

if (options?.skipVerification) {
return;
}

await expect(this.page.getByTestId('@modal/metadata-provider')).not.toBeVisible({
await expect(this.metadataModal).not.toBeVisible({
timeout: 30000,
});
}

@step()
async editLabel(accountId: string, newLabel: string) {
async editAccountLabel(accountId: string, newLabel: string) {
await this.accountLabel(accountId).click();
await this.editLabelButton(accountId).click();
await this.metadataInput.fill(newLabel);
await this.metadataSubmitButton.click();
await this.editAccountLabelButton(accountId).click();
await this.fillLabelInput(newLabel, { useButton: true });
}

@step()
async clickAddLabelButton(accountId: string) {
async clickAddAccountLabelButton(accountId: string) {
await this.accountLabel(accountId).hover();
await this.addAccountLabelButton(accountId).click();
}

@step()
async addAccountLabel(accountId: string, label: string) {
await this.clickAddAccountLabelButton(accountId);
await this.fillLabelInput(label);
}

@step()
async clickAddOutputLabelButton(outputId: string, txNumber: number) {
await this.outputLabel(outputId, txNumber).hover();
await this.page
.getByTestId(`${this.getAccountLabelTestId(accountId)}/add-label-button`)
.getByTestId(`${this.getOutputLabelTestId(outputId, txNumber)}/add-label-button`)
.click();
}

@step()
async addLabel(accountId: string, label: string) {
await this.clickAddLabelButton(accountId);
async addOutputLabel(outputId: string, txNumber: number, label: string) {
await this.clickAddOutputLabelButton(outputId, txNumber);
await this.fillLabelInput(label);
}

@step()
async editOutputLabel(outputId: string, txNumber: number, newLabel: string) {
await this.outputLabel(outputId, txNumber).click();
await this.outputDropdownEditLabel(outputId, txNumber).click();
await this.fillLabelInput(newLabel);
}

@step()
async fillLabelInput(label: string, options?: MetadataSubmitOptions) {
await this.metadataInput.fill(label);

if (options?.useButton) {
await this.metadataSubmitButton.click();

return;
}

await this.page.keyboard.press('Enter');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
await expect(page.getByTestId('@account-menu/btc/normal/0/label')).toHaveText('Bitcoin #1');

// Metadata flow
await metadataPage.clickAddLabelButton(AccountLabelId.BitcoinDefault1);
await metadataPage.clickAddAccountLabelButton(AccountLabelId.BitcoinDefault1);
await metadataPage.passThroughInitMetadata(MetadataProvider.DROPBOX);

// Edit label
Expand All @@ -40,17 +40,21 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
);

// Submit label changes via button
await metadataPage.editLabel(AccountLabelId.BitcoinDefault1, 'even cooler');
await metadataPage.editAccountLabel(AccountLabelId.BitcoinDefault1, 'even cooler');
await expect(page.getByTestId('@account-menu/btc/normal/0/label')).toHaveText(
'even cooler',
);

await expect(metadataPage.successLabel(AccountLabelId.BitcoinDefault1)).toBeVisible();
await expect(metadataPage.successLabel(AccountLabelId.BitcoinDefault1)).not.toBeVisible();
await expect(
metadataPage.successAccountLabel(AccountLabelId.BitcoinDefault1),
).toBeVisible();
await expect(
metadataPage.successAccountLabel(AccountLabelId.BitcoinDefault1),
).not.toBeVisible();

// Discard changes via escape
await metadataPage.accountLabel(AccountLabelId.BitcoinDefault1).click();
await metadataPage.editLabelButton(AccountLabelId.BitcoinDefault1).click();
await metadataPage.editAccountLabelButton(AccountLabelId.BitcoinDefault1).click();
await metadataPage.metadataInput.fill('bcash is true bitcoin');
await page.keyboard.press('Escape');
await expect(page.getByTestId('@account-menu/btc/normal/0/label')).toHaveText(
Expand All @@ -68,7 +72,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =

// Remove metadata by clearing input
await metadataPage.accountLabel(AccountLabelId.BitcoinDefault1).hover();
await metadataPage.editLabelButton(AccountLabelId.BitcoinDefault1).click();
await metadataPage.editAccountLabelButton(AccountLabelId.BitcoinDefault1).click();
await metadataPage.metadataInput.clear();
await page.keyboard.press('Enter');
await expect(page.getByTestId('@account-menu/btc/normal/0/label')).toHaveText('Bitcoin #1');
Expand All @@ -77,13 +81,17 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
await page.getByTestId('@account-menu/segwit').click();
await page.getByTestId('@account-menu/btc/segwit/0').click();

await metadataPage.addLabel(AccountLabelId.BitcoinSegwit1, 'typing into one input');
await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit1)).toBeVisible();
await metadataPage.addAccountLabel(AccountLabelId.BitcoinSegwit1, 'typing into one input');
await expect(metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit1)).toBeVisible();

await page.getByTestId('@account-menu/btc/segwit/1').click();

await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit2)).not.toBeVisible();
await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit1)).not.toBeVisible();
await expect(
metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit2),
).not.toBeVisible();
await expect(
metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit1),
).not.toBeVisible();

// Check metadata requests when switching routes
await page.getByTestId('@suite/menu/suite-index').click();
Expand All @@ -94,7 +102,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
await page.getByTestId('@account-menu/add-account').click();
await settingsPage.coins.networkButton('btc').click();
await page.getByTestId('@add-account').click();
await metadataPage.addLabel(
await metadataPage.addAccountLabel(
AccountLabelId.BitcoinDefault3,
'adding label to a newly added account. does it work?',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe('Dropbox API errors', { tag: ['@group=metadata', '@webOnly'] }, ()
await page.getByTestId('@account-menu/btc/normal/0').click();

await metadataPage.accountLabel(AccountLabelId.BitcoinDefault1).click();
await metadataPage.editLabelButton(AccountLabelId.BitcoinDefault1).click();
await metadataPage.editAccountLabelButton(AccountLabelId.BitcoinDefault1).click();

// Simulated API responses for retries with malformed token must be supplied exactly at this point in the flow
for (let i = 0; i < 4; i++) {
Expand Down Expand Up @@ -121,7 +121,7 @@ test.describe('Dropbox API errors', { tag: ['@group=metadata', '@webOnly'] }, ()
});

await page.getByTestId('@account-menu/btc/normal/0').click();
await metadataPage.editLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
await metadataPage.editAccountLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
await expect(metadataPage.accountLabel(AccountLabelId.BitcoinDefault1)).toContainText(
'Kvooo',
);
Expand Down Expand Up @@ -157,7 +157,7 @@ test.describe('Dropbox API errors', { tag: ['@group=metadata', '@webOnly'] }, ()

await page.getByTestId('@account-menu/btc/normal/0').click();
// just enter some label, this indicates that app did not crash
await metadataPage.editLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
await metadataPage.editAccountLabel(AccountLabelId.BitcoinDefault1, 'Kvooo');
});

test.afterEach(async ({ metadataProviderMock }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test.describe('Google API errors', { tag: ['@group=metadata', '@webOnly'] }, ()
await dashboardPage.discoveryShouldFinish();

await page.getByTestId('@account-menu/btc/normal/0').click();
await metadataPage.clickAddLabelButton(AccountLabelId.BitcoinDefault1);
await metadataPage.clickAddAccountLabelButton(AccountLabelId.BitcoinDefault1);

await metadataPage.passThroughInitMetadata(MetadataProvider.GOOGLE, {
skipVerification: true,
Expand Down
Loading

0 comments on commit 4dcc207

Please sign in to comment.