Skip to content

Commit

Permalink
@ops/BO/catalog/product : Added first commonTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed May 2, 2024
1 parent ed33f4b commit 3c1ea79
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export {default as FakerTaxRule} from '@data/faker/taxRule';
export {default as FakerTitle} from '@data/faker/title';
export {default as FakerZone} from '@data/faker/zone';

// Export common
export {default as opsBOCatalogProduct} from '@ops/BO/catalog/product'

Check failure on line 54 in src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

Missing semicolon

// Export Pages
export * as CommonPage from '@pages/commonPage';
// Export Pages BO
Expand Down
225 changes: 225 additions & 0 deletions src/ops/BO/catalog/product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
import test, { Page, expect } from '@playwright/test';
import FakerProduct from '@data/faker/product';
import boProductsPage from '@pages/BO/catalog/products';
import boProductsCreatePage from '@pages/BO/catalog/products/create';
import boDashboardPage from '@pages/BO/dashboard';
import boLoginPage from '@pages/BO/login';
import utilsTest from '@utils/test';

let numberOfProducts: number;

export default {
/**
* Function to create standard product
* @param page {Page}
* @param productData {FakerProduct} Data to set to create product
* @param baseContext {string} String to identify the test
*/
async createProduct(page: Page, productData: FakerProduct, baseContext: string = 'commonTests-createProduct'): Promise<void> {
test('should login in BO', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

await boLoginPage.goTo(page, global.BO.URL);
await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD);

const pageTitle = await boDashboardPage.getPageTitle(page);
expect(pageTitle).toContain(boDashboardPage.pageTitle);
});

test('should go to \'Catalog > Products\' page', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPage', baseContext);

await boDashboardPage.goToSubMenu(page, boDashboardPage.catalogParentLink, boDashboardPage.productsLink);
await boProductsPage.closeSfToolBar(page);

const pageTitle = await boProductsPage.getPageTitle(page);
expect(pageTitle).toContain(boProductsPage.pageTitle);
});

test('should click on \'New product\' button and check new product modal', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnNewProductButton', baseContext);

const isModalVisible = await boProductsPage.clickOnNewProductButton(page);
expect(isModalVisible).toBeTruthy();
});

test(`should choose '${productData.type} product' and go to new product page`, async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'chooseTypeOfProduct', baseContext);

await boProductsPage.selectProductType(page, productData.type);
await boProductsPage.clickOnAddNewProduct(page);
await boProductsCreatePage.closeSfToolBar(page);

const pageTitle = await boProductsCreatePage.getPageTitle(page);
expect(pageTitle).toContain(boProductsCreatePage.pageTitle);
});

test('should create product', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'createStandardProduct', baseContext);

const createProductMessage = await boProductsCreatePage.setProduct(page, productData);
expect(createProductMessage).toEqual(boProductsCreatePage.successfulUpdateMessage);
});

test('should logout', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);

await boProductsCreatePage.logoutBO(page);

const pageTitle = await boLoginPage.getPageTitle(page);
expect(pageTitle).toContain(boLoginPage.pageTitle);
});
},

/**
* Function to delete product
* @param page {Page}
* @param productData {FakerProduct} Data to set to delete product
* @param baseContext {string} String to identify the test
*/
async deleteProduct(page: Page, productData: FakerProduct, baseContext: string = 'commonTests-deleteProduct'): Promise<void> {
test('should login in BO', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

await boLoginPage.goTo(page, global.BO.URL);
await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD);

const pageTitle = await boDashboardPage.getPageTitle(page);
expect(pageTitle).toContain(boDashboardPage.pageTitle);
});

test('should go to \'Catalog > Products\' page', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPageToDelete', baseContext);

await boDashboardPage.goToSubMenu(page, boDashboardPage.catalogParentLink, boDashboardPage.productsLink);

const pageTitle = await boProductsPage.getPageTitle(page);
expect(pageTitle).toContain(boProductsPage.pageTitle);
});

test('should reset all filters', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'resetFilters', baseContext);

await boProductsPage.resetFilter(page);

const numberOfProducts = await boProductsPage.resetAndGetNumberOfLines(page);
expect(numberOfProducts).toBeGreaterThan(0);
});

test('should click on delete product button', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnDeleteProduct', baseContext);

const isModalVisible: boolean = await boProductsPage.clickOnDeleteProductButton(page);
expect(isModalVisible).toBeTruthy();
});

test('should delete product', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'deleteProduct', baseContext);

const textMessage: string = await boProductsPage.clickOnConfirmDialogButton(page);
expect(textMessage).toEqual(boProductsPage.successfulDeleteMessage);
});

test('should reset filter', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'resetFilter', baseContext);

const numberOfProductsAfterReset: number = await boProductsPage.resetAndGetNumberOfLines(page);
expect(numberOfProductsAfterReset).toBeGreaterThan(0);
});
},

/**
* Function to bulk delete product
* @param productName {string} Value to set on product name input
* @param baseContext {string} String to identify the test
*/
/*
function bulkDeleteProductsTest(productName: string, baseContext: string = 'commonTests-bulkDeleteProductsTest'): void {
describe('POST-TEST: Bulk delete created products', async () => {
let numberOfProductsAfterFilter: number;
// before and after functions
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});
after(async () => {
await helper.closeBrowserContext(browserContext);
});
test('should login in BO', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);
await boLoginPage.goTo(page, global.BO.URL);
await boLoginPage.successLogin(page, global.BO.EMAIL, global.BO.PASSWD);
const pageTitle = await boDashboardPage.getPageTitle(page);
expect(pageTitle).toContain(boDashboardPage.pageTitle);
});
test('should go to \'Catalog > Products\' page', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'goToProductsPageToBulkDelete', baseContext);
await dashboardPage.goToSubMenu(page, dashboardPage.catalogParentLink, dashboardPage.productsLink);
const pageTitle = await productsPage.getPageTitle(page);
expect(pageTitle).to.contains(productsPage.pageTitle);
});
test('should reset filter and get number of products', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'getNumberOfProduct', baseContext);
numberOfProducts = await productsPage.resetAndGetNumberOfLines(page);
expect(numberOfProducts).to.be.above(0);
});
test('should filter list by \'Name\' and check result', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'filterListByReference', baseContext);
await productsPage.filterProducts(page, 'product_name', productName, 'input');
numberOfProductsAfterFilter = await productsPage.getNumberOfProductsFromList(page);
const textColumn = await productsPage.getTextColumn(page, 'product_name', 1);
expect(textColumn).to.contains(productName);
});
test('should select the products', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'selectProducts', baseContext);
const isBulkDeleteButtonEnabled = await productsPage.bulkSelectProducts(page);
expect(isBulkDeleteButtonEnabled).to.be.eq(true);
});
test('should click on bulk actions button', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'clickOnBulkActionsButton', baseContext);
const textMessage = await productsPage.clickOnBulkActionsProducts(page, 'delete');
expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} products`);
});
test('should bulk delete products', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'bulkDeleteProducts', baseContext);
const textMessage = await productsPage.bulkActionsProduct(page, 'delete');
expect(textMessage).to.equal(`Deleting ${numberOfProductsAfterFilter} / ${numberOfProductsAfterFilter} products`);
});
test('should close progress modal', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'closeDeleteProgressModal', baseContext);
const isModalVisible = await productsPage.closeBulkActionsProgressModal(page, 'delete');
expect(isModalVisible).to.be.eq(true);
});
test('should reset filter and get number of products', async function () {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'checkNumberOfProduct', baseContext);
const numberOfProductAfterBulkActions = await productsPage.resetAndGetNumberOfLines(page);
expect(numberOfProductAfterBulkActions).to.be.equal(numberOfProducts - numberOfProductsAfterFilter);
});
});
}*/

};
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"@interfaces/*": [
"src/interfaces/*"
],
"@ops/*": [
"src/ops/*"
],
"@pages/*": [
"src/pages/*"
],
Expand Down

0 comments on commit 3c1ea79

Please sign in to comment.