Skip to content

Commit

Permalink
refactored fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mmitiche committed Oct 30, 2024
1 parent dd0e45b commit 389aef4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {SearchObject} from '../../../../../../playwright/page-object/search-obje

type QuanticPagerE2EFixtures = {
pager: PagerObject;
search: SearchObject;
};

export const testSearch = quanticBase.extend<QuanticPagerE2EFixtures>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
useCaseTestCases,
useCaseEnum,
} from '../../../../../../playwright/utils/use-case';
import {InsightObject} from '../../../../../../playwright/page-object/insight-object';
import {InsightSetupObject} from '../../../../../../playwright/page-object/insight-setup-object';
import {ConfigurationObject} from '../../../../../../playwright/page-object/configuration-object';

interface PageObjects {
configuration: ConfigurationObject;
search: SearchObject;
insight?: InsightObject;
insightSetup?: InsightSetupObject;
}

interface PagerOptions {
Expand All @@ -21,14 +21,14 @@ interface PagerOptions {

async function visitPage(
page: Page,
{search, insight, configuration}: PageObjects,
{search, insightSetup, configuration}: PageObjects,
options: Partial<PagerOptions> = {}
) {
const pageUrl = 's/quantic-pager';
await page.goto(pageUrl);
configuration.configure(options);
if (options.useCase === useCaseEnum.insight) {
await insight?.waitForInsightInterfaceInitialization();
await insightSetup?.waitForInsightInterfaceInitialization();
await search.interceptSearchAndLimitResultPages(5);
await search.performSearch();
await search.waitForSearchResponse();
Expand All @@ -51,15 +51,15 @@ async function visitPageAndloadOptionsFromUrl(

async function setupWithPauseBeforeSearch(
page: Page,
{search, insight, configuration}: PageObjects,
{search, insightSetup, configuration}: PageObjects,
options: Partial<PagerOptions> = {}
) {
const pageUrl = 's/quantic-pager';
await page.goto(pageUrl);

if (options.useCase === useCaseEnum.insight) {
configuration.configure(options);
await insight?.waitForInsightInterfaceInitialization();
await insightSetup?.waitForInsightInterfaceInitialization();
const stalledRequest = search.interceptSearchIndefinitely();
await search.performSearch();
return stalledRequest;
Expand All @@ -78,10 +78,10 @@ useCaseTestCases.forEach((useCase) => {
let test = fixtures[useCase.value];

test.describe(`quantic pager ${useCase.label}`, () => {
test.beforeEach(async ({page, search, insight, configuration}) => {
test.beforeEach(async ({page, search, insightSetup, configuration}) => {
await visitPage(
page,
{search, insight, configuration},
{search, insightSetup, configuration},
{useCase: useCase.value}
);
});
Expand All @@ -90,13 +90,13 @@ useCaseTestCases.forEach((useCase) => {
test('should display the pager only after the search request has been completed', async ({
page,
search,
insight,
insightSetup,
pager,
configuration,
}) => {
const resumeSearchRequest = await setupWithPauseBeforeSearch(
page,
{search, insight, configuration},
{search, insightSetup, configuration},
{useCase: useCase.value}
);

Expand Down
13 changes: 4 additions & 9 deletions packages/quantic/playwright/fixtures/base-fixture.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import {test as base} from '@playwright/test';
import {SearchObject} from '../page-object/search-object';
import {InsightObject} from '../page-object/insight-object';
import {InsightSetupObject} from '../page-object/insight-setup-object';
import {ConfigurationObject} from '../page-object/configuration-object';

type QuanticBaseE2EFixtures = {
configuration: ConfigurationObject;
search: SearchObject;
insight?: InsightObject;
insightSetup?: InsightSetupObject;
};

export const quanticBase = base.extend<QuanticBaseE2EFixtures>({
configuration: async ({page}, use) => {
await use(new ConfigurationObject(page));
},
search: async ({page}, use) => {
await use(new SearchObject(page, 'search'));
},
insight: async ({page}, use) => {
await use(new InsightObject(page));
insightSetup: async ({page}, use) => {
await use(new InsightSetupObject(page));
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Page, expect} from '@playwright/test';

export class InsightObject {
export class InsightSetupObject {
constructor(private page: Page) {
this.page = page;
}
Expand Down

0 comments on commit 389aef4

Please sign in to comment.