forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03_CRUDStandardProductWithCombinationsInBO.js
112 lines (109 loc) · 4.83 KB
/
03_CRUDStandardProductWithCombinationsInBO.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require('module-alias/register');
// Using chai
const {expect} = require('chai');
const helper = require('@utils/helpers');
const loginCommon = require('@commonTests/loginBO');
// importing pages
const LoginPage = require('@pages/BO/login');
const DashboardPage = require('@pages/BO/dashboard');
const BOBasePage = require('@pages/BO/BObasePage');
const ProductsPage = require('@pages/BO/products');
const AddProductPage = require('@pages/BO/addProduct');
const FOProductPage = require('@pages/FO/product');
const ProductFaker = require('@data/faker/product');
let browser;
let page;
let productWithCombinations;
let editedProductWithCombinations;
// creating pages objects in a function
const init = async function () {
return {
loginPage: new LoginPage(page),
dashboardPage: new DashboardPage(page),
boBasePage: new BOBasePage(page),
productsPage: new ProductsPage(page),
addProductPage: new AddProductPage(page),
foProductPage: new FOProductPage(page),
};
};
// Create, read, update and delete Standard product with combinations in BO
describe('Create, read, update and delete Standard product with combinations in BO', async () => {
// before and after functions
before(async function () {
browser = await helper.createBrowser();
page = await helper.newTab(browser);
this.pageObjects = await init();
const productToCreate = {
type: 'Standard product',
productHasCombinations: true,
};
productWithCombinations = await (new ProductFaker(productToCreate));
editedProductWithCombinations = await (new ProductFaker(productToCreate));
});
after(async () => {
await helper.closeBrowser(browser);
});
// Steps
loginCommon.loginBO();
it('should go to Products page', async function () {
await this.pageObjects.boBasePage.goToSubMenu(
this.pageObjects.boBasePage.productsParentLink,
this.pageObjects.boBasePage.productsLink,
);
await this.pageObjects.boBasePage.closeSfToolBar();
const pageTitle = await this.pageObjects.productsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.productsPage.pageTitle);
});
it('should reset all filters', async function () {
if (await this.pageObjects.productsPage.elementVisible(this.pageObjects.productsPage.filterResetButton, 2000)) {
await this.pageObjects.productsPage.resetFilter();
}
await this.pageObjects.productsPage.resetFilterCategory();
const numberOfProducts = await this.pageObjects.productsPage.getNumberOfProductsFromList();
await expect(numberOfProducts).to.be.above(0);
});
it('should create Product with Combinations', async function () {
await this.pageObjects.productsPage.goToAddProductPage();
const createProductMessage = await this.pageObjects.addProductPage.createEditProduct(productWithCombinations);
await expect(createProductMessage).to.equal(this.pageObjects.addProductPage.settingUpdatedMessage);
});
it('should preview and check product in FO', async function () {
page = await this.pageObjects.addProductPage.previewProduct();
this.pageObjects = await init();
const result = await this.pageObjects.foProductPage.checkProduct(productWithCombinations);
page = await this.pageObjects.foProductPage.closePage(browser, 1);
this.pageObjects = await init();
// Check that all Product attribute are correct
await Promise.all([
expect(result.name).to.be.true,
expect(result.price).to.be.true,
expect(result.quantity_wanted).to.be.true,
expect(result.description).to.be.true,
]);
});
it('should edit Product', async function () {
const createProductMessage = await this.pageObjects.addProductPage.createEditProduct(editedProductWithCombinations,
false);
await expect(createProductMessage).to.equal(this.pageObjects.addProductPage.settingUpdatedMessage);
});
it('should preview and check product in FO', async function () {
page = await this.pageObjects.addProductPage.previewProduct();
this.pageObjects = await init();
const result = await this.pageObjects.foProductPage.checkProduct(editedProductWithCombinations);
page = await this.pageObjects.foProductPage.closePage(browser, 1);
this.pageObjects = await init();
// Check that all Product attribute are correct
await Promise.all([
expect(result.name).to.be.true,
expect(result.price).to.be.true,
expect(result.quantity_wanted).to.be.true,
expect(result.description).to.be.true,
]);
});
it('should delete Product and be on product list page', async function () {
const testResult = await this.pageObjects.addProductPage.deleteProduct();
await expect(testResult).to.equal(this.pageObjects.productsPage.productDeletedSuccessfulMessage);
const pageTitle = await this.pageObjects.productsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.productsPage.pageTitle);
});
});