From e890bed3760ff052f52848c5808b9891f06441bd Mon Sep 17 00:00:00 2001 From: Ibrahim Taveras Date: Mon, 28 Oct 2019 20:59:25 -0400 Subject: [PATCH] added tests for custom rpc --- .../__snapshots__/index.test.js.snap | 2 + app/components/UI/NetworkList/index.js | 5 +- .../__snapshots__/index.test.js.snap | 5 + .../NetworksSettings/NetworkSettings/index.js | 8 +- .../__snapshots__/index.test.js.snap | 2 + .../Views/Settings/NetworksSettings/index.js | 9 +- e2e/add-custom-rpc.spec.js | 91 +++++++++++++++++++ 7 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 e2e/add-custom-rpc.spec.js diff --git a/app/components/UI/NetworkList/__snapshots__/index.test.js.snap b/app/components/UI/NetworkList/__snapshots__/index.test.js.snap index 5dea32f0f00..1bf124e170b 100644 --- a/app/components/UI/NetworkList/__snapshots__/index.test.js.snap +++ b/app/components/UI/NetworkList/__snapshots__/index.test.js.snap @@ -64,6 +64,7 @@ exports[`NetworkList should render correctly 1`] = ` }, ] } + testID="network-name" > Other Networks diff --git a/app/components/UI/NetworkList/index.js b/app/components/UI/NetworkList/index.js index 6d7ac997907..0b53d35f05f 100644 --- a/app/components/UI/NetworkList/index.js +++ b/app/components/UI/NetworkList/index.js @@ -224,6 +224,7 @@ export class NetworkList extends PureComponent { style={[styles.network, styles.mainnet]} key={`network-mainnet`} onPress={() => this.onNetworkChange('mainnet')} // eslint-disable-line + testID={'network-name'} > {isMainnet} @@ -254,7 +255,9 @@ export class NetworkList extends PureComponent { {this.renderMainnet()} - {strings('networks.other_networks')} + + {strings('networks.other_networks')} + {this.renderOtherNetworks()} {this.renderRpcNetworks()} diff --git a/app/components/Views/Settings/NetworksSettings/NetworkSettings/__snapshots__/index.test.js.snap b/app/components/Views/Settings/NetworksSettings/NetworkSettings/__snapshots__/index.test.js.snap index b93bf0aa0e7..054c6f3065d 100644 --- a/app/components/Views/Settings/NetworksSettings/NetworkSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/Settings/NetworksSettings/NetworkSettings/__snapshots__/index.test.js.snap @@ -9,6 +9,7 @@ exports[`NetworkSettings should render correctly 1`] = ` "flexDirection": "column", } } + testID="new-rpc-screen" > Add diff --git a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js index 6e451242446..5ce95e71152 100644 --- a/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js +++ b/app/components/Views/Settings/NetworksSettings/NetworkSettings/index.js @@ -296,7 +296,7 @@ class NetworkSettings extends PureComponent { enableAction } = this.state; return ( - + {addMode && {strings('app_settings.new_RPC_URL')}} @@ -313,6 +313,7 @@ class NetworkSettings extends PureComponent { placeholder={strings('app_settings.network_name_placeholder')} placeholderTextColor={colors.grey100} onSubmitEditing={this.jumpToRpcURL} + testID={'input-network-name'} /> {strings('app_settings.network_rpc_url_label')} @@ -328,9 +329,10 @@ class NetworkSettings extends PureComponent { placeholder={strings('app_settings.network_rpc_placeholder')} placeholderTextColor={colors.grey100} onSubmitEditing={this.jumpToChainId} + testID={'input-rpc-url'} /> {warningRpcUrl && ( - + {warningRpcUrl} )} @@ -368,6 +370,7 @@ class NetworkSettings extends PureComponent { placeholder={strings('app_settings.network_symbol_placeholder')} placeholderTextColor={colors.grey100} onSubmitEditing={this.jumpBlockExplorerURL} + testID={'input-network-symbol'} /> {strings('app_settings.network_block_explorer_label')} @@ -390,6 +393,7 @@ class NetworkSettings extends PureComponent { diff --git a/app/components/Views/Settings/NetworksSettings/__snapshots__/index.test.js.snap b/app/components/Views/Settings/NetworksSettings/__snapshots__/index.test.js.snap index 37b02bde19e..d298d14d2d8 100644 --- a/app/components/Views/Settings/NetworksSettings/__snapshots__/index.test.js.snap +++ b/app/components/Views/Settings/NetworksSettings/__snapshots__/index.test.js.snap @@ -11,6 +11,7 @@ exports[`NetworksSettings should render correctly 1`] = ` "paddingVertical": 12, } } + testID="networks-screen" > @@ -345,6 +346,7 @@ exports[`NetworksSettings should render correctly 1`] = ` "opacity": 0.6, } } + testID="add-network-button" type="confirm" > Add Network diff --git a/app/components/Views/Settings/NetworksSettings/index.js b/app/components/Views/Settings/NetworksSettings/index.js index 2627aa42ef8..0ce76da4234 100644 --- a/app/components/Views/Settings/NetworksSettings/index.js +++ b/app/components/Views/Settings/NetworksSettings/index.js @@ -190,14 +190,19 @@ class NetworksSettings extends PureComponent { render() { return ( - + {this.renderMainnet()} {strings('app_settings.network_other_networks')} {this.renderOtherNetworks()} {this.renderRpcNetworksView()} - + {strings('app_settings.network_add_network')} { + beforeEach(() => { + jest.setTimeout(170000); + }); + + it('should create new wallet and dismiss tutorial', async () => { + // Check that we are on the onboarding carousel screen + await TestHelpers.checkIfVisible('onboarding-carousel-screen'); + // Check that Get started CTA is visible & tap it + await TestHelpers.waitAndTap('onboarding-get-started-button'); + // Check that we are on the onboarding screen + await TestHelpers.checkIfVisible('onboarding-screen'); + // Check that Start Exploring CTA is visible & tap it + await TestHelpers.waitAndTap('start-exploring-button'); + // Check that we are on the metametrics optIn screen + await TestHelpers.checkIfVisible('metaMetrics-OptIn'); + // Check that I Agree CTA is visible and tap it + await TestHelpers.waitAndTap('agree-button'); + // Check that we are on the wallet screen + await TestHelpers.checkIfExists('wallet-screen'); + // Check that the onboarding wizard is present + await TestHelpers.checkIfVisible('onboarding-wizard-step1-view'); + // Check that No thanks CTA is visible and tap it + await TestHelpers.waitAndTap('onboarding-wizard-back-button'); + // Check that the onboarding wizard is gone + await TestHelpers.checkIfNotVisible('onboarding-wizard-step1-view'); + }); + + it('should go to settings then networks', async () => { + // Open Drawer + await TestHelpers.tapAtPoint('wallet-screen', { x: 30, y: -5 }); + // Check that the drawer is visbile + await TestHelpers.checkIfVisible('drawer-screen'); + // Tap on settings + await TestHelpers.tap('settings-button'); + // Tap on the "Networks" option + await TestHelpers.tapByText('Networks'); + // Check that we are on the networks screen + await TestHelpers.checkIfVisible('networks-screen'); + }); + + it('should add xDai network', async () => { + // Tap on Add Network button + await TestHelpers.tap('add-network-button'); + // Check that we are on the add new rpc network screen + await TestHelpers.checkIfVisible('new-rpc-screen'); + // Input Network Name + await TestHelpers.typeTextAndHideKeyboard('input-network-name', 'xDai'); + // Input incorrect RPC URL + await TestHelpers.typeTextAndHideKeyboard('input-rpc-url', 'abc'); + // Check that warning is displayed + await TestHelpers.checkIfVisible('rpc-url-warning'); + // Clear RPC URL field + await TestHelpers.clearField('input-rpc-url'); + // Input correct RPC URL for Ganache network + await TestHelpers.typeTextAndHideKeyboard('input-rpc-url', XDAI_URL); + // Focus outside of text input field + await TestHelpers.tapAtPoint('new-rpc-screen', { x: 280, y: 30 }); + // Input Symbol + await TestHelpers.typeTextAndHideKeyboard('input-network-symbol', 'xDAI'); + // Focus outside of text input field + await TestHelpers.tapAtPoint('new-rpc-screen', { x: 280, y: 30 }); + // Tap on Add button + await TestHelpers.waitAndTap('network-add-button'); + // Check that we are on the wallet screen + await TestHelpers.checkIfVisible('wallet-screen'); + // Check that we are on correct network + await TestHelpers.checkIfElementHasString('network-name', 'xDai'); + }); + + it('should validate that xDai is added to network list then switch networks', async () => { + // Tap to prompt network list + await TestHelpers.tapAtPoint('wallet-screen', { x: 200, y: -5 }); + // Check that networks list is visible + await TestHelpers.checkIfVisible('networks-list'); + // Swipe down on networks list + await TestHelpers.swipe('networks-list', 'up'); + // Check that our network is added + await TestHelpers.checkIfElementHasString('other-network-name', 'xDai'); + // Change to Rinkeby Network + await TestHelpers.tapByText(RINKEBY); + // Check that we are on correct network + await TestHelpers.checkIfElementHasString('network-name', RINKEBY); + }); +});