Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLASK] Create new E2E test for snap_getLocale #20861

Merged
merged 16 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/e2e/run-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async function main() {
'settings-add-snap-account-toggle.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',
];
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/snaps/enums.js
Original file line number Diff line number Diff line change
@@ -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/',
};
173 changes: 173 additions & 0 deletions test/e2e/snaps/test-snap-get-locale.spec.js
Original file line number Diff line number Diff line change
@@ -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!',
bowensanders marked this conversation as resolved.
Show resolved Hide resolved
);

// 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!',
);
},
);
});
});
Loading