Skip to content

Commit

Permalink
test: add searchForTerm task to shop customer
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavli committed Jan 24, 2025
1 parent ad352bb commit 7be4b6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
20 changes: 6 additions & 14 deletions src/page-objects/storefront/SearchSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { PageObject } from '../../types/PageObject';
import { Home } from './Home';

export class SearchSuggest extends Home implements PageObject {

public readonly searchSuggestLineItemImages: Locator;
public readonly searchInput: Locator;
public readonly searchIcon: Locator;
Expand All @@ -19,26 +18,19 @@ export class SearchSuggest extends Home implements PageObject {
this.searchSuggestLineItemImages = page.locator('.search-suggest-product-image-container');
this.searchInput = page.locator('.header-search-input');
this.searchIcon = page.locator('.header-search-icon');
this.searchSuggestNoResult = page.locator ('.search-suggest-no-result');
this.searchSuggestLineItemName = page.locator ('.search-suggest-product-name');
this.searchSuggestLineItemPrice = page.locator ('.col-auto.search-suggest-product-price');
this.searchSuggestTotalLink = page.locator ('.search-suggest-total-link');
this.searchResultTotal = page.locator ('.search-suggest-total-count');
this.searchHeadline = page.locator ('.search-headline');
this.searchSuggestNoResult = page.locator('.search-suggest-no-result');
this.searchSuggestLineItemName = page.locator('.search-suggest-product-name');
this.searchSuggestLineItemPrice = page.locator('.col-auto.search-suggest-product-price');
this.searchSuggestTotalLink = page.locator('.search-suggest-total-link');
this.searchResultTotal = page.locator('.search-suggest-total-count');
this.searchHeadline = page.locator('.search-headline');
}

async getTotalSearchResultCount(): Promise<number> {
const totalCountText = await this.searchResultTotal.textContent();
return parseInt(totalCountText?.trim().replace(/\D/g, '') || '0', 10);
}

async searchForTerm(searchTerm: string): Promise<void> {
await this.searchInput.fill(searchTerm);
await this.page.waitForResponse((response) =>
response.url().includes(`suggest?search=${searchTerm}`) && response.ok()
);
}

url(searchTerm?: string) {
return `suggest?search=${searchTerm}`;
}
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/shop-customer-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Register } from './shop-customer/Account/Register';
import { RegisterGuest } from './shop-customer/Account/RegisterGuest';
import { ChangeStorefrontCurrency } from './shop-customer/Account/ChangeStorefrontCurrency';


import { AddProductToCart } from './shop-customer/Product/AddProductToCart';
import { ProceedFromProductToCheckout } from './shop-customer/Product/ProceedFromProductToCheckout';

Expand All @@ -22,6 +21,7 @@ import { SubmitOrder } from './shop-customer/Checkout/SubmitOrder';

import { OpenSearchResultPage } from './shop-customer/Search/OpenSearchResultPage';
import { OpenSearchSuggestPage } from './shop-customer/Search/OpenSearchSuggestPage';
import { SearchForTerm } from './shop-customer/Search/SearchForTerm';

import { ValidateAccessibility } from './shop-customer/Accessibility/ValidateAccessibility';

Expand All @@ -44,5 +44,6 @@ export const test = mergeTests(
SubmitOrder,
OpenSearchResultPage,
OpenSearchSuggestPage,
ValidateAccessibility,
);
SearchForTerm,
ValidateAccessibility
);
16 changes: 16 additions & 0 deletions src/tasks/shop-customer/Search/SearchForTerm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { test as base } from '@playwright/test';
import type { Task } from '../../../types/Task';
import type { FixtureTypes } from '../../../types/FixtureTypes';

export const SearchForTerm = base.extend<{ SearchForTerm: Task }, FixtureTypes>({
SearchForTerm: async ({ StorefrontSearchSuggest }, use) => {
const task = (searchTerm: string) => {
return async function SearchForTerm() {
await StorefrontSearchSuggest.searchInput.fill(searchTerm);
await StorefrontSearchSuggest.page.waitForResponse((response) => response.url().includes(`suggest?search=${searchTerm}`) && response.ok());
};
};

await use(task);
},
});

0 comments on commit 7be4b6f

Please sign in to comment.