Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
nesrineabdmouleh committed Dec 19, 2022
1 parent 5402818 commit 7abc46b
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions tests/UI/campaigns/productV2/functional/01_filterProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import productsPage from '@pages/BO/catalog/productsV2';
import {Products} from '@data/demo/products';
import {Categories} from '@data/demo/categories';

const baseContext = 'productV2_functional_filterProducts';
const baseContext: string = 'productV2_functional_filterProducts';

describe('BO - Catalog - Products : Filter in Products Page', async () => {
let browserContext: BrowserContext;
Expand Down Expand Up @@ -52,14 +52,14 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
dashboardPage.productsLink,
);

const pageTitle = await productsPage.getPageTitle(page);
const pageTitle: string = await productsPage.getPageTitle(page);
await expect(pageTitle).to.contains(productsPage.pageTitle);
});

it('should check that no filter is applied by default', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNoFilter', baseContext);

const isVisible = await productsPage.isResetButtonVisible(page);
const isVisible: boolean = await productsPage.isResetButtonVisible(page);
await expect(isVisible, 'Reset button is visible!').to.be.false;
});

Expand Down Expand Up @@ -104,7 +104,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

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

const textMessage = await productsPage.getAlertDangerBlockContent(page);
const textMessage: string = await productsPage.getAlertDangerBlockContent(page);
await expect(textMessage).to.equal(test.args.alertDanger);
});
});
Expand All @@ -116,6 +116,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
filterBy: 'id_product',
filterValue: {min: 5, max: 10},
filterType: 'input',
comparisonType: 'toWithinMinMax',
},
},
{
Expand Down Expand Up @@ -148,6 +149,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
filterBy: 'price',
filterValue: {min: 5, max: 10},
filterType: 'input',
comparisonType: 'toWithinMinMax',
},
},
{
Expand All @@ -156,6 +158,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
filterBy: 'quantity',
filterValue: {min: 100, max: 1000},
filterType: 'input',
comparisonType: 'toWithinMinMax',
},
},
{
Expand All @@ -164,6 +167,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
filterBy: 'active',
filterValue: 'Yes',
filterType: 'select',
comparisonType: 'toBeTrue',
},
},
].forEach((test) => {
Expand All @@ -172,7 +176,7 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

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

const numberOfProductsAfterFilter = await productsPage.getNumberOfProductsFromList(page);
const numberOfProductsAfterFilter: number = await productsPage.getNumberOfProductsFromList(page);

if (test.args.filterBy === 'active') {
await expect(numberOfProductsAfterFilter).to.be.above(0);
Expand All @@ -181,23 +185,27 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {
}

for (let i = 1; i <= numberOfProductsAfterFilter; i++) {
const textColumn = await productsPage.getTextColumn(page, test.args.filterBy, i);

if (test.args.filterBy === 'id_product' || test.args.filterBy === 'price'
|| test.args.filterBy === 'quantity') {
await expect(textColumn).to.within(test.args.filterValue.min, test.args.filterValue.max);
} else if (test.args.filterBy === 'active' && test.args.filterValue === 'Yes') {
await expect(textColumn).to.be.true;
} else {
await expect(textColumn).to.be.contain(test.args.filterValue);
const textColumn: string|number = await productsPage.getTextColumn(page, test.args.filterBy, i);

switch (test.args.comparisonType) {
case 'toWithinMinMax':
await expect(textColumn).to.within(test.args.filterValue.min, test.args.filterValue.max);
break;

case 'toBeTrue':
await expect(textColumn).to.be.true;
break;

default:
await expect(textColumn).to.contain(test.args.filterValue);
}
}
});

it('should reset filter', async function () {
await testContext.addContextItem(this, 'testIdentifier', `resetAfter${test.args.identifier}`, baseContext);

const numberOfProductsAfterReset = await productsPage.resetAndGetNumberOfLines(page);
const numberOfProductsAfterReset: number = await productsPage.resetAndGetNumberOfLines(page);
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});
});
Expand All @@ -207,14 +215,14 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

await productsPage.filterProducts(page, 'active', false, 'select');

const textColumn = await productsPage.getTextForEmptyTable(page);
const textColumn: string = await productsPage.getTextForEmptyTable(page);
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);
const numberOfProductsAfterReset: number = await productsPage.resetAndGetNumberOfLines(page);
await expect(numberOfProductsAfterReset).to.equal(numberOfProducts);
});
});
Expand All @@ -225,28 +233,28 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

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

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

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

const filterButtonName = await productsPage.getFilterByCategoryButtonName(page);
const filterButtonName: string = 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);
const isVisible: boolean = await productsPage.isClearFilterLinkVisible(page);
await expect(isVisible).to.be.true;
});

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);
const isVisible: boolean = await productsPage.isPositionColumnVisible(page);
await expect(isVisible).to.be.true;
});

Expand All @@ -255,14 +263,14 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

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

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

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

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

Expand All @@ -271,21 +279,21 @@ describe('BO - Catalog - Products : Filter in Products Page', async () => {

await productsPage.clickOnClearFilterLink(page);

const numberOfProductsAfterReset = await productsPage.resetAndGetNumberOfLines(page);
const numberOfProductsAfterReset: number = 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);
const isVisible: boolean = 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);
const isVisible: boolean = await productsPage.isPositionColumnVisible(page);
await expect(isVisible).to.be.false;
});
});
Expand Down

0 comments on commit 7abc46b

Please sign in to comment.