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 'FO > Hummingbird > Change quantity in quick view modal' #35430

Merged
merged 2 commits into from
Feb 21, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';
import files from '@utils/files';

// Import common tests
import {installHummingbird, uninstallHummingbird} from '@commonTests/FO/hummingbird';

// Import pages
import homePage from '@pages/FO/hummingbird/home';

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

const baseContext: string = 'functional_FO_hummingbird_productPage_quickView_changeQuantity';

/*
Pre-condition:
- Install hummingbird theme
Scenario:
- Go to FO
- Quick view third product
- Click up/down on quantity input
- Set quantity input (good/bad value)
Post-condition:
- Uninstall hummingbird theme
*/
describe('FO - Product page - Quick view : Change quantity', async () => {
let browserContext: BrowserContext;
let page: Page;

// Pre-condition : Install Hummingbird
installHummingbird(`${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);
await files.deleteFile('../../admin-dev/hummingbird.zip');
});

describe('Change quantity', async () => {
it('should go to FO home page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToFoToCreateAccount', baseContext);

await homePage.goToFo(page);

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

it('should quick view the third product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'quickView', baseContext);

await homePage.quickViewProduct(page, 3);

const isModalVisible = await homePage.isQuickViewProductModalVisible(page);
expect(isModalVisible).to.eq(true);
});

it('should change the quantity by using the arrow \'UP\' button', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'incrementQuantity', baseContext);

await homePage.setQuantityByArrowUpDown(page, 5, 'increment');

const productQuantity = await homePage.getProductQuantityFromQuickViewModal(page);
expect(productQuantity).to.equal(5);
});

it('should change the quantity by using the arrow \'Down\' button', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'incrementQuantity2', baseContext);

await homePage.setQuantityByArrowUpDown(page, 1, 'decrement');

const productQuantity = await homePage.getProductQuantityFromQuickViewModal(page);
expect(productQuantity).to.equal(1);
});

it('should add quantity of the product by setting input value', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateQuantityByInput', baseContext);

await homePage.changeQuantity(page, 12);
await homePage.addToCartByQuickView(page);

const isVisible = await homePage.isBlockCartModalVisible(page);
expect(isVisible).to.eq(true);
});

it('should click on continue shopping and check that the modal is not visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnContinueShopping', baseContext);

const isNotVisible = await homePage.continueShopping(page);
expect(isNotVisible).to.eq(true);
});

it('should check the cart notifications number', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNotificationsNumber', baseContext);

const notificationsNumber = await homePage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.equal(12);
});

it('should quick view the third product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'quickView2', baseContext);

await homePage.quickViewProduct(page, 3);

const isModalVisible = await homePage.isQuickViewProductModalVisible(page);
expect(isModalVisible).to.eq(true);
});

// @todo : https://github.com/PrestaShop/PrestaShop/issues/35219
it.skip('should set \'-24\' in the quantity input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateQuantityByInput2', baseContext);

await homePage.changeQuantity(page, '-24');
await homePage.addToCartByQuickView(page);

const isVisible = await homePage.isBlockCartModalVisible(page);
expect(isVisible).to.eq(true);
});

it.skip('should click on continue shopping and check that the modal is not visible', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnContinueShopping2', baseContext);

const isNotVisible = await homePage.continueShopping(page);
expect(isNotVisible).to.eq(true);
});

it.skip('should check the cart notifications number', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkNotificationsNumber2', baseContext);

const notificationsNumber = await homePage.getCartNotificationsNumber(page);
expect(notificationsNumber).to.equal(12);
});

it.skip('should quick view the third product', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'quickView3', baseContext);

await homePage.quickViewProduct(page, 3);

const isModalVisible = await homePage.isQuickViewProductModalVisible(page);
expect(isModalVisible).to.eq(true);
});

it('should set \'Prestashop\' in the quantity input and check that add to cart button is disabled', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateQuantityByInput3', baseContext);

await homePage.changeQuantity(page, 'Prestashop');
await homePage.addToCartByQuickView(page);

const isEnabled = await homePage.isAddToCartButtonEnabled(page);
expect(isEnabled, 'Add to cart button is not disabled').to.eq(false);
});
});

// Post-condition : Uninstall Hummingbird
uninstallHummingbird(`${baseContext}_postTest`);
});
33 changes: 31 additions & 2 deletions tests/UI/pages/FO/classic/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class HomePage extends FOBasePage {

protected blockCartModalCloseButton: string;

protected productRowQuantityUpDownButton: (direction: string) => string;

private readonly cartModalProductNameBlock: string;

private readonly cartModalProductPriceBlock: string;
Expand Down Expand Up @@ -206,6 +208,8 @@ class HomePage extends FOBasePage {
this.quickViewTwitterSocialSharing = `${this.quickViewModalDiv} .twitter a`;
this.quickViewPinterestSocialSharing = `${this.quickViewModalDiv} .pinterest a`;
this.addToCartButton = `${this.quickViewModalDiv} button[data-button-action='add-to-cart']`;
this.productRowQuantityUpDownButton = (direction: string) => 'span.input-group-btn-vertical'
+ ` button.bootstrap-touchspin-${direction}`;

// Block Cart Modal
this.blockCartModalDiv = '#blockcart-modal';
Expand Down Expand Up @@ -348,7 +352,7 @@ class HomePage extends FOBasePage {
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async hasProductsBlock(page: Page, blockName: 'bestsellers'|'newproducts'|'onsale'|'popularproducts'): Promise<boolean> {
async hasProductsBlock(page: Page, blockName: 'bestsellers' | 'newproducts' | 'onsale' | 'popularproducts'): Promise<boolean> {
return (await page.locator(this.productsBlock(blockName)).count()) > 0;
}

Expand Down Expand Up @@ -508,10 +512,35 @@ class HomePage extends FOBasePage {
* @param quantity {number} The product quantity to change
* @returns {Promise<void>}
*/
async changeQuantity(page: Page, quantity: number): Promise<void> {
async changeQuantity(page: Page, quantity: number | string): Promise<void> {
await this.setValue(page, this.quickViewQuantityWantedInput, quantity);
}

/**
* Get product quantity from quick view modal
* @param page {Page} Browser tab
* @returns {Promise<number>}
*/
async getProductQuantityFromQuickViewModal(page: Page): Promise<number> {
return parseInt(await page.locator(this.quickViewQuantityWantedInput).evaluate((node: HTMLSelectElement) => node.value), 10);
}

/**
* Update quantity value arrow up down in quick view modal
* @param page {Page} Browser tab
* @param quantityWanted {number} Value to add/subtract from quantity
* @param direction {string} Direction to click on
* @returns {Promise<string>}
*/
async setQuantityByArrowUpDown(page: Page, quantityWanted: number, direction: string): Promise<void> {
const inputValue = await this.getProductQuantityFromQuickViewModal(page);
const nbClick: number = Math.abs(inputValue - quantityWanted);

for (let i = 0; i < nbClick; i++) {
await page.locator(this.productRowQuantityUpDownButton(direction)).click();
}
}

/**
* Click on add to cart button from quick view modal
* @param page {Page} Browser tab
Expand Down
1 change: 1 addition & 0 deletions tests/UI/pages/FO/hummingbird/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Home extends HomePage {
this.productImg = (number: number) => `${this.productArticle(number)} img`;
this.productQuickViewLink = (number: number) => `${this.productArticle(number)} .product-miniature__quickview button`;
this.blockCartModalCloseButton = `${this.blockCartModalDiv} button.btn-close`;
this.productRowQuantityUpDownButton = (direction: string) => `div.product-actions__quantity button.js-${direction}-button`;

// Block cart modal
this.blockCartModalSummary = '.blockcart-modal__summery';
Expand Down