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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests - Add new test 'BO > Customers > View/edit voucher' #34223

Merged
merged 3 commits into from
Oct 10, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import loginCommon from '@commonTests/BO/loginBO';
import {createCartRuleTest} from '@commonTests/BO/catalog/cartRule';

// Import pages
import customersPage from '@pages/BO/customers';
import dashboardPage from '@pages/BO/dashboard';
import viewCustomerPage from '@pages/BO/customers/view';
import editRulesPage from '@pages/BO/catalog/discounts/add';

// Import data
import Customers from '@data/demo/customers';
import CartRuleData from '@data/faker/cartRule';

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

const baseContext: string = 'functional_BO_customers_customers_viewEditVoucher';

describe('BO - Customers - Customers : View/edit voucher', async () => {
let browserContext: BrowserContext;
let page: Page;

// Data to create cart rule
const newCartRuleData: CartRuleData = new CartRuleData({
name: 'reduction',
customer: Customers.johnDoe,
discountType: 'Amount',
discountAmount: {
value: 20,
currency: 'EUR',
tax: 'Tax included',
},
});

const editCartRuleData: CartRuleData = new CartRuleData({
name: 'reduction',
description: 'abkjbhvggfvfi',
discountType: 'Amount',
discountAmount: {
value: 20,
currency: 'EUR',
tax: 'Tax included',
},
});

// Pre-condition: Create cart rule
createCartRuleTest(newCartRuleData, `${baseContext}_PreTest`);

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

after(async () => {
await helper.closeBrowserContext(browserContext);
});

describe('View voucher', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Customers > Customers\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToCustomersPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.customersParentLink,
dashboardPage.customersLink,
);
await customersPage.closeSfToolBar(page);

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

it(`should filter list by email '${Customers.johnDoe.email}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterToViewCreatedCustomer', baseContext);

await customersPage.resetFilter(page);
await customersPage.filterCustomers(page, 'input', 'email', Customers.johnDoe.email);

const textEmail = await customersPage.getTextColumnFromTableCustomers(page, 1, 'email');
expect(textEmail).to.contains(Customers.johnDoe.email);
});

it('should click on view customer', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToViewCustomerPageAfterCreateCustomer', baseContext);

await customersPage.goToViewCustomerPage(page, 1);

const pageTitle = await viewCustomerPage.getPageTitle(page);
expect(pageTitle).to.contains(viewCustomerPage.pageTitle('J. DOE'));
});

it('should check vouchers number', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkVouchersNumber', baseContext);

const cardHeaderText = await viewCustomerPage.getNumberOfElementFromTitle(page, 'Vouchers');
expect(cardHeaderText).to.eq('1');
});

it('should check vouchers table', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkVouchersTable', baseContext);

const vouchers = await viewCustomerPage.getTextFromElement(page, 'Vouchers');
expect(vouchers).to.contains(`${newCartRuleData.name} check 1`);
});
});

describe('Edit voucher', async () => {
it('should click on edit voucher button', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnEditVoucherButton', baseContext);

await viewCustomerPage.goToPage(page, 'Vouchers');

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

it('should update the created cart rule', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateCartRule', baseContext);

await editRulesPage.fillInformationForm(page, editCartRuleData);

const validationMessage = await editRulesPage.saveCartRule(page);
expect(validationMessage).to.contains(viewCustomerPage.updateSuccessfulMessage);
});

it('should delete the created voucher', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteVoucher', baseContext);

const successMessage = await viewCustomerPage.deleteVoucher(page, 1);
expect(successMessage).to.contains(viewCustomerPage.successfulDeleteMessage);
});

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

await dashboardPage.goToSubMenu(
page,
dashboardPage.customersParentLink,
dashboardPage.customersLink,
);

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

it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'resetFilter', baseContext);

await customersPage.resetFilter(page);

const numberOfCustomersAfterDelete = await customersPage.resetAndGetNumberOfLines(page);
expect(numberOfCustomersAfterDelete).to.be.at.least(0);
});
});
});
27 changes: 20 additions & 7 deletions tests/UI/pages/BO/catalog/discounts/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class AddCartRule extends BOBasePage {
* @param cartRuleData {CartRuleData} Data to set on information form
* @return {Promise<void>}
*/
async fillInformationForm(page: Frame|Page, cartRuleData: CartRuleData): Promise<void> {
async fillInformationForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to tab conditions
await page.click(this.infomationsTabLink);

Expand Down Expand Up @@ -320,7 +320,7 @@ class AddCartRule extends BOBasePage {
* @param cartRuleData {CartRuleData} Data to set on conditions form
* @return {Promise<void>}
*/
async fillConditionsForm(page: Frame|Page, cartRuleData: CartRuleData): Promise<void> {
async fillConditionsForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to tab conditions
await page.click(this.conditionsTabLink);

Expand Down Expand Up @@ -407,7 +407,7 @@ class AddCartRule extends BOBasePage {
* @param cartRuleData {CartRuleData} Data to set on actions form
* @return {Promise<void>}
*/
async fillActionsForm(page: Frame|Page, cartRuleData: CartRuleData): Promise<void> {
async fillActionsForm(page: Frame | Page, cartRuleData: CartRuleData): Promise<void> {
// Go to actions tab
await page.click(this.actionsTabLink);

Expand Down Expand Up @@ -485,10 +485,10 @@ class AddCartRule extends BOBasePage {
* @returns {Promise<string|null>}
*/
async createEditCartRules(
page: Frame|Page,
page: Frame | Page,
cartRuleData: CartRuleData,
waitForNavigation: boolean = true,
): Promise<string|null> {
): Promise<string | null> {
// Fill information form
await this.fillInformationForm(page, cartRuleData);

Expand All @@ -500,15 +500,28 @@ class AddCartRule extends BOBasePage {

if (waitForNavigation) {
// Save and return successful message
await this.clickAndWaitForURL(page, this.saveButton);
return this.getAlertSuccessBlockContent(page);
return this.saveCartRule(page);
}

// Save
await this.waitForSelectorAndClick(page, this.saveButton);
return null;
}

/**
* Save cart rule
* @param page {Frame|Page} Browser tab
* @returns {Promise<string>}
*/
async saveCartRule(page: Frame | Page): Promise<string> {
await this.clickAndWaitForURL(page, this.saveButton);

if (await this.elementVisible(page, `${this.alertSuccessBlock}[role='alert']`, 2000)) {
return this.getTextContent(page, `${this.alertSuccessBlock}[role='alert']`);
}
return this.getTextContent(page, this.alertSuccessBlock);
}

/**
* Get limit single customer
* @param page {Page} Browser tab
Expand Down
46 changes: 35 additions & 11 deletions tests/UI/pages/BO/customers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ class ViewCustomer extends BOBasePage {

private readonly vouchersDiv: string;

private readonly voucherEditButton: string;
private readonly voucherEditButton: (row: number) => string;

private readonly voucherToggleDropdown: string;
private readonly voucherToggleDropdown: (row: number) => string;

private readonly voucherDeleteButton: string;

private readonly voucherDeleteConfirmButton: string;

private readonly voucherDeleteModal: string;

private readonly lastEmailsDiv: string;

private readonly lastConnectionsDiv: string;
Expand Down Expand Up @@ -100,9 +104,11 @@ class ViewCustomer extends BOBasePage {

// Vouchers
this.vouchersDiv = '.customer-discounts-card';
this.voucherEditButton = `${this.vouchersDiv} a.grid-edit-row-link`;
this.voucherToggleDropdown = `${this.vouchersDiv} a[data-toggle='dropdown']`;
this.voucherDeleteButton = `${this.vouchersDiv} .dropdown-menu a.grid-delete-row-link`;
this.voucherEditButton = (row: number) => `${this.vouchersDiv} tr:nth-child(${row}) a.grid-edit-row-link`;
this.voucherToggleDropdown = (row: number) => `${this.vouchersDiv} tr:nth-child(${row}) a[data-toggle='dropdown']`;
this.voucherDeleteButton = `${this.vouchersDiv} .dropdown-menu button.grid-delete-row-link`;
this.voucherDeleteModal = '#customer_discount-grid-confirm-modal';
this.voucherDeleteConfirmButton = `${this.voucherDeleteModal} button.btn-confirm-submit`;

// Last emails
this.lastEmailsDiv = '.customer-sent-emails-card';
Expand Down Expand Up @@ -134,7 +140,7 @@ class ViewCustomer extends BOBasePage {
* @param cardTitle {string} Value of card title to get number of elements
* @returns {Promise<string>}
*/
getNumberOfElementFromTitle(page: Frame|Page, cardTitle: string): Promise<string> {
async getNumberOfElementFromTitle(page: Frame | Page, cardTitle: string): Promise<string> {
let selector: string;

switch (cardTitle) {
Expand Down Expand Up @@ -180,7 +186,7 @@ class ViewCustomer extends BOBasePage {
* @param page {Page|Frame} Browser tab
* @returns {Promise<string>}
*/
getPersonalInformationTitle(page: Page|Frame): Promise<string> {
async getPersonalInformationTitle(page: Page | Frame): Promise<string> {
return this.getTextContent(page, this.personnalInformationDiv);
}

Expand All @@ -190,7 +196,7 @@ class ViewCustomer extends BOBasePage {
* @param element {string} Value of element to get text content
* @returns {Promise<string>}
*/
getTextFromElement(page: Page, element: string): Promise<string> {
async getTextFromElement(page: Page, element: string): Promise<string> {
let selector: string;

switch (element) {
Expand Down Expand Up @@ -241,7 +247,7 @@ class ViewCustomer extends BOBasePage {
* @param row {number} Row number in table Last connections
* @returns {Promise<string>}
*/
getTextColumnFromTableLastConnections(page: Page, column: string, row: number = 1): Promise<string> {
async getTextColumnFromTableLastConnections(page: Page, column: string, row: number = 1): Promise<string> {
return this.getTextContent(page, this.lastConnectionTableColumn(row, column));
}

Expand All @@ -252,7 +258,7 @@ class ViewCustomer extends BOBasePage {
* @param row {number} Row number in table carts
* @returns {Promise<string>}
*/
getTextColumnFromTableCarts(page: Page, column: string, row: number = 1): Promise<string> {
async getTextColumnFromTableCarts(page: Page, column: string, row: number = 1): Promise<string> {
return this.getTextContent(page, this.cartsTableColumn(row, column));
}

Expand All @@ -261,7 +267,7 @@ class ViewCustomer extends BOBasePage {
* @param page {Frame|Page} Browser tab
* @returns {Promise<boolean>}
*/
isPrivateNoteBlockVisible(page: Frame|Page): Promise<boolean> {
async isPrivateNoteBlockVisible(page: Frame | Page): Promise<boolean> {
return this.elementVisible(page, this.privateNoteDiv, 1000);
}

Expand Down Expand Up @@ -307,13 +313,31 @@ class ViewCustomer extends BOBasePage {
case 'Addresses':
selector = this.addressesEditButton;
break;
case 'Vouchers':
selector = this.voucherEditButton;
break;
default:
throw new Error(`${cardTitle} was not found`);
}

return this.clickAndWaitForURL(page, selector(row));
}

/**
* Delete voucher
* @param page {Page} Browser tab
* @param row {number} Row in vouchers table
* @returns {Promise<string>}
*/
async deleteVoucher(page: Page, row: number) {
await page.locator(this.voucherToggleDropdown(row)).click();
await page.locator(this.voucherDeleteButton).click();
await this.waitForVisibleSelector(page, this.voucherDeleteModal);
await page.locator(this.voucherDeleteConfirmButton).click();

return this.getTextContent(page, `${this.alertSuccessBlock}[role='alert']`);
}

/**
* Get customer ID
* @param page {Page} Browser tab
Expand Down