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 - Add some tests in 'Customer service > Merchandise return' page #32149

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

Large diffs are not rendered by default.

@@ -0,0 +1,330 @@
// 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 merchandiseReturnsPage from '@pages/BO/customerService/merchandiseReturns';
import dashboardPage from '@pages/BO/dashboard';
import ordersPage from '@pages/BO/orders';
import {viewOrderBasePage} from '@pages/BO/orders/view/viewOrderBasePage';
import editMerchandiseReturnsPage from '@pages/BO/customerService/merchandiseReturns/edit';
// Import FO pages
import cartPage from '@pages/FO/cart';
import checkoutPage from '@pages/FO/checkout';
import orderConfirmationPage from '@pages/FO/checkout/orderConfirmation';
import {homePage} from '@pages/FO/home';
import {loginPage as foLoginPage} from '@pages/FO/login';
import myAccountPage from '@pages/FO/myAccount';
import foMerchandiseReturnsPage from '@pages/FO/myAccount/merchandiseReturns';
import orderDetailsPage from '@pages/FO/myAccount/orderDetails';
import orderHistoryPage from '@pages/FO/myAccount/orderHistory';

// Import data
import Customers from '@data/demo/customers';
import OrderStatuses from '@data/demo/orderStatuses';
import PaymentMethods from '@data/demo/paymentMethods';

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

const baseContext: string = 'functional_BO_customerService_merchandiseReturns_deleteProduct';

/*
Pre-condition:
- Create order in FO
- Activate merchandise returns
- Change the first order status in the list to shipped
Scenario
- Create merchandise returns in FO (3 products)
- GO to BO > merchandise returns page > Edit
- Delete the first product (Click on Take me out of here!)
- Delete the second product (Click on I understand the risks...)
- Try to delete the last product and check the error message
Post-condition:
- Deactivate merchandise returns
*/
describe('BO - Customer Service - Merchandise Returns : Delete product', async () => {
let browserContext: BrowserContext;
let page: Page;

// 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('PRE-TEST: Create order in FO', async () => {
it('should go to FO page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFO', baseContext);

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

const isHomePage = await homePage.isHomePage(page);
await expect(isHomePage, 'Fail to open FO home page').to.be.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);
await expect(pageTitle, 'Fail to open FO login page').to.contains(foLoginPage.pageTitle);
});

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

await foLoginPage.customerLogin(page, Customers.johnDoe);

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

it('should add 3 products to the cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'addProductToCart', baseContext);

await foLoginPage.goToHomePage(page);

// Add first product to cart by quick view
await homePage.addProductToCartByQuickView(page, 1, 2);
await homePage.continueShopping(page);

// Add second product to cart by quick view
await homePage.addProductToCartByQuickView(page, 2, 2);
await homePage.continueShopping(page);

// Add third product to cart by quick view
await homePage.addProductToCartByQuickView(page, 3, 2);
await homePage.proceedToCheckout(page);

const notificationsNumber = await cartPage.getCartNotificationsNumber(page);
await expect(notificationsNumber).to.be.equal(6);
});

it('should go to delivery step', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToDeliveryStep', baseContext);

await cartPage.clickOnProceedToCheckout(page);

const isStepAddressComplete = await checkoutPage.goToDeliveryStep(page);
await expect(isStepAddressComplete, 'Step Address is not complete').to.be.true;
});

it('should go to payment step', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToPaymentStep', baseContext);

const isStepDeliveryComplete = await checkoutPage.goToPaymentStep(page);
await expect(isStepDeliveryComplete, 'Step Address is not complete').to.be.true;
});

it('should choose payment method and confirm the order', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'confirmOrder', baseContext);

await checkoutPage.choosePaymentAndOrder(page, PaymentMethods.wirePayment.moduleName);

const cardTitle = await orderConfirmationPage.getOrderConfirmationCardTitle(page);
await expect(cardTitle).to.contains(orderConfirmationPage.orderConfirmationCardTitle);
});
});

describe('PRE-TEST: Enable merchandise returns', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Customer Service > Merchandise Returns\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToMerchandiseReturnsPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.customerServiceParentLink,
dashboardPage.merchandiseReturnsLink,
);
await merchandiseReturnsPage.closeSfToolBar(page);

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

it('should enable merchandise returns', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'enableReturns', baseContext);

const result = await merchandiseReturnsPage.setOrderReturnStatus(page, true);
await expect(result).to.contains(merchandiseReturnsPage.successfulUpdateMessage);
});
});

describe('PRE-TEST: Change order status to \'Shipped\'', async () => {
it('should go to \'Orders > Orders\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToOrdersPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.ordersParentLink,
dashboardPage.ordersLink,
);

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

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

await ordersPage.goToOrder(page, 1);

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

it(`should change the order status to '${OrderStatuses.shipped.name}' and check it`, async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateOrderStatus', baseContext);

const result = await viewOrderBasePage.modifyOrderStatus(page, OrderStatuses.shipped.name);
await expect(result).to.equal(OrderStatuses.shipped.name);
});

it('should check if the button \'Return products\' is visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkReturnProductsButton', baseContext);

const result = await viewOrderBasePage.isReturnProductsButtonVisible(page);
await expect(result).to.be.true;
});
});

describe('FO : Create merchandise returns', async () => {
it('should view my shop', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFO', baseContext);

page = await viewOrderBasePage.viewMyShop(page);
await homePage.changeLanguage(page, 'en');

const isHomePage = await homePage.isHomePage(page);
await expect(isHomePage, 'Home page is not displayed').to.be.true;
});

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

await homePage.goToMyAccountPage(page);

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

it('should go to \'Order history and details\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToOrderHistoryPage', baseContext);

await myAccountPage.goToHistoryAndDetailsPage(page);

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

it('should go to the first order in the list and check the existence of order return form', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'isOrderReturnFormVisible', baseContext);

await orderHistoryPage.goToDetailsPage(page, 1);

const result = await orderDetailsPage.isOrderReturnFormVisible(page);
await expect(result).to.be.true;
});

it('should create a merchandise return', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'createMerchandiseReturn', baseContext);

await orderDetailsPage.requestMerchandiseReturn(page,
'test',
3,
[{quantity: 1}, {quantity: 1}, {quantity: 2}]);

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

it('should close the FO page and go back to BO', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'closeFoAndGoBackToBO', baseContext);

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

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

describe('BO : Delete products from merchandise return', async () => {
[
{args: {understandTheRisk: false, button: 'Take me out of here!'}},
{args: {understandTheRisk: true, button: 'I understand the risks and I really want to display this page'}},
].forEach((test, index: number) => {
it('should go to \'Customer Service > Merchandise Returns\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', `goToMerchandiseReturnsPage${index}`, baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.customerServiceParentLink,
dashboardPage.merchandiseReturnsLink,
);

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

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

await merchandiseReturnsPage.goToMerchandiseReturnPage(page);

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

it(`should delete the first returned product and click on '${test.args.button}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `deleteFirstProduct${index}`, baseContext);

const text = await editMerchandiseReturnsPage.deleteProduct(page, 1, test.args.understandTheRisk);

if (test.args.understandTheRisk) {
await expect(text).to.contains(editMerchandiseReturnsPage.successfulUpdateMessage);
} else {
await expect(text).to.eq(dashboardPage.pageTitle);
}
});
});

it('should go to edit merchandise returns page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToEditReturnsPage3', baseContext);

await merchandiseReturnsPage.goToMerchandiseReturnPage(page);

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

it('should try to delete the last returned product and check the error message', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'deleteLastProduct', baseContext);

const errorMessage = await editMerchandiseReturnsPage.clickOnDeleteLastProductButton(page);
await expect(errorMessage).to.contains(merchandiseReturnsPage.errorDeletionMessage);
});
});

describe('POST-TEST: Disable merchandise returns', async () => {
it('should disable merchandise returns', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'disableReturns', baseContext);

const result = await merchandiseReturnsPage.setOrderReturnStatus(page, false);
await expect(result).to.contains(merchandiseReturnsPage.successfulUpdateMessage);
});
});
});