Skip to content

Commit

Permalink
Add some mocking to make UI behaviour easier to control.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain89 committed Oct 9, 2023
1 parent 7c1d628 commit 06132b9
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
name: E2E - Tools
runs-on: ubuntu-latest
timeout-minutes: 10
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

steps:
- uses: actions/checkout@v4
with:
Expand Down
12 changes: 0 additions & 12 deletions packages/apps/tools/e2e-tests/example.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/apps/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lint:src": "eslint src --ext .ts,.tsx",
"start": "next start",
"test": "jest --silent",
"test:e2e": "npx playwright test"
"test:e2e": "npx playwright test --ui"
},
"dependencies": {
"@hookform/resolvers": "~3.1.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/apps/tools/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { defineConfig } from "@playwright/test";
export default defineConfig({
...defaultConfig,
use: {
baseURL: "https://tools.kadena.io",
...defaultConfig.use,
trace: 'retain-on-failure'
},
webServer: {
...defaultConfig.webServer
},
expect: {
...defaultConfig.expect
}
});
21 changes: 21 additions & 0 deletions packages/apps/tools/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from './page-objects';
import {expect} from '@playwright/test'
import {accountsData} from './fixtures/data/accounts';
import { send } from './fixtures/mocks/send'
import { pollFinished, pollInProgress } from './fixtures/mocks/poll';

test('Fund account using the faucet @mocks', async ({ page, home, faucet , mockHelper}) => {

await page.goto('/');
await home.header.setNetwork("Testnet")
await home.header.goTo('Faucet')

await mockHelper.mockResponse('**/send', send)
await faucet.fundAccount(accountsData.publicKey, "0")


await mockHelper.mockResponse('**/poll', pollInProgress)
await expect(await faucet.notification.getTitle()).toHaveText('Transaction is being processed...')
await mockHelper.mockResponse('**/poll', pollFinished)
await expect(await faucet.notification.getTitle()).toHaveText('Transaction successfully completed')
});
48 changes: 48 additions & 0 deletions packages/apps/tools/tests/fixtures/mocks/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const pollInProgress = {}
export const pollFinished = {
"rNk4ePNVlJGwjCaVrjKFJbh3A0agpcZq6gYLfivOHYg": {
"gas": 940,
"result": {
"status": "success",
"data": "Write succeeded"
},
"reqKey": "rNk4ePNVlJGwjCaVrjKFJbh3A0agpcZq6gYLfivOHYg",
"logs": "GXRNaJAVVqBrZA05zJ1B66VRzos09z-s9M9LQAXdkvY",
"events": [
{
"params": [
"faucet-operation",
"k:db776793be0fcf8e76c75bdb35a36e67f298111dc6145c66693b0133192e2616",
9.4e-6
],
"name": "TRANSFER",
"module": {
"namespace": null,
"name": "coin"
},
"moduleHash": "rE7DU8jlQL9x_MPYuniZJf5ICBTAEHAIFQCB4blofP4"
},
{
"params": [
"coin-faucet",
"938c8ec66283493844c205481f220cfbd7024bda5859c7897141f6a5c6fc52c1",
100
],
"name": "TRANSFER",
"module": {
"namespace": null,
"name": "coin"
},
"moduleHash": "rE7DU8jlQL9x_MPYuniZJf5ICBTAEHAIFQCB4blofP4"
}
],
"metaData": {
"blockTime": 1696849672176432,
"prevBlockHash": "FxZHHgag5dS7f3hyNDVnTmeVOZZkdGtyvnqbkKspzVw",
"blockHash": "VnK4519k7MtweHWj9lENGQuIX_3plQj67LNAhgBljSc",
"blockHeight": 3672752
},
"continuation": null,
"txId": 3753319
}
}
1 change: 1 addition & 0 deletions packages/apps/tools/tests/fixtures/mocks/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const send = {"requestKeys":["rNk4ePNVlJGwjCaVrjKFJbh3A0agpcZq6gYLfivOHYg"]}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import FaucetPage from './pages/faucet.page';
import HomePage from './pages/home.page';
import TransactionsPage from './pages/transactions.page';
import AccountPage from './pages/account.page';
import MockHelper from '@kadena/e2e-components/helpers/mock.helper'

export const test = baseTest.extend<{
home: HomePage
transactions: TransactionsPage
faucet: FaucetPage;
account: AccountPage
mockHelper: MockHelper
}>({
home: async ({ page }, use) => {
await use(new HomePage(page));
Expand All @@ -22,4 +24,8 @@ export const test = baseTest.extend<{
account: async ({ page }, use) => {
await use(new AccountPage(page));
},

mockHelper: async ({ page }, use) => {
await use(new MockHelper(page));
},
});
File renamed without changes.
16 changes: 16 additions & 0 deletions packages/tools/e2e-components/helpers/mock.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Page } from '@playwright/test';

export default class MockHelper {
private readonly _page: Page;
public constructor(page: Page) {
this._page = page;
}

async mockResponse(uri: string|RegExp, response: object ): Promise<void> {
await this._page.route(uri, async (route) => {
const json = response;
await route.fulfill({ json });
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ export default class NotificationContainerComponent {

public constructor(page: Page) {
this._page = page;
this._componentLocator = this._page.getByTestId("kda-notification-container");
this._componentLocator = this._page.getByRole("alert");
}

async getTitle(): Promise<Locator> {
return this._componentLocator.getByRole('heading')
}

async getMessage(): Promise<Locator> {
return this._componentLocator.getByTestId('kda-notification-content')
return this._componentLocator.getByRole('generic')
}

async close(label: string): Promise<void> {
async close(): Promise<void> {
await this._page.getByRole('button', {name: 'Close Notification'}).click()
}

Expand Down
7 changes: 4 additions & 3 deletions packages/tools/heft-rig/playwright.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* See https://playwright.dev/docs/test-configuration.
*/
export const defaultConfig = {
testDir: 'e2e-tests',
testDir: 'tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
Expand All @@ -25,7 +25,8 @@ export const defaultConfig = {
command: 'pnpm run start',
url: 'http://127.0.0.1:3000',
reuseExistingServer: false,
stdout: 'ignore',
stderr: 'pipe',
},
expect: {
timeout: 10 * 1000,
},
};

0 comments on commit 06132b9

Please sign in to comment.