Skip to content

Commit cae0950

Browse files
Merge pull request #238 from nesrineabdmouleh/AddFilterProductMethodIn173Version
Add filter product method in 173
2 parents 65c1378 + 2e4c56a commit cae0950

File tree

2 files changed

+57
-2
lines changed
  • src/versions
    • 1.7.3/pages/BO/catalog/products
    • develop/pages/BO/catalog/products

2 files changed

+57
-2
lines changed

src/versions/1.7.3/pages/BO/catalog/products/index.ts

+56
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Import pages
22
import type {BOProductsPageInterface} from '@interfaces/BO/catalog/products';
33
import {ProductsPage} from '@versions/1.7.5/pages/BO/catalog/products';
4+
import {type ProductFilterMinMax} from '@data/types/product';
5+
import {type Page} from '@playwright/test';
46

57
/**
68
* Bo products page, contains functions that can be used on the page
@@ -28,6 +30,60 @@ class BOProductsVersion extends ProductsPage implements BOProductsPageInterface
2830
// Bulk actions
2931
this.selectAllProductsCheckbox = '#bulk_action_select_all';
3032
}
33+
34+
/**
35+
* Filter products
36+
* @param page {Page} Browser tab
37+
* @param filterBy {string} Column to filter
38+
* @param value {string|ProductFilterMinMax} Value to put on filter
39+
* @param filterType {string} Input or select to choose method of filter
40+
* @return {Promise<void>}
41+
*/
42+
async filterProducts(page: Page, filterBy: string, value: string | ProductFilterMinMax = '', filterType: string = 'input')
43+
: Promise<void> {
44+
switch (filterType) {
45+
case 'input':
46+
if (typeof value === 'string') {
47+
switch (filterBy) {
48+
case 'product_name':
49+
await page.locator(this.productFilterNameInput).fill(value);
50+
break;
51+
case 'reference':
52+
await page.locator(this.productFilterReferenceInput).fill(value);
53+
break;
54+
case 'category':
55+
await page.locator(this.productFilterCategoryInput).fill(value);
56+
break;
57+
case 'position':
58+
await this.setValue(page, this.productFilterPositionInput, value);
59+
break;
60+
default:
61+
}
62+
} else {
63+
switch (filterBy) {
64+
case 'id_product':
65+
await this.filterProductsByID(page, value.min, value.max);
66+
break;
67+
case 'price':
68+
await this.filterProductsByPrice(page, value.min, value.max);
69+
break;
70+
case 'quantity':
71+
await this.filterProductsByQuantity(page, value.min, value.max);
72+
break;
73+
default:
74+
}
75+
}
76+
break;
77+
case 'select':
78+
await this.selectByVisibleText(page, this.productFilterSelectStatus, typeof value === 'string' ? value : 'No');
79+
break;
80+
default:
81+
// Do nothing
82+
}
83+
// click on search
84+
await page.mouse.click(100, 100);
85+
await this.clickAndWaitForLoadState(page, this.filterSearchButton, 'networkidle', 10000);
86+
}
3187
}
3288

3389
const productsPage = new BOProductsVersion();

src/versions/develop/pages/BO/catalog/products/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class ProductsPage extends BOBasePage implements BOProductsPageInterface {
122122

123123
protected productFilterSelectStatus: string;
124124

125-
private readonly productFilterPositionInput: string;
125+
protected productFilterPositionInput: string;
126126

127127
protected productRow: string;
128128

@@ -765,7 +765,6 @@ class ProductsPage extends BOBasePage implements BOProductsPageInterface {
765765
// Do nothing
766766
}
767767
// click on search
768-
await page.mouse.click(100, 100);
769768
await this.clickAndWaitForLoadState(page, this.filterSearchButton, 'networkidle', 10000);
770769
}
771770

0 commit comments

Comments
 (0)