Skip to content

Commit a85989a

Browse files
authored
test(e2e): Add E2E test for Snap dialogs (MetaMask#17504)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This adds an E2E test for Snap dialogs (alert, confirmation, custom). Prompt dialogs don't seem to be implemented yet, so I skipped it for now. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 8765c91 commit a85989a

3 files changed

Lines changed: 129 additions & 1 deletion

File tree

e2e/pages/Browser/TestSnaps.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,31 @@ class TestSnaps {
129129
const webElement = Matchers.getElementByWebID(
130130
BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID,
131131
TestSnapViewSelectorWebIDS[buttonLocator],
132-
) as any;
132+
);
133133
await Gestures.scrollToWebViewPort(webElement);
134134
await Gestures.tapWebElement(webElement);
135135
}
136136

137+
async tapOkButton() {
138+
const button = Matchers.getElementByText('OK');
139+
await Gestures.waitAndTap(button);
140+
}
141+
142+
async tapApproveButton() {
143+
const button = Matchers.getElementByText('Approve');
144+
await Gestures.waitAndTap(button);
145+
}
146+
147+
async tapConfirmButton() {
148+
const button = Matchers.getElementByText('Confirm');
149+
await Gestures.waitAndTap(button);
150+
}
151+
152+
async tapCancelButton() {
153+
const button = Matchers.getElementByText('Cancel');
154+
await Gestures.waitAndTap(button);
155+
}
156+
137157
async getOptionValueByText(
138158
webElement: IndexableWebElement,
139159
text: string,

e2e/selectors/Browser/TestSnaps.selectors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const TestSnapViewSelectorWebIDS = {
77
connectBip32Button: 'connectbip32',
88
connectBip44Button: 'connectbip44',
99
connectClientStatusSnapButton: 'connectclient-status',
10+
connectDialogSnapButton: 'connectdialogs',
1011
connectGetEntropyButton: 'connectGetEntropySnap',
1112
connectGetPreferencesButton: 'connectpreferences',
1213
connectJsonRpcButton: 'connectjson-rpc',
@@ -25,7 +26,10 @@ export const TestSnapViewSelectorWebIDS = {
2526
signMessageBip32Secp256k1Button: 'sendBip32-secp256k1',
2627
signMessageBip32ed25519Button: 'sendBip32-ed25519',
2728
signMessageBip32ed25519Bip32Button: 'sendBip32-ed25519Bip32',
29+
sendAlertButton: 'sendAlertButton',
2830
sendClientStatusButton: 'sendClientStatusTest',
31+
sendConfirmationButton: 'sendConfirmationButton',
32+
sendCustomButton: 'sendCustomButton',
2933
sendGetStateButton: 'sendGetState',
3034
sendGetUnencryptedStateButton: 'sendGetUnencryptedState',
3135
sendManageStateButton: 'sendManageState',
@@ -81,6 +85,7 @@ export const TestSnapResultSelectorWebIDS = {
8185
clearManageStateResultSpan: 'clearManageStateResult',
8286
clearUnencryptedManageStateResultSpan: 'clearUnencryptedManageStateResult',
8387
clientStatusResultSpan: 'clientStatusResult',
88+
dialogResultSpan: 'dialogResult',
8489
encryptedStateResultSpan: 'encryptedStateResult',
8590
entropySignResultSpan: 'entropySignResult',
8691
preferencesResultSpan: 'preferencesResult',
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { FlaskBuildTests } from '../../tags';
2+
import { loginToApp } from '../../viewHelper';
3+
import TabBarComponent from '../../pages/wallet/TabBarComponent';
4+
import TestSnaps from '../../pages/Browser/TestSnaps';
5+
import Assertions from '../../framework/Assertions';
6+
import Gestures from '../../utils/Gestures';
7+
import { Matchers } from '../../framework';
8+
import { withFixtures } from '../../framework/fixtures/FixtureHelper';
9+
import FixtureBuilder from '../../framework/fixtures/FixtureBuilder';
10+
11+
jest.setTimeout(150_000);
12+
13+
describe(FlaskBuildTests('Dialog Snap Tests'), () => {
14+
it('connects to the Dialog Snap', async () => {
15+
await withFixtures(
16+
{
17+
fixture: new FixtureBuilder().build(),
18+
restartDevice: true,
19+
},
20+
async () => {
21+
await loginToApp();
22+
await TabBarComponent.tapBrowser();
23+
await TestSnaps.navigateToTestSnap();
24+
25+
await TestSnaps.installSnap('connectDialogSnapButton');
26+
},
27+
);
28+
});
29+
30+
describe('alert', () => {
31+
it('shows an alert dialog', async () => {
32+
await withFixtures(
33+
{
34+
fixture: new FixtureBuilder().build(),
35+
},
36+
async () => {
37+
await TestSnaps.tapButton('sendAlertButton');
38+
await Assertions.expectTextDisplayed(
39+
'This is an alert dialog. It has a single button: "OK".',
40+
);
41+
42+
await TestSnaps.tapOkButton();
43+
await TestSnaps.checkResultSpan('dialogResultSpan', 'null');
44+
},
45+
);
46+
});
47+
});
48+
49+
describe('confirmation', () => {
50+
it('shows a confirmation dialog', async () => {
51+
await withFixtures(
52+
{
53+
fixture: new FixtureBuilder().build(),
54+
},
55+
async () => {
56+
await TestSnaps.tapButton('sendConfirmationButton');
57+
await Assertions.expectTextDisplayed('Confirmation Dialog');
58+
59+
await TestSnaps.tapApproveButton();
60+
await TestSnaps.checkResultSpan('dialogResultSpan', 'true');
61+
},
62+
);
63+
});
64+
65+
it('shows a confirmation dialog and cancels', async () => {
66+
await withFixtures(
67+
{
68+
fixture: new FixtureBuilder().build(),
69+
},
70+
async () => {
71+
await TestSnaps.tapButton('sendConfirmationButton');
72+
await Assertions.expectTextDisplayed('Confirmation Dialog');
73+
74+
await TestSnaps.tapCancelButton();
75+
await TestSnaps.checkResultSpan('dialogResultSpan', 'false');
76+
},
77+
);
78+
});
79+
});
80+
81+
describe('custom', () => {
82+
it('shows a custom dialog', async () => {
83+
await withFixtures(
84+
{
85+
fixture: new FixtureBuilder().build(),
86+
},
87+
async () => {
88+
await TestSnaps.tapButton('sendCustomButton');
89+
await Assertions.expectTextDisplayed('Custom Dialog');
90+
91+
const input = Matchers.getElementByID('custom-input-snap-ui-input');
92+
await Gestures.typeTextAndHideKeyboard(input, 'Hello, World!');
93+
94+
await TestSnaps.tapConfirmButton();
95+
await TestSnaps.checkResultSpan(
96+
'dialogResultSpan',
97+
'"Hello, World!"',
98+
);
99+
},
100+
);
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)