|
| 1 | +import { strict as assert } from 'assert'; |
| 2 | +import { Suite } from 'mocha'; |
| 3 | +import FixtureBuilder from '../../fixture-builder'; |
| 4 | +import { |
| 5 | + defaultGanacheOptions, |
| 6 | + unlockWallet, |
| 7 | + withFixtures, |
| 8 | +} from '../../helpers'; |
| 9 | +import { Driver } from '../../webdriver/driver'; |
| 10 | + |
| 11 | +const selectors = { |
| 12 | + accountOptionsMenuButton: '[data-testid="account-options-menu-button"]', |
| 13 | + informationSymbol: '[data-testid="info-tooltip"]', |
| 14 | + settingsOption: { text: 'Settings', tag: 'div' }, |
| 15 | + networkOption: { text: 'Networks', tag: 'div' }, |
| 16 | + generalOption: { text: 'General', tag: 'div' }, |
| 17 | + ethereumNetwork: { text: 'Ethereum Mainnet', tag: 'div' }, |
| 18 | + deleteButton: { text: 'Delete', tag: 'button' }, |
| 19 | + cancelButton: { text: 'Cancel', tag: 'button' }, |
| 20 | + saveButton: { text: 'Save', tag: 'button' }, |
| 21 | + updatedNetworkDropDown: { tag: 'span', text: 'Update Network' }, |
| 22 | + errorMessageInvalidUrl: { |
| 23 | + tag: 'h6', |
| 24 | + text: 'URLs require the appropriate HTTP/HTTPS prefix.', |
| 25 | + }, |
| 26 | + networkNameInputField: '[data-testid="network-form-network-name"]', |
| 27 | + rpcUrlInputField: '[data-testid="network-form-rpc-url"]', |
| 28 | + chainIdInputField: '[data-testid="network-form-chain-id"]', |
| 29 | + errorContainer: '.settings-tab__error', |
| 30 | +}; |
| 31 | + |
| 32 | +const inputData = { |
| 33 | + networkName: 'Update Network', |
| 34 | + rpcUrl: 'test', |
| 35 | + chainId: '0x539', |
| 36 | +}; |
| 37 | + |
| 38 | +async function navigateToEditNetwork(driver: Driver) { |
| 39 | + await driver.clickElement(selectors.accountOptionsMenuButton); |
| 40 | + await driver.clickElement(selectors.settingsOption); |
| 41 | + await driver.clickElement(selectors.networkOption); |
| 42 | +} |
| 43 | +describe('Update Network:', function (this: Suite) { |
| 44 | + it('update network details and validate the ui elements', async function () { |
| 45 | + await withFixtures( |
| 46 | + { |
| 47 | + fixtures: new FixtureBuilder().build(), |
| 48 | + ganacheOptions: defaultGanacheOptions, |
| 49 | + title: this.test?.fullTitle(), |
| 50 | + }, |
| 51 | + |
| 52 | + async ({ driver }: { driver: Driver }) => { |
| 53 | + await unlockWallet(driver); |
| 54 | + await navigateToEditNetwork(driver); |
| 55 | + await driver.fill( |
| 56 | + selectors.networkNameInputField, |
| 57 | + inputData.networkName, |
| 58 | + ); |
| 59 | + await driver.fill(selectors.chainIdInputField, inputData.chainId); |
| 60 | + await driver.clickElement(selectors.saveButton); |
| 61 | + |
| 62 | + // Validate the error does not appear for updating the network name and chain id |
| 63 | + await driver.clickElement(selectors.generalOption); |
| 64 | + await driver.assertElementNotPresent(selectors.errorContainer); |
| 65 | + |
| 66 | + // Validate the network name is updated |
| 67 | + const updatedNetworkNamePresent = await driver.isElementPresent( |
| 68 | + selectors.updatedNetworkDropDown, |
| 69 | + ); |
| 70 | + assert.equal( |
| 71 | + updatedNetworkNamePresent, |
| 72 | + true, |
| 73 | + 'Network name is not updated', |
| 74 | + ); |
| 75 | + |
| 76 | + await navigateToEditNetwork(driver); |
| 77 | + await driver.fill(selectors.rpcUrlInputField, inputData.rpcUrl); |
| 78 | + |
| 79 | + // Validate the error message that appears for the invalid url format |
| 80 | + const errorMessage = await driver.isElementPresent( |
| 81 | + selectors.errorMessageInvalidUrl, |
| 82 | + ); |
| 83 | + assert.equal( |
| 84 | + errorMessage, |
| 85 | + true, |
| 86 | + 'Error message for the invalid url did not appear', |
| 87 | + ); |
| 88 | + |
| 89 | + // Validate the Save button is disabled for the invalid url format |
| 90 | + const saveButton = await driver.findElement(selectors.saveButton); |
| 91 | + const saveButtonEnabled = await saveButton.isEnabled(); |
| 92 | + assert.equal(saveButtonEnabled, false, 'Save button is enabled'); |
| 93 | + |
| 94 | + // Validate the information symbol appears for chain id |
| 95 | + const informationSymbolAppears = await driver.isElementPresent( |
| 96 | + selectors.informationSymbol, |
| 97 | + ); |
| 98 | + assert.equal( |
| 99 | + informationSymbolAppears, |
| 100 | + true, |
| 101 | + 'Information symbol did not appear for chain id', |
| 102 | + ); |
| 103 | + |
| 104 | + await driver.clickElement(selectors.ethereumNetwork); |
| 105 | + |
| 106 | + // Validate the Save,Cancel Delete button is not present for the default network |
| 107 | + await driver.assertElementNotPresent(selectors.deleteButton); |
| 108 | + await driver.assertElementNotPresent(selectors.cancelButton); |
| 109 | + await driver.assertElementNotPresent(selectors.saveButton); |
| 110 | + }, |
| 111 | + ); |
| 112 | + }); |
| 113 | +}); |
0 commit comments