-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional Tests : New products block module - Reset module
- Loading branch information
Showing
4 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
183 changes: 183 additions & 0 deletions
183
tests/UI/campaigns/modules/ps_newproducts/01_installation/04_resetModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// Import utils | ||
import helper from '@utils/helpers'; | ||
import testContext from '@utils/testContext'; | ||
|
||
// Import commonTests | ||
import loginCommon from '@commonTests/BO/loginBO'; | ||
|
||
// Import pages | ||
// Import FO pages | ||
import {homePage} from '@pages/FO/classic/home'; | ||
// Import BO pages | ||
import dashboardPage from '@pages/BO/dashboard'; | ||
import {moduleManager as moduleManagerPage} from '@pages/BO/modules/moduleManager'; | ||
import psNewProducts from '@pages/BO/modules/psNewProducts'; | ||
|
||
// Import data | ||
import Modules from '@data/demo/modules'; | ||
|
||
import {expect} from 'chai'; | ||
import type {BrowserContext, Page} from 'playwright'; | ||
|
||
const baseContext: string = 'modules_ps_newproducts_installation_resetModule'; | ||
|
||
describe('New products block module - Reset module', async () => { | ||
let browserContext: BrowserContext; | ||
let page: Page; | ||
let defaultValue: number; | ||
const numProducts: number = 10; | ||
|
||
// before and after functions | ||
before(async function () { | ||
browserContext = await helper.createBrowserContext(this.browser); | ||
page = await helper.newTab(browserContext); | ||
}); | ||
|
||
after(async () => { | ||
await helper.closeBrowserContext(browserContext); | ||
}); | ||
|
||
it('should login in BO', async function () { | ||
await loginCommon.loginBO(this, page); | ||
}); | ||
|
||
it('should go to \'Modules > Module Manager\' page', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToModuleManagerPage', baseContext); | ||
|
||
await dashboardPage.goToSubMenu( | ||
page, | ||
dashboardPage.modulesParentLink, | ||
dashboardPage.moduleManagerLink, | ||
); | ||
await moduleManagerPage.closeSfToolBar(page); | ||
|
||
const pageTitle = await moduleManagerPage.getPageTitle(page); | ||
expect(pageTitle).to.contains(moduleManagerPage.pageTitle); | ||
}); | ||
|
||
it(`should search the module ${Modules.psNewProducts.name}`, async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'searchModule', baseContext); | ||
|
||
const isModuleVisible = await moduleManagerPage.searchModule(page, Modules.psNewProducts); | ||
expect(isModuleVisible).to.eq(true); | ||
}); | ||
|
||
it('should display the reset modal and cancel it', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'resetModuleAndCancel', baseContext); | ||
|
||
const textResult = await moduleManagerPage.setActionInModule(page, Modules.psNewProducts, 'reset', true); | ||
expect(textResult).to.eq(''); | ||
|
||
const isModuleVisible = await moduleManagerPage.isModuleVisible(page, Modules.psNewProducts); | ||
expect(isModuleVisible).to.eq(true); | ||
|
||
const isModalVisible = await moduleManagerPage.isModalActionVisible(page, Modules.psNewProducts, 'reset'); | ||
expect(isModalVisible).to.eq(false); | ||
}); | ||
|
||
it(`should go to the configuration page of the module '${Modules.psNewProducts.name}'`, async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToConfigurationPage', baseContext); | ||
|
||
await moduleManagerPage.goToConfigurationPage(page, Modules.psNewProducts.tag); | ||
|
||
const pageTitle = await psNewProducts.getPageSubtitle(page); | ||
expect(pageTitle).to.eq(psNewProducts.pageSubTitle); | ||
|
||
defaultValue = parseInt(await psNewProducts.getNumProductsToDisplay(page), 10); | ||
expect(defaultValue).to.be.gt(0); | ||
}); | ||
|
||
it('should change the configuration in the module', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'changeConfiguration', baseContext); | ||
|
||
const textResult = await psNewProducts.setNumProductsToDisplay(page, numProducts); | ||
expect(textResult).to.contains(psNewProducts.updateSettingsSuccessMessage); | ||
}); | ||
|
||
it('should go to the front office', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToTheFo', baseContext); | ||
|
||
page = await psNewProducts.viewMyShop(page); | ||
await homePage.changeLanguage(page, 'en'); | ||
|
||
const isHomePage = await homePage.isHomePage(page); | ||
expect(isHomePage).to.eq(true); | ||
}); | ||
|
||
it('should check the number of products in the "New Products" block', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'changeConfiguration', baseContext); | ||
|
||
const numProductsInBlock = await homePage.getProductsBlockNumber(page, 4); | ||
expect(numProductsInBlock).to.be.equal(numProducts); | ||
}); | ||
|
||
it('should return to the back office', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'changeConfiguration', baseContext); | ||
|
||
page = await homePage.closePage(browserContext, page, 0); | ||
|
||
const pageTitle = await psNewProducts.getPageSubtitle(page); | ||
expect(pageTitle).to.eq(psNewProducts.pageSubTitle); | ||
}); | ||
|
||
it('should return to \'Modules > Module Manager\' page', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToModuleManagerPage', baseContext); | ||
|
||
await dashboardPage.goToSubMenu( | ||
page, | ||
dashboardPage.modulesParentLink, | ||
dashboardPage.moduleManagerLink, | ||
); | ||
await moduleManagerPage.closeSfToolBar(page); | ||
|
||
const pageTitle = await moduleManagerPage.getPageTitle(page); | ||
expect(pageTitle).to.contains(moduleManagerPage.pageTitle); | ||
}); | ||
|
||
it(`should search the module ${Modules.psNewProducts.name}`, async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'searchModule', baseContext); | ||
|
||
const isModuleVisible = await moduleManagerPage.searchModule(page, Modules.psNewProducts); | ||
expect(isModuleVisible).to.eq(true); | ||
}); | ||
|
||
it('should reset the module', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'resetModule', baseContext); | ||
|
||
const successMessage = await moduleManagerPage.setActionInModule(page, Modules.psNewProducts, 'reset'); | ||
expect(successMessage).to.eq(moduleManagerPage.resetModuleSuccessMessage(Modules.psNewProducts.tag)); | ||
}); | ||
|
||
it(`should go to the configuration page of the module '${Modules.psNewProducts.name}'`, async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToConfigurationPage', baseContext); | ||
|
||
await moduleManagerPage.goToConfigurationPage(page, Modules.psNewProducts.tag); | ||
|
||
const pageTitle = await psNewProducts.getPageSubtitle(page); | ||
expect(pageTitle).to.eq(psNewProducts.pageSubTitle); | ||
}); | ||
|
||
it('should check the configuration is reset', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'changeConfiguration', baseContext); | ||
|
||
const numProductsValue = await psNewProducts.getNumProductsToDisplay(page); | ||
expect(numProductsValue).to.be.equal(defaultValue.toString()); | ||
}); | ||
|
||
it('should go to the front office', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'goToTheFo', baseContext); | ||
|
||
page = await psNewProducts.viewMyShop(page); | ||
await homePage.changeLanguage(page, 'en'); | ||
|
||
const isHomePage = await homePage.isHomePage(page); | ||
expect(isHomePage).to.eq(true); | ||
}); | ||
|
||
it('should check the number of products in the "New Products" block', async function () { | ||
await testContext.addContextItem(this, 'testIdentifier', 'changeConfiguration', baseContext); | ||
|
||
const numProductsInBlock = await homePage.getProductsBlockNumber(page, 4); | ||
expect(numProductsInBlock).to.be.equal(defaultValue); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {ModuleConfiguration} from '@pages/BO/modules/moduleConfiguration'; | ||
|
||
import type {Page} from 'playwright'; | ||
|
||
/** | ||
* Module configuration page for module : ps_newproducts, contains selectors and functions for the page | ||
* @class | ||
* @extends ModuleConfiguration | ||
*/ | ||
class PsNewProducts extends ModuleConfiguration { | ||
public readonly pageSubTitle: string; | ||
|
||
public readonly updateSettingsSuccessMessage: string; | ||
|
||
private readonly productsToDisplayInput: string; | ||
|
||
private readonly saveSettingsForm: string; | ||
|
||
/** | ||
* @constructs | ||
* Setting up titles and selectors to use on ps email subscription page | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.pageSubTitle = 'New products block'; | ||
this.updateSettingsSuccessMessage = 'The settings have been updated.'; | ||
|
||
// Selectors | ||
this.productsToDisplayInput = '#NEW_PRODUCTS_NBR'; | ||
this.saveSettingsForm = '#module_form_submit_btn'; | ||
} | ||
|
||
/* Methods */ | ||
/** | ||
* Set Products to display | ||
* @param page {Page} Browser tab | ||
* @param value {number} | ||
* @returns {Promise<string>} | ||
*/ | ||
async setNumProductsToDisplay(page: Page, value: number): Promise<string> { | ||
await page.locator(this.productsToDisplayInput).fill(value.toString()); | ||
await this.clickAndWaitForLoadState(page, this.saveSettingsForm); | ||
|
||
return this.getAlertSuccessBlockContent(page); | ||
} | ||
|
||
/** | ||
* Get Products to display | ||
* @param page {Page} Browser tab | ||
* @returns {Promise<string>} | ||
*/ | ||
async getNumProductsToDisplay(page: Page): Promise<string> { | ||
return this.getAttributeContent(page, this.productsToDisplayInput, 'value'); | ||
} | ||
} | ||
|
||
export default new PsNewProducts(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters