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

Use playwright mocks in Transactions e2e, update e2e tags #406

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
} from '@backbase-gsa/transactions-journey/e2e-tests';
export const transactionListSandboxData: TransactionListDataType = {
size: 10,
searchExpectations: [{ term: 'pocket', count: 5 }],
searchExpectations: [{ term: 'pocket', count: 6 }],
};

export const transactionDetailSandboxData: TransactionDetailDataType = {
recipient: 'BP',
category: 'Gasoline/Fuel',
description: 'BP Global',
recipient: 'Pocket Transfer',
category: 'Entertainment',
description: 'Pocket',
status: 'BILLED',
id: '8a82815f936800030193810b891452e0',
id: '8a82802294ac68e50194ce41c66331f0',
};
2 changes: 2 additions & 0 deletions apps/golden-sample-app-e2e/fixtures/transactions.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const test = mergeTests(
// overrode default data based on environment config
detailsData: async ({ env }, use) => await use(testData[env]!.detailsData),
listData: async ({ env }, use) => await use(testData[env]!.listData),
// whether to use mocks or not
useMocks: async ({ env }, use) => await use(env === TestEnvironment.MOCKS),
// type of the user
userType: 'userWithNoContext',
});
50 changes: 50 additions & 0 deletions libs/transactions-journey/e2e-tests/fixture/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { readFileSync } from 'node:fs';

const accessControlMocks = {
success: {
'**/accessgroups/users/permissions/summary': JSON.parse(
readFileSync(
'./mock-server/mocks/golden-sample-app/accessgroups/users_permission_summary.json',
'utf-8'
)
).responses.ok.data,
'**/accessgroups/service-agreements/context': JSON.parse(
readFileSync(
'./mock-server/mocks/golden-sample-app/accessgroups/user-context_service-agreements.json',
'utf-8'
)
).responses.ok.data,
},
};
const arrangementsMocks = {
success: {
'**/productsummary/context/arrangements**': JSON.parse(
readFileSync(
'./mock-server/mocks/golden-sample-app/productsummary/context_arrangements.json',
'utf-8'
)
).responses.ok.data,
},
};
const transactionsMocks = {
success: {
'**/v2/transactions': JSON.parse(
readFileSync(
'./mock-server/mocks/golden-sample-app/transactions/transactions.json',
'utf-8'
)
).responses.ok.data,
},
};

export const defaultListMocks = {
...accessControlMocks.success,
...arrangementsMocks.success,
...transactionsMocks.success,
};

export const defaultDetailsMocks = {
...accessControlMocks.success,
...arrangementsMocks.success,
...transactionsMocks.success,
};
15 changes: 13 additions & 2 deletions libs/transactions-journey/e2e-tests/fixture/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import {
TransactionListDataType,
} from '../model';
import { TransactionDetailsPage, TransactionsListPage } from '../page-object';
import { defaultDetailsMocks, defaultListMocks } from './mocks';

export const test = baseTest.extend<TransactionFixture>({
detailsPage: async ({ page, baseURL }, use) => {
const pageObject = new TransactionDetailsPage(page, { baseURL });
await use(pageObject);
},
detailsData: {} as TransactionDetailDataType, // pass default data
// expected details data, should be overridden
detailsData: {} as TransactionDetailDataType,
// mocks data, can be overridden or bypassed via "useMocks"
detailsMocks: async ({ useMocks }, use) =>
await use(useMocks ? defaultDetailsMocks : {}),

listPage: async ({ page, baseURL }, use) => {
const pageObject = new TransactionsListPage(page, { baseURL });
await use(pageObject);
},
// expected list data, should be overridden
listData: {} as TransactionListDataType,
// mocks data, can be overridden or bypassed via "useMocks"
listMocks: async ({ useMocks }, use) =>
await use(useMocks ? defaultListMocks : {}),

listData: {} as TransactionListDataType, // pass default data
useMocks: true,
});
10 changes: 8 additions & 2 deletions libs/transactions-journey/e2e-tests/model/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PlaywrightTestArgs } from '@playwright/test';
import { TransactionDetailsPage } from '../page-object/transaction-details.page';
import { TransactionsListPage } from '../page-object/transactions-list.page';

Expand All @@ -18,9 +19,14 @@ export interface TransactionDetailDataType {
id: string;
}

export interface TransactionFixture {
export type TransactionFixture = {
detailsPage: TransactionDetailsPage;
detailsData: TransactionDetailDataType;
detailsMocks: Record<string, object | string>;

listPage: TransactionsListPage;
listData: TransactionListDataType;
}
listMocks: Record<string, object | string>;

useMocks: boolean;
} & PlaywrightTestArgs;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ export function testTransactionDetails(
'Transactions details',
{ tag: ['@e2e', '@transactions', '@transactions-details'] },
() => {
test.beforeEach(async ({ detailsPage, detailsData }) => {
await detailsPage.navigate(detailsData.id);
});
test.beforeEach(
async ({ page, detailsPage, detailsData, detailsMocks }) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great.
The only thing i would consider is to move this whole code (which sets page.route) into fixture.
This way engineers will have full control when they want to override something on the app level

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Added listMocksSetup and detailsMocksSetup which can be overriden.

An example:

  // override list mocks setup
  listMocksSetup: async ({ useMocks, page }, use) => await use(() => {
    if (useMocks) {
      page.route(
        '**/accessgroups/users/permissions/summary',
        (route) => route.fulfill({ json: JSON.parse(readFileSync('./my-mocks/summary.json','utf-8')) })
      );
      page.route(
        '**/accessgroups/service-agreements/context',
        (route) => route.fulfill({ json: JSON.parse(readFileSync('./my-mocks/agreements.json', 'utf-8')) })
      );
      page.route(
        '**/productsummary/context/arrangements**',
        (route) => route.fulfill({ json: JSON.parse(readFileSync('./my-mocks/arrangements.json', 'utf-8')) })
      );
      page.route(
        '**/v2/transactions',
        (route) => route.fulfill({ json: JSON.parse(readFileSync('./my-mocks/transactions.json', 'utf-8')) })
      );
    }
  }),

for (const [endpoint, data] of Object.entries(detailsMocks ?? {})) {
page.route(endpoint, (route) => route.fulfill({ json: data }));
}
await detailsPage.navigate(detailsData.id);
}
);

test('should display correct transaction details', async ({
detailsPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export function testTransactionsList(
'Transactions list',
{ tag: ['@e2e', '@transactions', '@transactions-details'] },
() => {
test.beforeEach(async ({ listPage }) => {
test.beforeEach(async ({ page, listPage, listMocks }) => {
for (const [endpoint, data] of Object.entries(listMocks ?? {})) {
page.route(endpoint, (route) => route.fulfill({ json: data }));
}
await listPage.navigate();
});

Expand All @@ -32,7 +35,7 @@ export function testTransactionsList(
test(
'should display correct error state',
{ tag: ['@mocks-only'] },
async ({ listPage }) => {
async () => {
// Error state test placeholder
expect(true).toBe(true);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/transactions-journey/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": ["@angular/localize/init"]
"types": ["@angular/localize/init", "node"]
},
"exclude": [
"src/test-setup.ts",
Expand Down
9 changes: 1 addition & 8 deletions playwright.localhost.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,5 @@ export default defineConfig<TestOptions>({
},
},
],
webServer: [
{
command: 'npm run mock-server',
url: 'http://localhost:9999/dev-interface',
timeout: 30 * 1000,
reuseExistingServer: true,
},
],
webServer: [],
telmanagababov marked this conversation as resolved.
Show resolved Hide resolved
})