Skip to content

Commit

Permalink
test(extension): e2e - add tests for DApps: empty state + app on the …
Browse files Browse the repository at this point in the history
…… (#2707)
  • Loading branch information
ljagiela committed May 25, 2023
2 parents 4581ad4 + eb3c81e commit 3ff76f3
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 160 deletions.
Expand Up @@ -56,7 +56,7 @@ export const DappList = withDappContext(
popupView={popupView}
>
<>
<Text className={styles.description}>
<Text className={styles.description} data-testid="dapp-list-subtitle">
{hasConnectedDapps ? t('dapp.list.subTitle') : t('dapp.list.subTitleEmpty')}
</Text>
{visible &&
Expand Down
Expand Up @@ -15,7 +15,9 @@ export const DappListEmpty = ({ title }: dappListEmptyProps): React.ReactElement
return (
<div data-testid="dapp-list-empty" className={styles.container}>
<Image data-testid="dapp-list-empty-image" preview={false} width={120} src={Empty} />
<div className={styles.text}>{title || translate('dapp.list.empty.text')}</div>
<div data-testid="dapp-list-empty-text" className={styles.text}>
{title || translate('dapp.list.empty.text')}
</div>
</div>
);
};
Expand Up @@ -5,7 +5,7 @@ import { Avatar } from 'antd';
import { ReactComponent as DeleteIcon } from '../../assets/icons/delete-icon.component.svg';

export const DAPP_CONTAINER_TESTID = 'dapp-container-id';
export const LOGO_TESTID = 'dapp-logo-id';
export const LOGO_TESTID = 'connected-dapp-logo';
export const DELETE_ICON_TESTID = 'dapp-delete-icon-id';

type DappInfo = {
Expand All @@ -25,8 +25,10 @@ export const ConnectedDapp = ({ name, url, logo, onDelete }: connectedDappProps)
<Avatar className={styles.logo} alt="connected-dapp-logo" data-testid={LOGO_TESTID} src={logo} />
</div>
<div className={styles.body}>
<div className={styles.name}>{name}</div>
<div className={styles.url}>
<div data-testid="connected-dapp-name" className={styles.name}>
{name}
</div>
<div data-testid="connected-dapp-url" className={styles.url}>
<div>{url}</div>
</div>
</div>
Expand Down
126 changes: 126 additions & 0 deletions packages/e2e-tests/src/assert/dAppConnectorAssert.ts
@@ -0,0 +1,126 @@
import { expect } from 'chai';
import { t } from '../utils/translationService';
import AuthorizeDAppPage from '../elements/dappConnector/authorizeDAppPage';
import AuthorizedDAppsPage from '../elements/dappConnector/authorizedDAppsPage';
import AuthorizeDAppModal from '../elements/dappConnector/authorizeDAppModal';
import ExampleDAppPage from '../elements/dappConnector/testDAppPage';

export type ExpectedAuthorizedDAppDetails = {
hasLogo: boolean;
name: string;
url: string;
};

class DAppConnectorAssert {
async assertSeeAuthorizeDAppPage(expectedDappName: string, expectedDappUrl: string) {
await AuthorizeDAppPage.headerLogo.waitForDisplayed();
await AuthorizeDAppPage.betaPill.waitForDisplayed();
await expect(await AuthorizeDAppPage.betaPill.getText()).to.equal(await t('core.dapp.beta'));

await AuthorizeDAppPage.pageTitle.waitForDisplayed();
await expect(await AuthorizeDAppPage.pageTitle.getText()).to.equal(await t('dapp.connect.header'));

await AuthorizeDAppPage.dAppLogo.waitForDisplayed();
await AuthorizeDAppPage.dAppName.waitForDisplayed();
await expect(await AuthorizeDAppPage.dAppName.getText()).to.equal(expectedDappName);
await AuthorizeDAppPage.dAppUrl.waitForDisplayed();
await expect(await AuthorizeDAppPage.dAppUrl.getText()).to.equal(expectedDappUrl);

await AuthorizeDAppPage.banner.container.waitForDisplayed();
await AuthorizeDAppPage.banner.icon.waitForDisplayed();
await AuthorizeDAppPage.banner.description.waitForDisplayed();
await expect(await AuthorizeDAppPage.banner.description.getText()).to.equal(await t('core.authorizeDapp.warning'));
await this.assertSeeAuthorizePagePermissions();

await AuthorizeDAppPage.authorizeButton.waitForDisplayed();
await expect(await AuthorizeDAppPage.authorizeButton.getText()).to.equal(await t('dapp.connect.btn.accept'));
await AuthorizeDAppPage.cancelButton.waitForDisplayed();
await expect(await AuthorizeDAppPage.cancelButton.getText()).to.equal(await t('dapp.connect.btn.cancel'));
}

async assertSeeAuthorizePagePermissions() {
await AuthorizeDAppPage.permissionsTitle.waitForDisplayed();
await expect(await AuthorizeDAppPage.permissionsTitle.getText()).to.equal(
`${await t('package.core.authorizeDapp.title', true)}:`
);

await AuthorizeDAppPage.permissionsList.waitForDisplayed();
const currentTexts = await AuthorizeDAppPage.permissionsListItems.map(async (option) => await option.getText());

const expectedTexts = [
await t('package.core.authorizeDapp.seeNetwork', true),
await t('package.core.authorizeDapp.seeWalletUtxo', true),
await t('package.core.authorizeDapp.seeWalletBalance', true),
await t('package.core.authorizeDapp.seeWalletAddresses', true)
];

await expect(currentTexts).to.have.all.members(expectedTexts);
}

async assertSeeDAppConnectionModal() {
await AuthorizeDAppModal.container.waitForDisplayed();
await AuthorizeDAppModal.title.waitForDisplayed();
await expect(await AuthorizeDAppModal.title.getText()).to.equal(await t('dapp.connect.modal.header'));

await AuthorizeDAppModal.description.waitForDisplayed();
await expect(await AuthorizeDAppModal.description.getText()).to.equal(await t('dapp.connect.modal.description'));

await AuthorizeDAppModal.alwaysButton.waitForDisplayed();
await expect(await AuthorizeDAppModal.alwaysButton.getText()).to.equal(await t('dapp.connect.modal.allowAlways'));

await AuthorizeDAppModal.onceButton.waitForDisplayed();
await expect(await AuthorizeDAppModal.onceButton.getText()).to.equal(await t('dapp.connect.modal.allowOnce'));
}

async assertWalletFoundButNotConnectedInTestDApp() {
await expect(await ExampleDAppPage.walletItem.getAttribute('value')).to.equal('lace');
await expect(await ExampleDAppPage.walletFound.getText()).to.equal('true');
await expect(await ExampleDAppPage.walletConnected.getText()).to.equal('false');
await expect(await ExampleDAppPage.walletApiVersion.getText()).to.equal('0.1.0');
await expect(await ExampleDAppPage.walletName.getText()).to.equal('lace');
await expect(await ExampleDAppPage.walletNetworkId.getText()).to.be.empty;
await expect(await ExampleDAppPage.walletBalance.getText()).to.be.empty;
await expect(await ExampleDAppPage.walletChangeAddress.getText()).to.be.empty;
await expect(await ExampleDAppPage.walletStakingAddress.getText()).to.be.empty;
await expect(await ExampleDAppPage.walletUsedAddress.getText()).to.be.empty;
}

async assertSeeAuthorizedDAppsEmptyState(mode: 'extended' | 'popup') {
if (mode === 'extended') {
await AuthorizedDAppsPage.drawerNavigationTitle.waitForDisplayed();
await expect(await AuthorizedDAppsPage.drawerNavigationTitle.getText()).to.equal(
await t('browserView.settings.heading')
);

await AuthorizedDAppsPage.closeButton.waitForDisplayed();
await AuthorizedDAppsPage.backButton.waitForDisplayed({ reverse: true });
} else {
await AuthorizedDAppsPage.closeButton.waitForDisplayed({ reverse: true });
await AuthorizedDAppsPage.backButton.waitForDisplayed();
}

await AuthorizedDAppsPage.drawerHeaderTitle.waitForDisplayed();
await expect(await AuthorizedDAppsPage.drawerHeaderTitle.getText()).to.equal(await t('dapp.list.title'));

await AuthorizedDAppsPage.drawerHeaderSubtitle.waitForDisplayed();
await expect(await AuthorizedDAppsPage.drawerHeaderSubtitle.getText()).to.equal(await t('dapp.list.subTitleEmpty'));

await AuthorizedDAppsPage.emptyStateImage.waitForDisplayed();
await AuthorizedDAppsPage.emptyStateText.waitForDisplayed();
await expect(await AuthorizedDAppsPage.emptyStateText.getText()).to.equal(await t('dapp.list.empty.text'));

expect(await AuthorizedDAppsPage.dAppContainers.length).to.equal(0);
}

async assertSeeAuthorizedDAppsOnTheList(expectedDApps: ExpectedAuthorizedDAppDetails[]) {
expect(await AuthorizedDAppsPage.dAppContainers.length).to.equal(expectedDApps.length);
for (const [i, expectedDapp] of expectedDApps.entries()) {
await AuthorizedDAppsPage.dAppLogos[i].waitForDisplayed({ reverse: !expectedDApps[i].hasLogo });
await expect(await AuthorizedDAppsPage.dAppNames[i].getText()).to.equal(expectedDapp.name);
await expect(await AuthorizedDAppsPage.dAppUrls[i].getText()).to.equal(expectedDapp.url);
await AuthorizedDAppsPage.dAppRemoveButtons[i].waitForDisplayed();
}
}
}

export default new DAppConnectorAssert();
82 changes: 0 additions & 82 deletions packages/e2e-tests/src/assert/dappConnectorAssert.ts

This file was deleted.

@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
import { ChainablePromiseElement } from 'webdriverio';

class AuthorizeDappModal {
class AuthorizeDAppModal {
private CONTAINER = '[data-testid="connect-modal-container"]';
private TITLE = '[data-testid="connect-modal-title"]';
private DESCRIPTION = '[data-testid="connect-modal-description"]';
Expand Down Expand Up @@ -29,4 +29,4 @@ class AuthorizeDappModal {
}
}

export default new AuthorizeDappModal();
export default new AuthorizeDAppModal();
Expand Up @@ -3,7 +3,7 @@ import Banner from '../banner';
import { ChainablePromiseElement } from 'webdriverio';
import { ChainablePromiseArray } from 'webdriverio/build/types';

class AuthorizeDappPage {
class AuthorizeDAppPage {
private HEADER_LOGO = '[data-testid="header-logo"]';
private BETA_PILL = '[data-testid="beta-pill"]';
private PAGE_TITLE = '[data-testid="layout-title"]';
Expand All @@ -27,15 +27,15 @@ class AuthorizeDappPage {
return $(this.PAGE_TITLE);
}

get dappLogo(): ChainablePromiseElement<WebdriverIO.Element> {
get dAppLogo(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.DAPP_LOGO);
}

get dappName(): ChainablePromiseElement<WebdriverIO.Element> {
get dAppName(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.DAPP_NAME);
}

get dappUrl(): ChainablePromiseElement<WebdriverIO.Element> {
get dAppUrl(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.DAPP_URL);
}

Expand Down Expand Up @@ -64,4 +64,4 @@ class AuthorizeDappPage {
}
}

export default new AuthorizeDappPage();
export default new AuthorizeDAppPage();
@@ -0,0 +1,49 @@
/* eslint-disable no-undef */
import { ChainablePromiseElement } from 'webdriverio';
import { ChainablePromiseArray } from 'webdriverio/build/types';
import CommonDrawerElements from '../CommonDrawerElements';

class AuthorizedDAppsPage extends CommonDrawerElements {
private SUBTITLE = '[data-testid="dapp-list-subtitle"]';
private EMPTY_STATE_IMAGE = '[data-testid="dapp-list-empty-image"]';
private EMPTY_STATE_TEXT = '[data-testid="dapp-list-empty-text"]';
private DAPP_CONTAINER = '[data-testid="dapp-container-id"]';
private DAPP_LOGO = '[data-testid="connected-dapp-logo"]';
private DAPP_NAME = '[data-testid="connected-dapp-name"]';
private DAPP_URL = '[data-testid="connected-dapp-url"]';
private DAPP_DELETE_ICON = '[data-testid="dapp-delete-icon-id"]';

get drawerHeaderSubtitle(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.SUBTITLE);
}

get emptyStateImage(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.EMPTY_STATE_IMAGE);
}

get emptyStateText(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.EMPTY_STATE_TEXT);
}

get dAppContainers(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$(this.DAPP_CONTAINER);
}

get dAppLogos(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$(this.DAPP_LOGO);
}

get dAppNames(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$(this.DAPP_NAME);
}

get dAppUrls(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$(this.DAPP_URL);
}

get dAppRemoveButtons(): ChainablePromiseArray<WebdriverIO.ElementArray> {
return $$(this.DAPP_DELETE_ICON);
}
}

export default new AuthorizedDAppsPage();
32 changes: 32 additions & 0 deletions packages/e2e-tests/src/elements/dappConnector/removeDAppModal.ts
@@ -0,0 +1,32 @@
/* eslint-disable no-undef */
import { ChainablePromiseElement } from 'webdriverio';

class RemoveDAppModal {
private CONTAINER = '.ant-modal-body';
private TITLE = '[data-testid="delete-dapp-modal-title"]';
private DESCRIPTION = '[data-testid="delete-dapp-modal-description"]';
private CONFIRM_BUTTON = '[data-testid="delete-dapp-modal-confirm"]';
private CANCEL_BUTTON = '[data-testid="delete-dapp-modal-cancel"]';

get container(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.CONTAINER);
}

get title(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.TITLE);
}

get description(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.DESCRIPTION);
}

get confirmButton(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.CONFIRM_BUTTON);
}

get cancelButton(): ChainablePromiseElement<WebdriverIO.Element> {
return $(this.CANCEL_BUTTON);
}
}

export default new RemoveDAppModal();
@@ -1,7 +1,7 @@
/* eslint-disable no-undef */
import { ChainablePromiseElement } from 'webdriverio';

class TestDappPage {
class TestDAppPage {
private WALLET_ITEM = '[data-testid="wallet-item"]';
private REFRESH_BUTTON = '[data-testid="refresh-button"]';
private WALLET_FOUND = '[data-testid="wallet-found"]';
Expand Down Expand Up @@ -108,4 +108,4 @@ class TestDappPage {
}
}

export default new TestDappPage();
export default new TestDAppPage();

0 comments on commit 3ff76f3

Please sign in to comment.