Skip to content

Commit

Permalink
Complete the test script
Browse files Browse the repository at this point in the history
  • Loading branch information
nesrineabdmouleh committed Dec 16, 2022
1 parent c576e85 commit dd8e009
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 19 deletions.
64 changes: 60 additions & 4 deletions tests/UI/campaigns/productV2/functional/01_filterProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
},
].forEach((test) => {
it(`should filter list by '${test.args.filterBy}' min upper than max and check error message`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterByIDMinMax', baseContext);
await testContext.addContextItem(this, 'testIdentifier', test.args.identifier, baseContext);

await productsPage.filterProducts(page, test.args.filterBy, test.args.filterValue, test.args.filterType);

Expand Down Expand Up @@ -211,24 +211,80 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
await expect(textColumn).to.equal('warning No records found');
});

it('should reset filter', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilterByStatus', baseContext);

const numberOfProductsAfterReset = await productsPage.resetAndGetNumberOfLines(page);
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});

it('should filter by category \'Home\'', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterByCategories', baseContext);

await productsPage.filterProductsByCategory(page, 'Home');

const numberOfProductsAfterFilter = await productsPage.getNumberOfProductsFromList(page);
await expect(numberOfProductsAfterFilter).to.be.below(numberOfProducts);
await expect(numberOfProductsAfterFilter).to.equal(numberOfProducts);
});

it('should check if the \'Clear filter\' link is visible', async function(){
it('should check the filter by category button name', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkFilterButtonName', baseContext);

const filterButtonName = await productsPage.getFilterByCategoryButtonName(page);
await expect(filterButtonName).to.equal('Filter by categories (Home)');
});

it('should check that the \'Clear filter\' link is visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkClearFilterLink', baseContext);

const isVisible = await productsPage.isClearFilterLinkVisible(page);
await expect(isVisible).to.be.true;
});

it('should check if the new column \'Position\' is visible', async function(){
it('should check that the new column \'Position\' is visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkPositionColumn', baseContext);

const isVisible = await productsPage.isPositionColumnVisible(page);
await expect(isVisible).to.be.true;
});

it('should filter list by \'Position\' and check result', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterByPosition', baseContext);

await productsPage.filterProducts(page, 'position', 1, 'input');

const textColumn = await productsPage.getTextColumn(page, 'position');
await expect(textColumn).to.equal(1);
});

it('should reset filter', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilterByPosition', baseContext);

const numberOfProductsAfterReset = await productsPage.resetAndGetNumberOfLines(page);
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});

it('should click on \'Clear filter\' button', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnClearFilterButton', baseContext);

await productsPage.clickOnClearFilterLink(page);

const numberOfProductsAfterReset = await productsPage.resetAndGetNumberOfLines(page);
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});

it('should check that the \'Clear filter\' link is not visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkClearFilterLinkNotVisible', baseContext);

const isVisible = await productsPage.isClearFilterLinkVisible(page);
await expect(isVisible).to.be.false;
});

it('should check that the new column \'Position\' is not visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkPositionColumnNotVisible', baseContext);

const isVisible = await productsPage.isPositionColumnVisible(page);
await expect(isVisible).to.be.false;
});
});

Expand Down
61 changes: 46 additions & 15 deletions tests/UI/pages/BO/catalog/productsV2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ class Products extends BOBasePage {
this.productGridPanel = '#product_grid_panel';
this.productGridHeader = `${this.productGridPanel} div.js-grid-header`;
this.headerTitle = `${this.productGridHeader} .card-header-title`;
this.productGrid = '#product_grid';

// Filter by categories
this.treeCategoriesBloc = '#tree-categories';
this.filterByCategoriesButton = '#product_catalog_category_tree_filter button';
this.filterByCategoriesExpandButton = `${this.treeCategoriesBloc} a#product_catalog_category_tree_filter_expand`;
this.filterByCategoriesUnselectButton = `${this.treeCategoriesBloc} a#product_catalog_category_tree_filter_reset`;
this.filterByCategoriesCategoryLabel = `${this.treeCategoriesBloc} label.category-label`;
this.filterByCategoryBlock = `${this.productGrid} form.d-inline-block`;
this.filterByCategoriesButton = `${this.filterByCategoryBlock} div button.dropdown-toggle`;
this.filterByCategoriesExpandButton = `${this.filterByCategoryBlock} div button.category_tree_filter_expand`;
this.filterByCategoriesUnselectButton = `${this.filterByCategoryBlock} div button.category_tree_filter_reset.btn`;
this.filterByCategoriesLabel = '#category_filter ul.category-tree li div.category-label';
this.clearFilterButton = `${this.filterByCategoryBlock} button.btn-link.category_tree_filter_reset`;

// Bulk actions selectors
this.productBulkMenuButton = `${this.productGridPanel} button.js-bulk-actions-btn`;
Expand All @@ -63,7 +65,7 @@ class Products extends BOBasePage {
this.productFilterQuantityMinInput = '#product_quantity_min_field';
this.productFilterQuantityMaxInput = '#product_quantity_max_field';
this.productFilterSelectStatus = '#product_active';
this.productFilterSelectStatus = '#product_active';
this.productFilterPositionInput = '#product_position';

// Products list
this.productRow = `${this.productGridTable} tbody tr`;
Expand All @@ -78,7 +80,8 @@ class Products extends BOBasePage {
this.productsListTableColumnPriceATI = (row) => `${this.productsListTableRow(row)} `
+ 'td.column-price_tax_included';
this.productsListTableColumnQuantity = (row) => `${this.productsListTableRow(row)} td.column-quantity a`;
this.productsListTableColumnStatusInput = (row) => `${this.productsListTableRow(row)} td.column-active input`;
this.productsListTableColumnStatus = (row) => `${this.productsListTableRow(row)} td.column-active input`;
this.productsListTableColumnPosition = (row) => `${this.productsListTableRow(row)} td.column-position`;
this.productListTableDropDownList = (row) => `${this.productsListTableRow(row)} td.column-actions `
+ 'a.dropdown-toggle';
this.productListTableDeleteButton = (row) => `${this.productsListTableRow(row)}`
Expand Down Expand Up @@ -264,7 +267,7 @@ class Products extends BOBasePage {
await page.click(this.filterByCategoriesExpandButton);

// Choose category to filter with
const args = {allCategoriesSelector: this.filterByCategoriesCategoryLabel, val: categoryName};
const args = {allCategoriesSelector: this.filterByCategoriesLabel, val: categoryName};
// eslint-disable-next-line no-eval
const fn = eval(`({
async categoryClick(args) {
Expand All @@ -284,7 +287,16 @@ class Products extends BOBasePage {
if (!found) {
throw new Error(`${categoryName} not found as a category`);
}
await page.waitForNavigation();
await page.waitForNavigation('networkidle');
}

/**
* Get filter by categories button name
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
getFilterByCategoryButtonName(page) {
return this.getTextContent(page, this.filterByCategoriesButton);
}

/**
Expand All @@ -308,11 +320,25 @@ class Products extends BOBasePage {
* @returns {Promise<boolean>}
*/
isClearFilterLinkVisible(page) {
return this.elementVisible(page, '#product_catalog_category_tree_filter > button.btn.btn-link');
return this.elementVisible(page, this.clearFilterButton, 2000);
}

/**
* Click on clear filter link
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async clickOnClearFilterLink(page) {
await this.clickAndWaitForNavigation(page, this.clearFilterButton);
}

isPositionColumnVisible(page){
return this.elementVisible(page, '#product_catalog_category_tree_filter > button.btn.btn-link');
/**
* Is position column visible
* @param page {Page} Browser tab
* @returns {Promise<boolean>}
*/
isPositionColumnVisible(page) {
return this.elementVisible(page, this.productFilterPositionInput);
}

/**
Expand Down Expand Up @@ -355,7 +381,7 @@ class Products extends BOBasePage {
* Filter products
* @param page {Page} Browser tab
* @param filterBy {string} Column to filter
* @param value {{min: number, max:number}|string|boolean} Value to put on filter
* @param value {{min: number, max:number}|string|boolean|number} Value to put on filter
* @param filterType {string} Input or select to choose method of filter
* @return {Promise<void>}
*/
Expand All @@ -381,6 +407,9 @@ class Products extends BOBasePage {
case 'quantity':
await this.filterProductsByQuantity(page, value.min, value.max);
break;
case 'position':
await this.setValue(page, this.productFilterPositionInput, value);
break;
default:
}
break;
Expand Down Expand Up @@ -459,7 +488,7 @@ class Products extends BOBasePage {
async getProductStatusFromList(page, row) {
const inputValue = await this.getAttributeContent(
page,
`${this.productsListTableColumnStatusInput(row)}[checked]`,
`${this.productsListTableColumnStatus(row)}[checked]`,
'value',
);

Expand All @@ -473,7 +502,7 @@ class Products extends BOBasePage {
* @param row {number} Row on table
* @returns {Promise<string|number>}
*/
async getTextColumn(page, columnName, row) {
async getTextColumn(page, columnName, row = 1) {
switch (columnName) {
case 'id_product':
return this.getNumberFromText(page, this.productsListTableColumnID(row));
Expand All @@ -489,6 +518,8 @@ class Products extends BOBasePage {
return this.getNumberFromText(page, this.productsListTableColumnQuantity(row));
case 'active':
return this.getProductStatusFromList(page, row);
case 'position':
return this.getNumberFromText(page, this.productsListTableColumnPosition(row));
default:
// Do nothing
}
Expand Down

0 comments on commit dd8e009

Please sign in to comment.