Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional Tests : New products block module - Reset module #35357

Merged
merged 1 commit into from Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -182,7 +182,7 @@ describe('BO - International - Translation : Modify translation', async () => {
it('should check the translation', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkTranslation', baseContext);

const title = await homePage.getBlockTitle(page);
const title = await homePage.getBlockTitle(page, 'popularproducts');
expect(title).to.contain('translate');
});
});
Expand Down
Expand Up @@ -49,14 +49,14 @@ describe('FO - Home Page : Display some products', async () => {

await homePage.changeLanguage(page, 'en');

const popularProductTitle = await homePage.getBlockTitle(page, 1);
const popularProductTitle = await homePage.getBlockTitle(page, 'popularproducts');
expect(popularProductTitle).to.equal('Popular Products');
});

it('should check the number of popular products', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkPopularProductsNumber', baseContext);

const productsNumber = await homePage.getProductsBlockNumber(page, 1);
const productsNumber = await homePage.getProductsBlockNumber(page, 'popularproducts');
expect(productsNumber).to.equal(8);
});

Expand Down Expand Up @@ -99,14 +99,14 @@ describe('FO - Home Page : Display some products', async () => {
it('should check products on sale block title', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkProductsOnSaleBlockTitle', baseContext);

const popularProductTitle = await homePage.getBlockTitle(page, 2);
const popularProductTitle = await homePage.getBlockTitle(page, 'onsale');
expect(popularProductTitle).to.equal('On sale');
});

it('should check the number of products in sale', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNumberOfProductsInSale', baseContext);

const productsNumber = await homePage.getProductsBlockNumber(page, 2);
const productsNumber = await homePage.getProductsBlockNumber(page, 'onsale');
expect(productsNumber).to.equal(2);
});

Expand All @@ -133,14 +133,14 @@ describe('FO - Home Page : Display some products', async () => {
it('should check new products title', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNewProductsBlock', baseContext);

const popularProductTitle = await homePage.getBlockTitle(page, 3);
const popularProductTitle = await homePage.getBlockTitle(page, 'newproducts');
expect(popularProductTitle).to.equal('New products');
});

it('should check the number of new products', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNewProductsNumber', baseContext);

const productsNumber = await homePage.getProductsBlockNumber(page, 3);
const productsNumber = await homePage.getProductsBlockNumber(page, 'newproducts');
expect(productsNumber).to.equal(8);
});

Expand Down
@@ -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, 'newproducts');
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, 'newproducts');
expect(numProductsInBlock).to.be.equal(defaultValue);
});
});
4 changes: 4 additions & 0 deletions tests/UI/data/demo/modules.ts
Expand Up @@ -31,6 +31,10 @@ export default {
name: 'Faceted search',
releaseZip: 'https://github.com/PrestaShop/ps_facetedsearch/releases/download/v3.14.1/ps_facetedsearch.zip',
}),
psNewProducts: new ModuleData({
tag: 'ps_newproducts',
name: 'New products',
}),
psThemeCusto: new ModuleData({
tag: 'ps_themecusto',
name: 'Theme Customization',
Expand Down
58 changes: 58 additions & 0 deletions tests/UI/pages/BO/modules/psNewProducts/index.ts
@@ -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();