Skip to content

Commit 1ccd356

Browse files
feat: converts viewHelper and all POMs + selectors to ts (#17376)
<!-- 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 PR refactors the `viewHelper` to typescript along with all Page Objects + selectors used by it. ### Improvement details - all `TestHelpers.delay()` removed from viewHelper functions which results in a reduction of 134 files having hardcoded delays 🚀 - 21 Page Objects refactored to typescript - 19 selectors renamed to typescript - More consistent imports <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **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 5184987 commit 1ccd356

File tree

65 files changed

+1269
-1088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1269
-1088
lines changed

e2e/framework/Assertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class Assertions {
1111
* Assert element is visible with auto-retry
1212
*/
1313
static async expectElementToBeVisible(
14-
detoxElement: DetoxElement | WebElement,
14+
detoxElement: DetoxElement | WebElement | DetoxMatcher,
1515
options: AssertionOptions = {},
1616
): Promise<void> {
1717
const {

e2e/pages/Common/ForgotPasswordModalView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '../../selectors/Common/ForgotPasswordModal.selectors';
55
import Matchers from '../../framework/Matchers.ts';
66
import Gestures from '../../framework/Gestures.ts';
7-
import { OnboardingSelectorText } from '../../selectors/Onboarding/Onboarding.selectors.js';
7+
import { OnboardingSelectorText } from '../../selectors/Onboarding/Onboarding.selectors';
88

99
class ForgotPasswordModalView {
1010
get container(): DetoxElement {

e2e/pages/Network/NetworkEducationModal.js renamed to e2e/pages/Network/NetworkEducationModal.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@ import {
22
NetworkEducationModalSelectorsIDs,
33
NetworkEducationModalSelectorsText,
44
} from '../../selectors/Network/NetworkEducationModal.selectors';
5-
import Matchers from '../../framework/Matchers.ts';
6-
import Gestures from '../../framework/Gestures.ts';
5+
import Matchers from '../../framework/Matchers';
6+
import Gestures from '../../framework/Gestures';
77

88
class NetworkEducationModal {
9-
get container() {
9+
get container(): DetoxElement {
1010
return Matchers.getElementByID(NetworkEducationModalSelectorsIDs.CONTAINER);
1111
}
1212

13-
get closeButton() {
13+
get closeButton(): DetoxElement {
1414
return device.getPlatform() === 'ios'
1515
? Matchers.getElementByID(NetworkEducationModalSelectorsIDs.CLOSE_BUTTON)
1616
: Matchers.getElementByLabel(
1717
NetworkEducationModalSelectorsIDs.CLOSE_BUTTON,
1818
);
1919
}
2020

21-
get addToken() {
21+
get addToken(): DetoxElement {
2222
return Matchers.getElementByText(
2323
NetworkEducationModalSelectorsText.ADD_TOKEN,
2424
);
2525
}
2626

27-
get networkName() {
27+
get networkName(): DetoxElement {
2828
return Matchers.getElementByID(
2929
NetworkEducationModalSelectorsIDs.NETWORK_NAME,
3030
);
3131
}
3232

33-
async tapGotItButton() {
33+
async tapGotItButton(): Promise<void> {
3434
await Gestures.waitAndTap(this.closeButton, {
3535
elemDescription: 'Got it button',
3636
});
3737
}
3838

39-
async tapNetworkName() {
39+
async tapNetworkName(): Promise<void> {
4040
await Gestures.waitAndTap(this.networkName);
4141
await Gestures.waitAndTap(this.networkName);
4242
}

e2e/pages/Network/NetworkListModal.js renamed to e2e/pages/Network/NetworkListModal.ts

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,57 @@ import {
22
NetworkListModalSelectorsIDs,
33
NetworkListModalSelectorsText,
44
} from '../../selectors/Network/NetworkListModal.selectors';
5-
import Matchers from '../../utils/Matchers';
6-
import Gestures from '../../utils/Gestures';
7-
import TestHelpers from '../../helpers';
85
import { NetworksViewSelectorsIDs } from '../../selectors/Settings/NetworksView.selectors';
6+
import Matchers from '../../framework/Matchers';
7+
import Gestures from '../../framework/Gestures';
98

109
class NetworkListModal {
11-
get networkScroll() {
10+
get networkScroll(): DetoxElement {
1211
return Matchers.getElementByID(NetworkListModalSelectorsIDs.SCROLL);
1312
}
1413

15-
get closeIcon() {
14+
get closeIcon(): DetoxElement {
1615
return Matchers.getElementByID(NetworksViewSelectorsIDs.CLOSE_ICON);
1716
}
1817

19-
get deleteNetworkButton() {
18+
get deleteNetworkButton(): DetoxElement {
2019
return Matchers.getElementByText(
2120
NetworkListModalSelectorsText.DELETE_NETWORK,
2221
);
2322
}
2423

25-
get addPopularNetworkButton() {
24+
get addPopularNetworkButton(): DetoxElement {
2625
return Matchers.getElementByText(
2726
NetworkListModalSelectorsText.ADD_POPULAR_NETWORK_BUTTON,
2827
);
2928
}
3029

31-
get networkSearchInput() {
30+
get networkSearchInput(): DetoxElement {
3231
return Matchers.getElementByID(
3332
NetworksViewSelectorsIDs.SEARCH_NETWORK_INPUT_BOX_ID,
3433
);
3534
}
3635

37-
get selectNetwork() {
36+
get selectNetwork(): DetoxElement {
3837
return Matchers.getElementByText(
3938
NetworkListModalSelectorsText.SELECT_NETWORK,
4039
);
4140
}
4241

43-
get testNetToggle() {
42+
get testNetToggle(): DetoxElement {
4443
return Matchers.getElementByID(
4544
NetworkListModalSelectorsIDs.TEST_NET_TOGGLE,
4645
);
4746
}
4847

49-
get deleteButton() {
48+
get deleteButton(): DetoxElement {
5049
return Matchers.getElementByID('delete-network-button');
5150
}
5251

53-
async getCustomNetwork(network, custom = false) {
52+
async getCustomNetwork(
53+
network: string,
54+
custom = false,
55+
): Promise<DetoxElement> {
5456
if (device.getPlatform() === 'android' || !custom) {
5557
return Matchers.getElementByText(network);
5658
}
@@ -60,54 +62,57 @@ class NetworkListModal {
6062
);
6163
}
6264

63-
async tapDeleteButton() {
65+
async tapDeleteButton(): Promise<void> {
6466
await Gestures.waitAndTap(this.deleteNetworkButton);
6567
}
6668

67-
async scrollToTopOfNetworkList() {
68-
await Gestures.swipe(this.networkScroll, 'down', 'fast');
69+
async scrollToTopOfNetworkList(): Promise<void> {
70+
await Gestures.swipe(this.networkScroll, 'down', {
71+
speed: 'fast',
72+
});
6973
}
7074

71-
async changeNetworkTo(networkName, custom) {
75+
async changeNetworkTo(networkName: string, custom = false): Promise<void> {
7276
const elem = this.getCustomNetwork(networkName, custom);
73-
await Gestures.waitAndTap(elem, { delayBeforeTap: 2500 });
74-
await TestHelpers.delay(3000);
77+
await Gestures.waitAndTap(elem);
7578
}
7679

77-
async scrollToBottomOfNetworkList() {
78-
await Gestures.swipe(this.networkScroll, 'up', 'fast');
80+
async scrollToBottomOfNetworkList(): Promise<void> {
81+
await Gestures.swipe(this.networkScroll, 'up', {
82+
speed: 'fast',
83+
});
7984
}
8085

81-
async swipeToDismissModal() {
82-
await Gestures.swipe(this.selectNetwork, 'down', 'slow', 0.9);
86+
async swipeToDismissModal(): Promise<void> {
87+
await Gestures.swipe(this.selectNetwork, 'down', {
88+
speed: 'slow',
89+
percentage: 0.9,
90+
});
8391
}
8492

85-
async tapTestNetworkSwitch() {
86-
await Gestures.waitAndTap(this.testNetToggle, { delayBeforeTap: 2500 });
93+
async tapTestNetworkSwitch(): Promise<void> {
94+
await Gestures.waitAndTap(this.testNetToggle);
8795
}
8896

89-
async longPressOnNetwork(networkName) {
97+
async longPressOnNetwork(networkName: string): Promise<void> {
9098
const network = Matchers.getElementByText(networkName);
9199
await Gestures.tapAndLongPress(network);
92100
}
93101

94-
async SearchNetworkName(networkName) {
95-
await Gestures.typeTextAndHideKeyboard(
96-
this.networkSearchInput,
97-
networkName,
98-
);
102+
async SearchNetworkName(networkName: string): Promise<void> {
103+
await Gestures.typeText(this.networkSearchInput, networkName, {
104+
hideKeyboard: true,
105+
});
99106
}
100107

101-
async tapClearSearch() {
108+
async tapClearSearch(): Promise<void> {
102109
await Gestures.waitAndTap(this.closeIcon);
103110
}
104111

105-
async tapAddNetworkButton() {
106-
await Gestures.waitAndTap(this.addPopularNetworkButton, {
107-
delayBeforeTap: 2500,
108-
});
112+
async tapAddNetworkButton(): Promise<void> {
113+
await Gestures.waitAndTap(this.addPopularNetworkButton);
109114
}
110-
async deleteNetwork() {
115+
async deleteNetwork(): Promise<void> {
111116
await Gestures.waitAndTap(this.deleteButton);
112117
}
113118
}

e2e/pages/Onboarding/CreatePasswordView.js renamed to e2e/pages/Onboarding/CreatePasswordView.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,75 @@
11
import { ChoosePasswordSelectorsIDs } from '../../selectors/Onboarding/ChoosePassword.selectors';
2-
import Matchers from '../../framework/Matchers.ts';
3-
import Gestures from '../../framework/Gestures.ts';
2+
import Matchers from '../../framework/Matchers';
3+
import Gestures from '../../framework/Gestures';
44
import enContent from '../../../locales/languages/en.json';
55

66
class CreatePasswordView {
7-
get container() {
7+
get container(): DetoxElement {
88
return Matchers.getElementByID(ChoosePasswordSelectorsIDs.CONTAINER_ID);
99
}
1010

11-
get newPasswordInput() {
11+
get newPasswordInput(): DetoxElement {
1212
return Matchers.getElementByID(
1313
ChoosePasswordSelectorsIDs.NEW_PASSWORD_INPUT_ID,
1414
);
1515
}
1616

17-
get confirmPasswordInput() {
17+
get confirmPasswordInput(): DetoxElement {
1818
return Matchers.getElementByID(
1919
ChoosePasswordSelectorsIDs.CONFIRM_PASSWORD_INPUT_ID,
2020
);
2121
}
2222

23-
get iUnderstandCheckbox() {
23+
get iUnderstandCheckbox(): DetoxElement {
2424
return Matchers.getElementByID(
2525
ChoosePasswordSelectorsIDs.I_UNDERSTAND_CHECKBOX_ID,
2626
);
2727
}
2828

29-
get iUnderstandCheckboxNewWallet() {
29+
get iUnderstandCheckboxNewWallet(): DetoxElement {
3030
return Matchers.getElementByID(
3131
ChoosePasswordSelectorsIDs.I_UNDERSTAND_CHECKBOX_ID,
3232
);
3333
}
3434

35-
get submitButton() {
35+
get submitButton(): DetoxElement {
3636
return Matchers.getElementByID(ChoosePasswordSelectorsIDs.SUBMIT_BUTTON_ID);
3737
}
3838

39-
get passwordError() {
39+
get passwordError(): DetoxElement {
4040
return Matchers.getElementByText(enContent.import_from_seed.password_error);
4141
}
4242

43-
async resetPasswordInputs() {
44-
await Gestures.clearField(this.newPasswordInput);
45-
await Gestures.clearField(this.confirmPasswordInput);
43+
async resetPasswordInputs(): Promise<void> {
44+
await Gestures.typeText(this.newPasswordInput, '', {
45+
hideKeyboard: true,
46+
});
47+
await Gestures.typeText(this.confirmPasswordInput, '', {
48+
hideKeyboard: true,
49+
});
4650
}
4751

48-
async enterPassword(password) {
52+
async enterPassword(password: string): Promise<void> {
4953
await Gestures.typeText(this.newPasswordInput, password, {
5054
elemDescription: 'Create Password New Password Input',
5155
hideKeyboard: true,
5256
});
5357
}
5458

55-
async reEnterPassword(password) {
59+
async reEnterPassword(password: string): Promise<void> {
5660
await Gestures.typeText(this.confirmPasswordInput, password, {
5761
elemDescription: 'Create Password Confirm Password Input',
5862
hideKeyboard: true,
5963
});
6064
}
6165

62-
async tapIUnderstandCheckBox() {
66+
async tapIUnderstandCheckBox(): Promise<void> {
6367
await Gestures.tap(this.iUnderstandCheckbox, {
6468
elemDescription: 'Create Password - I Understand Checkbox',
6569
});
6670
}
6771

68-
async tapCreatePasswordButton() {
72+
async tapCreatePasswordButton(): Promise<void> {
6973
await Gestures.waitAndTap(this.submitButton, {
7074
elemDescription: 'Create Password Submit Button',
7175
});

e2e/pages/Onboarding/EnableDeviceNotificationsAlert.js renamed to e2e/pages/Onboarding/EnableDeviceNotificationsAlert.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import Gestures from '../../utils/Gestures';
2-
import Matchers from '../../utils/Matchers';
1+
import Gestures from '../../framework/Gestures';
2+
import Matchers from '../../framework/Matchers';
33

44
import { EnableDeviceNotificationsAlertSelectorText } from '../../selectors/Onboarding/EnableDeviceNotificationsAlert.selectors';
55

66
class EnableDeviceNotificationsAlert {
7-
get stepOneContainer() {
7+
get stepOneContainer(): DetoxElement {
88
return Matchers.getSystemElementByText(
99
EnableDeviceNotificationsAlertSelectorText.CONTAINER,
1010
);
1111
}
1212

13-
get getEnableDeviceNotificationsButton() {
13+
get getEnableDeviceNotificationsButton(): DetoxElement {
1414
return Matchers.getSystemElementByText(
1515
EnableDeviceNotificationsAlertSelectorText.YES_BUTTON,
1616
);
1717
}
1818

19-
async tapOnEnableDeviceNotificationsButton() {
20-
await Gestures.waitAndTap(this.getEnableDeviceNotificationsButton);
19+
async tapOnEnableDeviceNotificationsButton(): Promise<void> {
20+
await Gestures.waitAndTap(this.getEnableDeviceNotificationsButton, {
21+
elemDescription: 'Enable Device Notifications Button',
22+
});
2123
}
2224
}
2325

0 commit comments

Comments
 (0)