Skip to content

Commit

Permalink
chore(e2e): create account in wallet (#2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Jan 30, 2025
1 parent 0d702ff commit 824f91e
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function Accounts({
</Stack>
</Stack>
{accountsToShow.length ? (
<ul className={listClass}>
<ul className={listClass} data-testid="assetList">
{accountsToShow.map((account) => (
<li key={account.uuid}>
<AccountItem account={account} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,61 @@ import { WebAuthNHelper } from '../../helpers/chainweaver/webauthn.helper';
export class ChainweaverAppIndex {
private _webAuthNHelper: WebAuthNHelper = new WebAuthNHelper();
private _PROFILENAME: string = 'He-man';
private _PROFILENAME_WITHPASSWORD: string = 'Skeletor';
private _PASSWORD: string = 'M4st3r_of_th3_un1v3rs3';

public constructor() {}

public async createProfile(actor: Page): Promise<boolean> {
public async createAccount(actor: Page): Promise<boolean> {
const listItems = await actor
.getByTestId('assetList')
.getByRole('listitem')
.all();
await expect(listItems.length).toEqual(0);

const newAccountButton = actor.getByRole('button', {
name: 'Next Account',
});
await expect(newAccountButton).toBeVisible();
await newAccountButton.click();

const unlockButton = actor.getByRole('button', {
name: 'Unlock',
});

await expect(unlockButton).toBeVisible();
const input = actor.getByTestId('passwordField');
await input.fill(this._PASSWORD);

await unlockButton.click();
await expect(unlockButton).toBeHidden();

const newListItems = await actor
.getByTestId('assetList')
.getByRole('listitem')
.all();

await expect(newListItems.length).toEqual(1);
return true;
}

public async setup(actor: Page, full: boolean = true): Promise<boolean> {
await actor.goto('/');
await this.createProfileWithPassword(actor);
await this.goToSettings(actor);

if (full) {
await this.addNetwork(actor, {
networkId: 'development',
title: 'development',
host: 'http://localhost:8080',
});

await this.selectNetwork(actor, 'Development');
}
return true;
}
public async createProfile(actor: Page): Promise<string> {
await this._webAuthNHelper.enableVirtualAuthenticator(actor);

const button = actor.getByText('Add new profile');
Expand All @@ -28,12 +79,50 @@ export class ChainweaverAppIndex {
await expect(skipButton).toBeVisible();
await skipButton.click();

return true;
return this._PROFILENAME;
}
public async createProfileWithPassword(actor: Page): Promise<string> {
const button = actor.getByText('Add new profile');
await expect(button).toBeVisible();
await button.click();

const passwordButton = actor.getByRole('button', {
name: 'Prefer password',
});
await expect(passwordButton).toBeVisible();
await actor.fill('#profileName', this._PROFILENAME_WITHPASSWORD);
await passwordButton.click();

//create password
await expect(
actor.getByRole('heading', {
name: 'Choose a password',
}),
).toBeVisible();

const continueButton = actor.getByRole('button', {
name: 'Continue',
});
await expect(continueButton).toBeDisabled();

await actor.fill('#password', this._PASSWORD);
await actor.fill('#confirmation', this._PASSWORD);

await expect(continueButton).toBeEnabled();
await continueButton.click();

const skipButton = actor.getByRole('button', {
name: 'Skip',
});
await expect(skipButton).toBeVisible();
await skipButton.click();

return this._PROFILENAME_WITHPASSWORD;
}

public async logout(actor: Page): Promise<boolean> {
public async logout(actor: Page, profileName: string): Promise<boolean> {
const profileButton = actor.getByRole('button', {
name: this._PROFILENAME,
name: profileName,
});
await expect(profileButton).toHaveAttribute('aria-haspopup');
await profileButton.click();
Expand Down
17 changes: 17 additions & 0 deletions packages/e2e/e2e-dev-wallet/tests/createAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test } from '@kadena-dev/e2e-base/src/fixtures/shared/test.fixture';
import { expect } from '@playwright/test';

test('Create account', async ({ initiator, chainweaverApp }) => {
await test.step('setup', async () => {
await chainweaverApp.setup(initiator);
});

await test.step('create account', async () => {
await initiator.goto('/');
await chainweaverApp.selectNetwork(initiator, 'Development');

const result = await chainweaverApp.createAccount(initiator);

expect(result).toEqual(true);
});
});
8 changes: 4 additions & 4 deletions packages/e2e/e2e-dev-wallet/tests/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { test } from '@kadena-dev/e2e-base/src/fixtures/shared/test.fixture';
import { expect } from '@playwright/test';

test('Network creation', async ({ initiator, chainweaverApp }) => {
await test.step('setup', async () => {
await chainweaverApp.setup(initiator, false);
});
await test.step('Create network', async () => {
await initiator.goto('/');
await chainweaverApp.createProfile(initiator);
await chainweaverApp.goToSettings(initiator);

await initiator.goto('/networks');
await expect(initiator.getByText('mainnet01 - Mainnet')).toBeVisible();
await expect(initiator.getByText('development - development')).toBeHidden();

Expand Down
26 changes: 22 additions & 4 deletions packages/e2e/e2e-dev-wallet/tests/profile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { test } from '@kadena-dev/e2e-base/src/fixtures/shared/test.fixture';
import { expect } from '@playwright/test';

test('Login', async ({ initiator, chainweaverApp }) => {
test('Login passwordless', async ({ initiator, chainweaverApp }) => {
await test.step('create profile', async () => {
await initiator.goto('/');
const loggedIn = await chainweaverApp.createProfile(initiator);
expect(loggedIn).toEqual(true);
const profileName = await chainweaverApp.createProfile(initiator);
expect(profileName).toBeTruthy();

await expect(
initiator.getByRole('heading', {
name: 'Your Assets',
}),
).toBeVisible();

const loggedOut = await chainweaverApp.logout(initiator);
const loggedOut = await chainweaverApp.logout(initiator, profileName);
expect(loggedOut).toEqual(true);
});

Expand All @@ -24,3 +24,21 @@ test('Login', async ({ initiator, chainweaverApp }) => {
expect(loggedIn).toEqual(true);
});
});

test('Login with password', async ({ initiator, chainweaverApp }) => {
await test.step('create profile with a password', async () => {
await initiator.goto('/');
const profileName =
await chainweaverApp.createProfileWithPassword(initiator);
expect(profileName).toBeTruthy();

await expect(
initiator.getByRole('heading', {
name: 'Your Assets',
}),
).toBeVisible();

const loggedOut = await chainweaverApp.logout(initiator, profileName);
expect(loggedOut).toEqual(true);
});
});

0 comments on commit 824f91e

Please sign in to comment.