Skip to content

Commit

Permalink
Merge pull request PrestaShop#35298 from nesrineabdmouleh/TEST-4977
Browse files Browse the repository at this point in the history
Functional tests - Add new test to view voucher in FO - Hummingbird theme
  • Loading branch information
nesrineabdmouleh authored Feb 12, 2024
2 parents 7a2ee26 + 712dd12 commit 7af2b6f
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {homePage} from '@pages/FO/classic/home';
import {orderConfirmationPage} from '@pages/FO/classic/checkout/orderConfirmation';
import {productPage as foProductPage} from '@pages/FO/classic/product';
import {myAccountPage} from '@pages/FO/classic/myAccount';
import foVouchersPage from '@pages/FO/classic/myAccount/vouchers';
import {vouchersPage as foVouchersPage} from '@pages/FO/classic/myAccount/vouchers';
import {checkoutPage} from '@pages/FO/classic/checkout';

// Import data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import addCartRulePage from '@pages/BO/catalog/discounts/add';
import {homePage} from '@pages/FO/classic/home';
import {loginPage as foLoginPage} from '@pages/FO/classic/login';
import {myAccountPage} from '@pages/FO/classic/myAccount';
import foVouchersPage from '@pages/FO/classic/myAccount/vouchers';
import {vouchersPage as foVouchersPage} from '@pages/FO/classic/myAccount/vouchers';
import {cartPage} from '@pages/FO/classic/cart';

// Import data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {createAccountTest} from '@commonTests/FO/account';
import {homePage} from '@pages/FO/classic/home';
import {loginPage as foLoginPage} from '@pages/FO/classic/login';
import {myAccountPage} from '@pages/FO/classic/myAccount';
import foVouchersPage from '@pages/FO/classic/myAccount/vouchers';
import {vouchersPage as foVouchersPage} from '@pages/FO/classic/myAccount/vouchers';

// Import data
import CartRuleData from '@data/faker/cartRule';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Import utils
import date from '@utils/date';
import helper from '@utils/helpers';
import testContext from '@utils/testContext';
import files from '@utils/files';

// Import commonTests
import {createCartRuleTest} from '@commonTests/BO/catalog/cartRule';
import {deleteCustomerTest} from '@commonTests/BO/customers/customer';
import createAccountTest from '@commonTests/FO/hummingbird/account';
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

// Import FO pages
import homePage from '@pages/FO/hummingbird/home';
import foLoginPage from '@pages/FO/hummingbird/login';
import myAccountPage from '@pages/FO/hummingbird/myAccount';
import foVouchersPage from '@pages/FO/hummingbird/myAccount/vouchers';

// Import data
import CartRuleData from '@data/faker/cartRule';
import CustomerData from '@data/faker/customer';

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

const baseContext: string = 'functional_FO_hummingbird_userAccount_viewVouchers';

/*
Pre-condition:
- Create customer
- Create 2 cart rules for the customer
- Install hummingbird theme
Scenario:
- Go To FO and sign in
- Check vouchers in account page
Post-condition:
- Delete customer
- Uninstall hummingbird theme
*/
describe('FO - Account : View vouchers', async () => {
let browserContext: BrowserContext;
let page: Page;

// Data to create a date format
const pastDate: string = date.getDateFormat('yyyy-mm-dd', 'past');
const futureDate: string = date.getDateFormat('yyyy-mm-dd', 'future');
const expirationDate: string = date.getDateFormat('mm/dd/yyyy', 'future');
const customerData: CustomerData = new CustomerData({});
const firstCartRule: CartRuleData = new CartRuleData({
code: 'promo20',
customer: customerData,
discountType: 'Percent',
discountPercent: 20,
dateFrom: pastDate,
dateTo: futureDate,
});
const secondCartRule: CartRuleData = new CartRuleData({
code: 'freeShipping',
customer: customerData,
freeShipping: true,
dateFrom: pastDate,
dateTo: futureDate,
});

// Pre-condition : Install Hummingbird
installHummingbird(`${baseContext}_preTest_0`);

// Pre-condition: Create new account on FO
createAccountTest(customerData, `${baseContext}_preTest_1`);

// Pre-condition: Create 2 cart rules for the created customer
[firstCartRule, secondCartRule].forEach((cartRule: CartRuleData, index: number) => {
createCartRuleTest(cartRule, `${baseContext}_preTest_${index + 2}`);
});

// before and after functions
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);
});

after(async () => {
await helper.closeBrowserContext(browserContext);
await files.deleteFile('../../admin-dev/hummingbird.zip');
});

describe('View vouchers on FO', async () => {
it('should open the shop page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToShopFO', baseContext);

await homePage.goTo(page, global.FO.URL);

const result = await homePage.isHomePage(page);
expect(result).to.eq(true);
});

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

await homePage.goToLoginPage(page);

const pageTitle = await foLoginPage.getPageTitle(page);
expect(pageTitle, 'Fail to open FO login page').to.contains(foLoginPage.pageTitle);
});

it('should sign in with created customer', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'sighInFO', baseContext);

await foLoginPage.customerLogin(page, customerData);

const isCustomerConnected = await foLoginPage.isCustomerConnected(page);
expect(isCustomerConnected, 'Customer is not connected').to.eq(true);
});

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

await homePage.goToMyAccountPage(page);
await myAccountPage.goToVouchersPage(page);

const pageHeaderTitle = await foVouchersPage.getPageTitle(page);
expect(pageHeaderTitle).to.equal(foVouchersPage.pageTitle);
});

[
{args: {column: 'code', row: 1, value: firstCartRule.code}},
{args: {column: 'description', row: 1, value: firstCartRule.name}},
{args: {column: 'quantity', row: 1, value: '1'}},
{args: {column: 'value', row: 1, value: '20%'}},
{args: {column: 'minimum', row: 1, value: 'None'}},
{args: {column: 'cumulative', row: 1, value: 'Yes'}},
{args: {column: 'expiration_date', row: 1, value: expirationDate}},
{args: {column: 'code', row: 2, value: secondCartRule.code}},
{args: {column: 'description', row: 2, value: secondCartRule.name}},
{args: {column: 'quantity', row: 2, value: '1'}},
{args: {column: 'value', row: 2, value: 'Free shipping'}},
{args: {column: 'minimum', row: 2, value: 'None'}},
{args: {column: 'cumulative', row: 2, value: 'Yes'}},
{args: {column: 'expiration_date', row: 2, value: expirationDate}},
].forEach((cartRule, index: number) => {
it(`should check the voucher ${cartRule.args.column}${cartRule.args.row}`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkVoucher${index}`, baseContext);

const cartRuleTextColumn = await foVouchersPage.getTextColumnFromTableVouchers(
page,
cartRule.args.row,
cartRule.args.column,
);
expect(cartRuleTextColumn).to.equal(cartRule.args.value);
});
});
});

// Post-condition: Delete created customer
deleteCustomerTest(customerData, `${baseContext}_postTest_0`);

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest_1`);
});
9 changes: 5 additions & 4 deletions tests/UI/pages/FO/classic/myAccount/vouchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {Page} from 'playwright';
* @class
* @extends FOBasePage
*/
class Vouchers extends FOBasePage {
class VouchersPage extends FOBasePage {
public readonly pageTitle: string;

private readonly vouchersTable: string;
Expand Down Expand Up @@ -36,8 +36,8 @@ class Vouchers extends FOBasePage {
* @constructs
* Setting up texts and selectors to use on vouchers page
*/
constructor() {
super();
constructor(theme: string = 'classic') {
super(theme);

this.pageTitle = 'Discount';

Expand Down Expand Up @@ -115,4 +115,5 @@ class Vouchers extends FOBasePage {
}
}

export default new Vouchers();
const vouchersPage = new VouchersPage();
export {vouchersPage, VouchersPage};
18 changes: 18 additions & 0 deletions tests/UI/pages/FO/hummingbird/myAccount/vouchers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Import FO pages
import {VouchersPage} from '@pages/FO/classic/myAccount/vouchers';

/**
* @class
* @extends FOBasePage
*/
class Vouchers extends VouchersPage {
/**
* @constructs
* Setting up texts and selectors to use
*/
constructor() {
super('hummingbird');
}
}

export default new Vouchers();

0 comments on commit 7af2b6f

Please sign in to comment.