diff --git a/test/e2e/run-all.js b/test/e2e/run-all.js index b329080abd23..e850b7db1062 100644 --- a/test/e2e/run-all.js +++ b/test/e2e/run-all.js @@ -104,10 +104,8 @@ async function main() { let testPaths; if (snaps) { - testPaths = [ - ...(await getTestPathsForTestDir(path.join(__dirname, 'snaps'))), - ...(await getTestPathsForTestDir(path.join(__dirname, 'accounts'))), - ]; + const testDir = path.join(__dirname, 'snaps'); + testPaths = await getTestPathsForTestDir(testDir); } else if (rpc) { const testDir = path.join(__dirname, 'json-rpc'); testPaths = await getTestPathsForTestDir(testDir); @@ -132,9 +130,9 @@ async function main() { if (buildType !== 'flask') { const filteredTests = [ 'settings-add-snap-account-toggle.spec.js', - 'test-snap-accounts.spec.js', 'test-snap-manageAccount.spec.js', 'test-snap-lifecycle.spec.js', + 'test-snap-get-locale.spec.js', 'ppom-toggle-settings.spec.js', 'petnames.spec.js', ]; diff --git a/test/e2e/snaps/enums.js b/test/e2e/snaps/enums.js index d16ed59ae4a4..15c9d13788b8 100644 --- a/test/e2e/snaps/enums.js +++ b/test/e2e/snaps/enums.js @@ -1,6 +1,5 @@ module.exports = { - TEST_SNAPS_WEBSITE_URL: - 'https://metamask.github.io/snaps/test-snaps/0.38.0-flask.1/', + TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/1.0.0/', TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL: 'https://metamask.github.io/snap-simple-keyring/0.2.2/', }; diff --git a/test/e2e/snaps/test-snap-get-locale.spec.js b/test/e2e/snaps/test-snap-get-locale.spec.js new file mode 100644 index 000000000000..bf270935762d --- /dev/null +++ b/test/e2e/snaps/test-snap-get-locale.spec.js @@ -0,0 +1,173 @@ +const { strict: assert } = require('assert'); +const { withFixtures } = require('../helpers'); +const FixtureBuilder = require('../fixture-builder'); +const { TEST_SNAPS_WEBSITE_URL } = require('./enums'); + +describe('Test Snap Get Locale', function () { + it('test snap_getLocale functionality', async function () { + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: 25000000000000000000, + }, + ], + }; + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions, + failOnConsoleError: false, + title: this.test.title, + }, + async ({ driver }) => { + await driver.navigate(); + + // enter pw into extension + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + // navigate to test snaps page and connect to dialog snap + await driver.openNewPage(TEST_SNAPS_WEBSITE_URL); + await driver.delay(1000); + const dialogButton = await driver.findElement('#connectgetlocale'); + await driver.scrollToElement(dialogButton); + await driver.delay(1000); + await driver.clickElement('#connectgetlocale'); + await driver.delay(1000); + + // switch to metamask extension and click connect + let windowHandles = await driver.waitUntilXWindowHandles( + 3, + 1000, + 10000, + ); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement({ + text: 'Connect', + tag: 'button', + }); + + await driver.waitForSelector({ text: 'Install' }); + + await driver.clickElementSafe('[data-testid="snap-install-scroll"]'); + + await driver.clickElement({ + text: 'Install', + tag: 'button', + }); + + await driver.waitForSelector({ text: 'OK' }); + + await driver.clickElement({ + text: 'OK', + tag: 'button', + }); + + // switch to test snaps tab + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // wait for npm installation success + await driver.waitForSelector({ + css: '#connectgetlocale', + text: 'Reconnect to Get Locale Snap', + }); + + // click on alert dialog + await driver.clickElement('#sendGetLocaleHelloButton'); + await driver.delay(500); + + // switch to dialog popup + windowHandles = await driver.waitUntilXWindowHandles(3, 1000, 10000); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.delay(500); + + // check dialog contents + const result = await driver.findElement('.snap-ui-renderer__panel'); + await driver.scrollToElement(result); + await driver.delay(500); + assert.equal( + await result.getText(), + 'Hello https://metamask.github.io!\nThis is a dialog!', + ); + + // click ok button + await driver.clickElement({ + text: 'OK', + tag: 'button', + }); + + // switch back to test snaps tab + windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000); + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // check for result correctness + await driver.waitForSelector({ + css: '#getLocaleResult', + text: 'null', + }); + + // try switching language to dansk + // + // switch to the original MM tab + const extensionPage = windowHandles[0]; + await driver.switchToWindow(extensionPage); + await driver.delay(1000); + + // click on the global action menu + await driver.clickElement( + '[data-testid="account-options-menu-button"]', + ); + + // try to click on the notification item + await driver.clickElement({ text: 'Settings', tag: 'div' }); + await driver.delay(1000); + + // try to click on the snaps item + await driver.clickElement({ + text: 'General', + tag: 'div', + }); + await driver.delay(1000); + + // try to click on locale-select + await driver.clickElement('[data-testid="locale-select"]'); + + // try to select dansk from the list + await driver.clickElement({ text: 'Dansk', tag: 'option' }); + + // switch back to test snaps tab + windowHandles = await driver.waitUntilXWindowHandles(2, 1000, 10000); + await driver.switchToWindowWithTitle('Test Snaps', windowHandles); + + // click on alert dialog + await driver.clickElement('#sendGetLocaleHelloButton'); + await driver.delay(500); + + // switch to dialog popup + windowHandles = await driver.waitUntilXWindowHandles(3, 1000, 10000); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.delay(500); + + // check dialog contents for dansk result + const result2 = await driver.findElement('.snap-ui-renderer__panel'); + await driver.scrollToElement(result2); + await driver.delay(500); + assert.equal( + await result2.getText(), + 'Hej https://metamask.github.io!\nDette er en dialog!', + ); + }, + ); + }); +});