Skip to content

Commit cffe429

Browse files
committed
feat(e2e): Migrated more metadata tests
1 parent 61f1d57 commit cffe429

11 files changed

+366
-310
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum OutputLabelId {
2+
BitcoinDefault1 = '1d7a8556bb5bda4895596c52017b98c9af29eda10770865e845d3848aa222d1c',
3+
BitcoinLegacy6 = 'b649a09e6d5d02b3cb4648a42511177efb6abf44366f30a51c1b202d52335d18',
4+
BitcoinLegacy10 = '40242836cc07b635569688d12d63041935b86feb2db3fe575be80f2c44e5b4cb',
5+
}

packages/suite-desktop-core/e2e/support/pageActions/metadataActions.ts

+62-9
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,49 @@ import { MetadataProvider } from '../mocks/metadataProviderMock';
66
import { DevicePromptActions } from './devicePromptActions';
77
import { step } from '../common';
88

9+
interface MetadataSubmitOptions {
10+
useButton?: boolean;
11+
}
12+
913
export class MetadataActions {
1014
private readonly metadataSubmitButton: Locator;
15+
readonly metadataCancelButton: Locator;
1116
readonly metadataInput: Locator;
12-
readonly editLabelButton = (accountId: string) =>
17+
18+
readonly editAccountLabelButton = (accountId: string) =>
1319
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/edit-label-button`);
14-
readonly successLabel = (accountId: string) =>
20+
readonly successAccountLabel = (accountId: string) =>
1521
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/success`);
1622
readonly accountLabel = (accountId: string) =>
1723
this.page.getByTestId(`${this.getAccountLabelTestId(accountId)}/hover-container`);
24+
readonly outputLabel = (outputId: string, txNumber: number) =>
25+
this.page.getByTestId(`${this.getOutputLabelTestId(outputId, txNumber)}/hover-container`);
26+
readonly outputDropdownCopyAddress = (outputId: string, txNumber: number) =>
27+
this.page.getByTestId(
28+
`${this.getOutputLabelTestId(outputId, txNumber)}/dropdown/copy-address`,
29+
);
30+
readonly outputDropdownEditLabel = (outputId: string, txNumber: number) =>
31+
this.page.getByTestId(
32+
`${this.getOutputLabelTestId(outputId, txNumber)}/dropdown/edit-label`,
33+
);
1834

1935
constructor(
2036
private readonly page: Page,
2137
private readonly devicePrompt: DevicePromptActions,
2238
) {
2339
this.metadataSubmitButton = page.getByTestId('@metadata/submit');
40+
this.metadataCancelButton = page.getByTestId('@metadata/cancel');
2441
this.metadataInput = page.getByTestId('@metadata/input');
2542
}
2643

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

48+
private getOutputLabelTestId(outputId: string, txNumber: number): string {
49+
return `@metadata/outputLabel/${outputId}-${txNumber}`;
50+
}
51+
3152
@step()
3253
async passThroughInitMetadata(
3354
provider: MetadataProvider,
@@ -47,25 +68,57 @@ export class MetadataActions {
4768
}
4869

4970
@step()
50-
async editLabel(accountId: string, newLabel: string) {
71+
async editAccountLabel(accountId: string, newLabel: string) {
5172
await this.accountLabel(accountId).click();
52-
await this.editLabelButton(accountId).click();
53-
await this.metadataInput.fill(newLabel);
54-
await this.metadataSubmitButton.click();
73+
await this.editAccountLabelButton(accountId).click();
74+
await this.fillLabelInput(newLabel, { useButton: true });
5575
}
5676

5777
@step()
58-
async clickAddLabelButton(accountId: string) {
78+
async clickAddAccountLabelButton(accountId: string) {
5979
await this.accountLabel(accountId).hover();
6080
await this.page
6181
.getByTestId(`${this.getAccountLabelTestId(accountId)}/add-label-button`)
6282
.click();
6383
}
6484

6585
@step()
66-
async addLabel(accountId: string, label: string) {
67-
await this.clickAddLabelButton(accountId);
86+
async addAccountLabel(accountId: string, label: string) {
87+
await this.clickAddAccountLabelButton(accountId);
88+
await this.fillLabelInput(label);
89+
}
90+
91+
@step()
92+
async clickAddOutputLabelButton(outputId: string, txNumber: number) {
93+
await this.outputLabel(outputId, txNumber).hover();
94+
await this.page
95+
.getByTestId(`${this.getOutputLabelTestId(outputId, txNumber)}/add-label-button`)
96+
.click();
97+
}
98+
99+
@step()
100+
async addOutputLabel(outputId: string, txNumber: number, label: string) {
101+
await this.clickAddOutputLabelButton(outputId, txNumber);
102+
await this.fillLabelInput(label);
103+
}
104+
105+
@step()
106+
async editOutputLabel(outputId: string, txNumber: number, newLabel: string) {
107+
await this.outputLabel(outputId, txNumber).click();
108+
await this.outputDropdownEditLabel(outputId, txNumber).click();
109+
await this.fillLabelInput(newLabel);
110+
}
111+
112+
@step()
113+
async fillLabelInput(label: string, options?: MetadataSubmitOptions) {
68114
await this.metadataInput.fill(label);
115+
116+
if (options?.useButton) {
117+
await this.metadataSubmitButton.click();
118+
119+
return;
120+
}
121+
69122
await this.page.keyboard.press('Enter');
70123
}
71124
}

packages/suite-desktop-core/e2e/tests/metadata/account-metadata.test.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
2929
await expect(page.getByTestId('@account-menu/btc/normal/0/label')).toHaveText('Bitcoin #1');
3030

3131
// Metadata flow
32-
await metadataPage.clickAddLabelButton(AccountLabelId.BitcoinDefault1);
32+
await metadataPage.clickAddAccountLabelButton(AccountLabelId.BitcoinDefault1);
3333
await metadataPage.passThroughInitMetadata(MetadataProvider.DROPBOX);
3434

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

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

48-
await expect(metadataPage.successLabel(AccountLabelId.BitcoinDefault1)).toBeVisible();
49-
await expect(metadataPage.successLabel(AccountLabelId.BitcoinDefault1)).not.toBeVisible();
48+
await expect(
49+
metadataPage.successAccountLabel(AccountLabelId.BitcoinDefault1),
50+
).toBeVisible();
51+
await expect(
52+
metadataPage.successAccountLabel(AccountLabelId.BitcoinDefault1),
53+
).not.toBeVisible();
5054

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

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

80-
await metadataPage.addLabel(AccountLabelId.BitcoinSegwit1, 'typing into one input');
81-
await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit1)).toBeVisible();
84+
await metadataPage.addAccountLabel(AccountLabelId.BitcoinSegwit1, 'typing into one input');
85+
await expect(metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit1)).toBeVisible();
8286

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

85-
await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit2)).not.toBeVisible();
86-
await expect(metadataPage.successLabel(AccountLabelId.BitcoinSegwit1)).not.toBeVisible();
89+
await expect(
90+
metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit2),
91+
).not.toBeVisible();
92+
await expect(
93+
metadataPage.successAccountLabel(AccountLabelId.BitcoinSegwit1),
94+
).not.toBeVisible();
8795

8896
// Check metadata requests when switching routes
8997
await page.getByTestId('@suite/menu/suite-index').click();
@@ -94,7 +102,7 @@ test.describe('Account metadata', { tag: ['@group=metadata', '@webOnly'] }, () =
94102
await page.getByTestId('@account-menu/add-account').click();
95103
await settingsPage.coins.networkButton('btc').click();
96104
await page.getByTestId('@add-account').click();
97-
await metadataPage.addLabel(
105+
await metadataPage.addAccountLabel(
98106
AccountLabelId.BitcoinDefault3,
99107
'adding label to a newly added account. does it work?',
100108
);

packages/suite-desktop-core/e2e/tests/metadata/dropbox-api-errors.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test.describe('Dropbox API errors', { tag: ['@group=metadata', '@webOnly'] }, ()
4343
await page.getByTestId('@account-menu/btc/normal/0').click();
4444

4545
await metadataPage.accountLabel(AccountLabelId.BitcoinDefault1).click();
46-
await metadataPage.editLabelButton(AccountLabelId.BitcoinDefault1).click();
46+
await metadataPage.editAccountLabelButton(AccountLabelId.BitcoinDefault1).click();
4747

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

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

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

163163
test.afterEach(async ({ metadataProviderMock }) => {

packages/suite-desktop-core/e2e/tests/metadata/google-api-errors.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test.describe('Google API errors', { tag: ['@group=metadata', '@webOnly'] }, ()
4646
await dashboardPage.discoveryShouldFinish();
4747

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

5151
await metadataPage.passThroughInitMetadata(MetadataProvider.GOOGLE, {
5252
skipVerification: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';
2+
3+
import { AccountLabelId } from '../../support/enums/accountLabelId';
4+
import { test, expect } from '../../support/fixtures';
5+
import { MetadataProvider } from '../../support/mocks/metadataProviderMock';
6+
7+
test.describe(
8+
'Metadata - cancel metadata on device',
9+
{ tag: ['@group=metadata', '@webOnly'] },
10+
() => {
11+
test.use({
12+
emulatorSetupConf: {
13+
mnemonic: 'mnemonic_all',
14+
passphrase_protection: true,
15+
},
16+
});
17+
test.beforeEach(async ({ metadataProviderMock }) => {
18+
await metadataProviderMock.start(MetadataProvider.DROPBOX);
19+
});
20+
21+
test('user cancels metadata on device, choice is respected on subsequent runs but only for the cancelled wallet', async ({
22+
page,
23+
onboardingPage,
24+
dashboardPage,
25+
settingsPage,
26+
metadataPage,
27+
devicePrompt,
28+
}) => {
29+
await onboardingPage.completeOnboarding({ enableViewOnly: false });
30+
await dashboardPage.discoveryShouldFinish();
31+
32+
await settingsPage.navigateTo('application');
33+
await expect(
34+
page.getByTestId('@settings/metadata-switch').locator('input'),
35+
).not.toBeChecked();
36+
37+
// Navigate to account and hover over add label button
38+
await page.getByTestId('@suite/menu/suite-index').click();
39+
await page.getByTestId('@account-menu/btc/normal/0').click();
40+
await metadataPage.clickAddAccountLabelButton(AccountLabelId.BitcoinDefault1);
41+
await devicePrompt.confirmOnDevicePromptIsShown();
42+
await TrezorUserEnvLink.pressNo();
43+
44+
// Reload app, cancel metadata again, and remember device
45+
await page.reload();
46+
await devicePrompt.confirmOnDevicePromptIsShown();
47+
await TrezorUserEnvLink.pressNo();
48+
49+
await dashboardPage.discoveryShouldFinish();
50+
await dashboardPage.deviceSwitchingOpenButton.click();
51+
await page.getByTestId('@viewOnlyStatus/disabled').click();
52+
await page.getByTestId('@viewOnly/radios/enabled').click();
53+
54+
await page.reload();
55+
56+
// Add another wallet, enable labeling on the new device
57+
await page.getByTestId('@menu/switch-device').click();
58+
await page.pause();
59+
await page.getByTestId('@switch-device/add-hidden-wallet-button').click();
60+
await page.getByTestId('@passphrase/input').fill('abc');
61+
await page.getByTestId('@passphrase/hidden/submit-button').click();
62+
await expect(page.getByTestId('@passphrase/input')).not.toBeVisible();
63+
64+
await devicePrompt.confirmOnDevicePromptIsShown();
65+
await TrezorUserEnvLink.pressYes();
66+
67+
await devicePrompt.confirmOnDevicePromptIsShown();
68+
await TrezorUserEnvLink.pressYes();
69+
70+
await page
71+
.getByTestId('@passphrase-confirmation/step1-open-unused-wallet-button')
72+
.click();
73+
await page.getByTestId('@passphrase-confirmation/step2-button').click();
74+
await page.getByTestId('@passphrase/input').fill('abc');
75+
await page.getByTestId('@passphrase/hidden/submit-button').click();
76+
77+
await devicePrompt.confirmOnDevicePromptIsShown();
78+
await TrezorUserEnvLink.pressYes();
79+
80+
await devicePrompt.confirmOnDevicePromptIsShown();
81+
await TrezorUserEnvLink.pressYes();
82+
83+
await expect(page.getByTestId('@passphrase/input')).not.toBeVisible();
84+
await devicePrompt.confirmOnDevicePromptIsShown();
85+
await TrezorUserEnvLink.pressYes();
86+
await devicePrompt.confirmOnDevicePromptIsShown();
87+
await TrezorUserEnvLink.pressYes();
88+
89+
// Close connect to data provider modal
90+
await page.getByTestId('@modal/close-button').click();
91+
92+
// Forget device and reload
93+
await page.getByTestId('@menu/switch-device').click();
94+
95+
await page.getByTestId('@switch-device/wallet-on-index/0/eject-button').click();
96+
await page.getByTestId('@switch-device/eject').click();
97+
await page.getByTestId('@switch-device/wallet-on-index/0/eject-button').click();
98+
await page.getByTestId('@switch-device/eject').click();
99+
await page.reload();
100+
101+
// Enable labeling dialogue appears again
102+
await devicePrompt.confirmOnDevicePromptIsShown();
103+
await TrezorUserEnvLink.pressNo();
104+
});
105+
106+
test.afterEach(async ({ metadataProviderMock }) => {
107+
await metadataProviderMock.stop();
108+
});
109+
},
110+
);

0 commit comments

Comments
 (0)