|
1 | 1 | // Import pages
|
2 | 2 | import type {BOProductsPageInterface} from '@interfaces/BO/catalog/products';
|
3 | 3 | 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'; |
4 | 6 |
|
5 | 7 | /**
|
6 | 8 | * Bo products page, contains functions that can be used on the page
|
@@ -28,6 +30,60 @@ class BOProductsVersion extends ProductsPage implements BOProductsPageInterface
|
28 | 30 | // Bulk actions
|
29 | 31 | this.selectAllProductsCheckbox = '#bulk_action_select_all';
|
30 | 32 | }
|
| 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 | + } |
31 | 87 | }
|
32 | 88 |
|
33 | 89 | const productsPage = new BOProductsVersion();
|
|
0 commit comments