Skip to content

Commit

Permalink
Merge branch 'PrestaShop:develop' into 35591-b3-migrated-attribute-pa…
Browse files Browse the repository at this point in the history
…ges-bug-3
  • Loading branch information
mattgoud authored Apr 23, 2024
2 parents 14585a3 + 5ff70cd commit e1a0df1
Show file tree
Hide file tree
Showing 9 changed files with 1,184 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
// Import utils
import api from '@utils/api';
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import commonTests
import {deleteAPIClientTest} from '@commonTests/BO/advancedParameters/authServer';
import loginCommon from '@commonTests/BO/loginBO';

// Import pages
import apiClientPage from 'pages/BO/advancedParameters/APIClient';
import addNewApiClientPage from '@pages/BO/advancedParameters/APIClient/add';
import productsPage from '@pages/BO/catalog/products';
import createProductsPage from '@pages/BO/catalog/products/add';
import descriptionTab from '@pages/BO/catalog/products/add/descriptionTab';
import dashboardPage from '@pages/BO/dashboard';

// Import data
import Languages from '@data/demo/languages';
import Products from '@data/demo/products';
import APIClientData from '@data/faker/APIClient';

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

const baseContext: string = 'functional_API_endpoints_product_getProductIdImages';

describe('API : GET /product/{productId}/images', async () => {
let apiContext: APIRequestContext;
let browserContext: BrowserContext;
let page: Page;
let accessToken: string;
let clientSecret: string;
let jsonResponse: any;

const clientScope: string = 'product_read';
const clientData: APIClientData = new APIClientData({
enabled: true,
scopes: [
clientScope,
],
});

describe('GET /product/{productId}/images', async () => {
before(async function () {
browserContext = await helper.createBrowserContext(this.browser);
page = await helper.newTab(browserContext);

apiContext = await helper.createAPIContext(global.API.URL);
});

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

describe('BackOffice : Fetch the access token', async () => {
it('should login in BO', async function () {
await loginCommon.loginBO(this, page);
});

it('should go to \'Advanced Parameters > API Client\' page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToAdminAPIPage', baseContext);

await dashboardPage.goToSubMenu(
page,
dashboardPage.advancedParametersLink,
dashboardPage.adminAPILink,
);

const pageTitle = await apiClientPage.getPageTitle(page);
expect(pageTitle).to.eq(apiClientPage.pageTitle);
});

it('should check that no records found', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkThatNoRecordFound', baseContext);

const noRecordsFoundText = await apiClientPage.getTextForEmptyTable(page);
expect(noRecordsFoundText).to.contains('warning No records found');
});

it('should go to add New API Client page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'goToNewAPIClientPage', baseContext);

await apiClientPage.goToNewAPIClientPage(page);

const pageTitle = await addNewApiClientPage.getPageTitle(page);
expect(pageTitle).to.eq(addNewApiClientPage.pageTitleCreate);
});

it('should create API Client', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'createAPIClient', baseContext);

const textResult = await addNewApiClientPage.addAPIClient(page, clientData);
expect(textResult).to.contains(addNewApiClientPage.successfulCreationMessage);

const textMessage = await addNewApiClientPage.getAlertInfoBlockParagraphContent(page);
expect(textMessage).to.contains(addNewApiClientPage.apiClientGeneratedMessage);
});

it('should copy client secret', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'copyClientSecret', baseContext);

await addNewApiClientPage.copyClientSecret(page);

clientSecret = await addNewApiClientPage.getClipboardText(page);
expect(clientSecret.length).to.be.gt(0);
});

it('should request the endpoint /access_token', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'requestOauth2Token', baseContext);

const apiResponse = await apiContext.post('access_token', {
form: {
client_id: clientData.clientId,
client_secret: clientSecret,
grant_type: 'client_credentials',
scope: clientScope,
},
});
expect(apiResponse.status()).to.eq(200);
expect(api.hasResponseHeader(apiResponse, 'Content-Type')).to.eq(true);
expect(api.getResponseHeader(apiResponse, 'Content-Type')).to.contains('application/json');

const jsonResponse = await apiResponse.json();
expect(jsonResponse).to.have.property('access_token');
expect(jsonResponse.token_type).to.be.a('string');

accessToken = jsonResponse.access_token;
});
});

describe('API : Create the Product Image', async () => {
it('should request the endpoint /product/{productId}/image', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'requestEndpoint', baseContext);

const apiResponse = await apiContext.get(`product/${Products.demo_1.id}/images`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

expect(apiResponse.status()).to.eq(200);
expect(api.hasResponseHeader(apiResponse, 'Content-Type')).to.eq(true);
expect(api.getResponseHeader(apiResponse, 'Content-Type')).to.contains('application/json');

jsonResponse = await apiResponse.json();
});

it('should check the JSON Response keys', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkResponseKeys', baseContext);

expect(jsonResponse.length).to.be.gt(0);

for (let i:number = 0; i < jsonResponse.length; i++) {
expect(jsonResponse[i]).to.have.all.keys(
'imageId',
'imageUrl',
'thumbnailUrl',
'legends',
'cover',
'position',
'shopIds',
);

expect(jsonResponse[i].imageId).to.be.gt(0);
expect(jsonResponse[i].imageUrl).to.be.a('string');
expect(jsonResponse[i].thumbnailUrl).to.be.a('string');
expect(jsonResponse[i].legends[Languages.english.id]).to.be.a('string');
expect(jsonResponse[i].legends[Languages.french.id]).to.be.a('string');
expect(jsonResponse[i].cover).to.be.a('boolean');
expect(jsonResponse[i].position).to.be.a('number');
expect(jsonResponse[i].shopIds).to.be.a('array');
}
});
});

describe('BackOffice : Check the Product Images', async () => {
it('should go to \'Catalog > 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 filter list by name', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'filterProduct', baseContext);

await productsPage.resetFilter(page);
await productsPage.filterProducts(page, 'product_name', Products.demo_1.name);

const numProducts = await productsPage.getNumberOfProductsFromList(page);
expect(numProducts).to.be.equal(1);

const productName = await productsPage.getTextColumn(page, 'product_name', 1);
expect(productName).to.contains(Products.demo_1.name);
});

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

await productsPage.goToProductPage(page, 1);

const pageTitle: string = await createProductsPage.getPageTitle(page);
expect(pageTitle).to.contains(createProductsPage.pageTitle);

const numImages = await descriptionTab.getNumberOfImages(page);
expect(numImages).to.be.equals(jsonResponse.length);
});

it('should fetch images informations', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'checkJSONItems', baseContext);

for (let idxItem: number = 0; idxItem < jsonResponse.length; idxItem++) {
const productImageInformation = await descriptionTab.getProductImageInformation(page, idxItem + 1);

expect(productImageInformation.id).to.equal(jsonResponse[idxItem].imageId);

expect(productImageInformation.caption.en).to.equal(jsonResponse[idxItem].legends[Languages.english.id]);
expect(productImageInformation.caption.fr).to.equal(jsonResponse[idxItem].legends[Languages.french.id]);

expect(productImageInformation.isCover).to.equal(jsonResponse[idxItem].cover);

expect(productImageInformation.position).to.equal(jsonResponse[idxItem].position);
}
});
});
});

// Post-condition: Delete an API Client
deleteAPIClientTest(`${baseContext}_postTest_0`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Import utils
import helper from '@utils/helpers';
import testContext from '@utils/testContext';

// Import pages
import {homePage} from '@pages/FO/classic/home';
import {productPage} from '@pages/FO/classic/product';
import {blockCartModal} from '@pages/FO/classic/modal/blockCart';
import {cartPage} from '@pages/FO/classic/cart';

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

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

const baseContext: string = 'functional_FO_classic_productPage_productPage_changeQuantity';

/*
Scenario:
- Go to FO
- Go to the third product in the list
- Click up/down on quantity input
- Set quantity input (good/bad value)
*/
describe('FO - Product page : Change quantity', 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);
});

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

await homePage.goToFo(page);

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

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

await homePage.goToProductPage(page, 3);

const pageTitle = await productPage.getPageTitle(page);
expect(pageTitle.toUpperCase()).to.contains(Products.demo_6.name.toUpperCase());
});

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

await productPage.setQuantityByArrowUpDown(page, 5, 'up');

const productQuantity = await productPage.getProductQuantity(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 productPage.setQuantityByArrowUpDown(page, 1, 'down');

const productQuantity = await productPage.getProductQuantity(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 productPage.setQuantity(page, 12);
await productPage.clickOnAddToCartButton(page);

const isVisible = await blockCartModal.isBlockCartModalVisible(page);
expect(isVisible).to.equal(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 blockCartModal.continueShopping(page);
expect(isNotVisible).to.equal(true);
});

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

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

it('should set \'-24\' in the quantity input', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateQuantityByInput2', baseContext);

await productPage.setQuantity(page, '-24');
await productPage.clickOnAddToCartButton(page);

const isVisible = await blockCartModal.isBlockCartModalVisible(page);
expect(isVisible).to.equal(true);
});

it('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 blockCartModal.continueShopping(page);
expect(isNotVisible).to.equal(true);
});

it('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(13);
});

it('should set \'Prestashop\' in the quantity input and proceed to checkout', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'updateQuantityByInput3', baseContext);

await productPage.addProductToTheCart(page, 'Prestashop');

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

it('should remove product from shopping cart', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'removeProduct', baseContext);

await cartPage.deleteProduct(page, 1);

const notificationNumber = await cartPage.getCartNotificationsNumber(page);
expect(notificationNumber).to.equal(0);
});
});
Loading

0 comments on commit e1a0df1

Please sign in to comment.