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

test: [Snaps E2E] Create test for snaps interactive ui functions #24884

Merged
merged 7 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion test/e2e/snaps/enums.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.6.1/',
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.8.0/',
};
99 changes: 99 additions & 0 deletions test/e2e/snaps/test-snap-interactive-ui.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const {
defaultGanacheOptions,
withFixtures,
unlockWallet,
switchToNotificationWindow,
WINDOW_TITLES,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
const { TEST_SNAPS_WEBSITE_URL } = require('./enums');

describe('Test Snap Interactive UI', function () {
it('test interactive ui elements', async function () {
await withFixtures(
{
fixtures: new FixtureBuilder().build(),
ganacheOptions: defaultGanacheOptions,
failOnConsoleError: false,
title: this.test.fullTitle(),
},
async ({ driver }) => {
await unlockWallet(driver);

// navigate to test snaps page and connect to interactive ui snap
await driver.openNewPage(TEST_SNAPS_WEBSITE_URL);
await driver.delay(1000);
const dialogButton = await driver.findElement('#connectinteractive-ui');
await driver.scrollToElement(dialogButton);
await driver.delay(1000);
await driver.clickElement('#connectinteractive-ui');

// switch to metamask extension and click connect
await switchToNotificationWindow(driver);
await driver.clickElement({
text: 'Connect',
tag: 'button',
});

await driver.clickElementSafe('[data-testid="snap-install-scroll"]');

await driver.waitForSelector({ text: 'Confirm' });

await driver.clickElement({
text: 'Confirm',
tag: 'button',
});

await driver.waitForSelector({ text: 'OK' });

await driver.clickElement({
text: 'OK',
tag: 'button',
});

// switch to test snaps tab
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestSnaps);

// wait for npm installation success
await driver.waitForSelector('#connectinteractive-ui');

// click create dialog button
await driver.clickElement('#createDialogButton');
await driver.delay(500);

// switch to dialog popup
await switchToNotificationWindow(driver);
await driver.delay(500);

// fill in thr example input
await driver.fill('#example-input', 'foo bar');

// try to click on dropdown
await driver.waitForSelector('[data-testid="snaps-dropdown"]');
await driver.clickElement('[data-testid="snaps-dropdown"]');

// try to select option 2 from the list
await driver.clickElement({ text: 'Option 2', tag: 'option' });

// try to click approve
await driver.clickElement('#submit');

// check for returned values
await driver.waitForSelector({ text: 'foo bar', tag: 'p' });
await driver.waitForSelector({ text: 'option2', tag: 'p' });

// try to click on approve
await driver.clickElement('[data-testid="confirmation-submit-button"]');

// switch to test snaps tab
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestSnaps);

// look for returned true
await driver.waitForSelector({
text: 'true',
css: '#interactiveUIResult',
});
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export const SnapUIDropdown: FunctionComponent<SnapUIDropdownProps> = ({
flexDirection={FlexDirection.Column}
>
{label && <Label htmlFor={name}>{label}</Label>}
<Dropdown selectedOption={value} onChange={handleChange} {...props} />
<Dropdown
data-testid="snaps-dropdown"
selectedOption={value}
onChange={handleChange}
{...props}
/>
{error && (
<HelpText severity={HelpTextSeverity.Danger} marginTop={1}>
{error}
Expand Down