Skip to content

Commit

Permalink
Merge pull request PrestaShop#34573 from nesrineabdmouleh/TEST-1045
Browse files Browse the repository at this point in the history
Functional tests - Add new test 'Shop parameters > Enable/Disable iframes'
  • Loading branch information
nesrineabdmouleh authored Nov 16, 2023
2 parents d0bdea5 + 091652e commit a32b1f1
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';

// Import pages
// Import BO pages
import dashboardPage from '@pages/BO/dashboard';
import generalPage from '@pages/BO/shopParameters/general';
import productsPage from '@pages/BO/catalog/products';
import addProductPage from '@pages/BO/catalog/products/add';
import descriptionTab from '@pages/BO/catalog/products/add/descriptionTab';
// Import FO pages
import foProductPage from '@pages/FO/product';

// Import data
import Products from '@data/demo/products';

import {expect} from 'chai';
import type {BrowserContext, Page} from 'playwright';

const baseContext: string = 'functional_BO_shopParameters_general_general_allowIframes';

/*
Enable/Disable allow iframe
Go to product page and edit the description
Add an iframe in the description
Preview product and check the product description
*/
describe('BO - Shop Parameters - General : Enable/Disable Allow iframes on HTML field', async () => {
let browserContext: BrowserContext;
let page: Page;
const description: string = '<iframe width="560" height="315" src="https://www.youtube.com/embed'
+ '/3qcApq8NMhw?si=0O8BBWjbJ7gJRkoi" title="YouTube video player" frameborder="0" allow="accelerometer; '
+ 'autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>';

// 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);
});

const tests = [
{args: {action: 'Disable', exist: false}},
{args: {action: 'Enable', exist: true}},
];

tests.forEach((test, index: number) => {
describe(`${test.args.action} Allow iframes on HTML fields`, async () => {
it('should go to \'Shop parameters > General\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToGeneralPage${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.shopParametersParentLink,
dashboardPage.shopParametersGeneralLink,
);
await generalPage.closeSfToolBar(page);

const pageTitle = await generalPage.getPageTitle(page);
expect(pageTitle).to.contains(generalPage.pageTitle);
});

it(`should ${test.args.action} allow iframes`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.action}AllowIframes`, baseContext);

const result = await generalPage.setAllowIframes(page, test.args.exist);
expect(result).to.contains(generalPage.successfulUpdateMessage);
});

it('should go to Products page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToProductsPage${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.catalogParentLink,
dashboardPage.productsLink,
);
await productsPage.closeSfToolBar(page);

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

it('should go to first product page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToFirstProductPage${index}`, baseContext);

await productsPage.goToProductPage(page, 1);

const pageTitle = await addProductPage.getPageTitle(page);
expect(pageTitle).to.contains(addProductPage.pageTitle);
});

it('should add an iframe in the product description', async function () {
await testContext.addContextItem(this, 'testIdentifier', `editDescription${index}`, baseContext);

await descriptionTab.setIframeInDescription(page, description);

// @todo : https://github.com/PrestaShop/PrestaShop/issues/33921
// To delete after the fix of the issue
if (test.args.action === 'Disable') {
await addProductPage.clickOnSaveProductButton(page);
} else {
const message = await addProductPage.saveProduct(page);
expect(message).to.eq(addProductPage.successfulUpdateMessage);
}
});

it('should preview the product', async function () {
await testContext.addContextItem(this, 'testIdentifier', `previewProduct${index}`, baseContext);

page = await addProductPage.previewProduct(page);
await foProductPage.changeLanguage(page, 'en');

const pageTitle = await foProductPage.getPageTitle(page);
expect(pageTitle).to.contains(Products.demo_14.name);
});

it('should check the existence of the iframe in the product description', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkIframe${index}`, baseContext);

const isIframeVisible = await foProductPage.isIframeVisibleInProductDescription(page);
expect(isIframeVisible).to.equal(test.args.exist);

if (test.args.exist) {
const youtubeURL = await foProductPage.getURLInProductDescription(page);
expect(youtubeURL).to.equal('https://www.youtube.com/embed/3qcApq8NMhw?si=0O8BBWjbJ7gJRkoi');
}
});

it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goBackToBo${index}`, baseContext);

page = await foProductPage.closePage(browserContext, page, 0);

const pageTitle = await addProductPage.getPageTitle(page);
expect(pageTitle).to.contains(addProductPage.pageTitle);
});
});
});

// POST-TEST : Delete iframe in product description
describe('POST-TEST : Reset product description', async () => {
it('should go to Products page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToProductsPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.catalogParentLink,
dashboardPage.productsLink,
);
await productsPage.closeSfToolBar(page);

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

it('should go to first product page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFirstProductPage', baseContext);

await productsPage.goToProductPage(page, 1);

const pageTitle = await addProductPage.getPageTitle(page);
expect(pageTitle).to.contains(addProductPage.pageTitle);
});

it('should reset the product description', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetDescription', baseContext);

await descriptionTab.setIframeInDescription(page, '');
await descriptionTab.setDescription(page, Products.demo_14.description);

const message = await addProductPage.saveProduct(page);
expect(message).to.eq(addProductPage.successfulUpdateMessage);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,92 +44,94 @@ describe('BO - Shop Parameters - General : Enable/Disable display suppliers', as
});

const tests = [
{args: {action: 'enable', exist: true}},
{args: {action: 'disable', exist: false}},
{args: {action: 'Enable', exist: true}},
{args: {action: 'Disable', exist: false}},
];

tests.forEach((test, index: number) => {
it('should go to \'Shop parameters > General\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToGeneralPage_${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.shopParametersParentLink,
dashboardPage.shopParametersGeneralLink,
);
await generalPage.closeSfToolBar(page);

const pageTitle = await generalPage.getPageTitle(page);
expect(pageTitle).to.contains(generalPage.pageTitle);
});
describe(`${test.args.action} Display suppliers`, async () => {
it('should go to \'Shop parameters > General\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToGeneralPage_${index}`, baseContext);

it(`should ${test.args.action} display suppliers`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.action}DisplaySuppliers`, baseContext);
await dashboardPage.goToSubMenu(
page,
dashboardPage.shopParametersParentLink,
dashboardPage.shopParametersGeneralLink,
);
await generalPage.closeSfToolBar(page);

const result = await generalPage.setDisplaySuppliers(page, test.args.exist);
expect(result).to.contains(generalPage.successfulUpdateMessage);
});
const pageTitle = await generalPage.getPageTitle(page);
expect(pageTitle).to.contains(generalPage.pageTitle);
});

it('should go to \'Brands & Suppliers\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToBrandsPage_${index}`, baseContext);
it(`should ${test.args.action} display suppliers`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.action}DisplaySuppliers`, baseContext);

await generalPage.goToSubMenu(
page,
generalPage.catalogParentLink,
generalPage.brandsAndSuppliersLink,
);
const result = await generalPage.setDisplaySuppliers(page, test.args.exist);
expect(result).to.contains(generalPage.successfulUpdateMessage);
});

const pageTitle = await brandsPage.getPageTitle(page);
expect(pageTitle).to.contains(brandsPage.pageTitle);
});
it('should go to \'Brands & Suppliers\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToBrandsPage_${index}`, baseContext);

it('should go to \'Suppliers\' tab', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToSuppliersTab_${index}`, baseContext);
await generalPage.goToSubMenu(
page,
generalPage.catalogParentLink,
generalPage.brandsAndSuppliersLink,
);

await brandsPage.goToSubTabSuppliers(page);
const pageTitle = await brandsPage.getPageTitle(page);
expect(pageTitle).to.contains(brandsPage.pageTitle);
});

const pageTitle = await suppliersPage.getPageTitle(page);
expect(pageTitle).to.contains(suppliersPage.pageTitle);
});
it('should go to \'Suppliers\' tab', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToSuppliersTab_${index}`, baseContext);

it(`should check that the message alert contains '${test.args.action}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkAlertContains_${test.args.action}`, baseContext);
await brandsPage.goToSubTabSuppliers(page);

const text = await suppliersPage.getAlertInfoBlockParagraphContent(page);
expect(text).to.contains(test.args.action);
});
const pageTitle = await suppliersPage.getPageTitle(page);
expect(pageTitle).to.contains(suppliersPage.pageTitle);
});

it('should go to FO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToFO_${test.args.action}`, baseContext);
it(`should check that the message alert contains '${test.args.action}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkAlertContains_${test.args.action}`, baseContext);

// View shop
page = await suppliersPage.viewMyShop(page);
// Change shop language
await homePage.changeLanguage(page, 'en');
const text = await suppliersPage.getAlertInfoBlockParagraphContent(page);
expect(text).to.contains(test.args.action.toLowerCase());
});

const isHomePage = await homePage.isHomePage(page);
expect(isHomePage).to.eq(true);
});
it('should go to FO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToFO_${test.args.action}`, baseContext);

it('should verify the existence of the suppliers page link', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkSuppliersPage_${test.args.action}`, baseContext);
// View shop
page = await suppliersPage.viewMyShop(page);
// Change shop language
await homePage.changeLanguage(page, 'en');

await homePage.goToFooterLink(page, 'Sitemap');
const isHomePage = await homePage.isHomePage(page);
expect(isHomePage).to.eq(true);
});

const pageTitle = await siteMapPage.getPageTitle(page);
expect(pageTitle).to.equal(siteMapPage.pageTitle);
it('should verify the existence of the suppliers page link', async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkSuppliersPage_${test.args.action}`, baseContext);

const exist = await siteMapPage.isSuppliersLinkVisible(page);
expect(exist).to.be.equal(test.args.exist);
});
await homePage.goToFooterLink(page, 'Sitemap');

const pageTitle = await siteMapPage.getPageTitle(page);
expect(pageTitle).to.equal(siteMapPage.pageTitle);

const exist = await siteMapPage.isSuppliersLinkVisible(page);
expect(exist).to.be.equal(test.args.exist);
});

it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goBackToBo_${test.args.action}`, baseContext);
it('should go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goBackToBo_${test.args.action}`, baseContext);

page = await siteMapPage.closePage(browserContext, page, 0);
page = await siteMapPage.closePage(browserContext, page, 0);

const pageTitle = await suppliersPage.getPageTitle(page);
expect(pageTitle).to.contains(suppliersPage.pageTitle);
const pageTitle = await suppliersPage.getPageTitle(page);
expect(pageTitle).to.contains(suppliersPage.pageTitle);
});
});
});
});
Loading

0 comments on commit a32b1f1

Please sign in to comment.