/
01_deleteEmptyCategory.js
137 lines (124 loc) · 5.75 KB
/
01_deleteEmptyCategory.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require('module-alias/register');
// Using chai
const {expect} = require('chai');
const helper = require('@utils/helpers');
const files = require('@utils/files');
const loginCommon = require('@commonTests/loginBO');
// Importing pages
const BOBasePage = require('@pages/BO/BObasePage');
const LoginPage = require('@pages/BO/login');
const DashboardPage = require('@pages/BO/dashboard');
const CategoriesPage = require('@pages/BO/catalog/categories');
const AddCategoryPage = require('@pages/BO/catalog/categories/add');
const MonitoringPage = require('@pages/BO/catalog/monitoring');
const CategoryFaker = require('@data/faker/category');
let browser;
let page;
let numberOfCategories = 0;
let numberOfEmptyCategories = 0;
const createCategoryData = new CategoryFaker();
// Init objects needed
const init = async function () {
return {
boBasePage: new BOBasePage(page),
loginPage: new LoginPage(page),
dashboardPage: new DashboardPage(page),
categoriesPage: new CategoriesPage(page),
addCategoryPage: new AddCategoryPage(page),
monitoringPage: new MonitoringPage(page),
};
};
/*
Create new category
Check existence of new category in monitoring page
Delete category and check deletion in categories page
*/
describe('Create empty category and delete it from monitoring page', async () => {
// before and after functions
before(async function () {
browser = await helper.createBrowser();
page = await helper.newTab(browser);
this.pageObjects = await init();
});
after(async () => {
await helper.closeBrowser(browser);
/* Delete the generated image */
await files.deleteFile(`${createCategoryData.name}.jpg`);
});
// Login into BO and go to categories page
loginCommon.loginBO();
it('should go to catalog > categories page', async function () {
await this.pageObjects.boBasePage.goToSubMenu(
this.pageObjects.boBasePage.catalogParentLink,
this.pageObjects.boBasePage.categoriesLink,
);
await this.pageObjects.boBasePage.closeSfToolBar();
const pageTitle = await this.pageObjects.categoriesPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.categoriesPage.pageTitle);
});
it('should reset all filters and get number of categories in BO', async function () {
numberOfCategories = await this.pageObjects.categoriesPage.resetAndGetNumberOfLines();
await expect(numberOfCategories).to.be.above(0);
});
describe('Create empty category in BO', async () => {
it('should go to add new category page', async function () {
await this.pageObjects.categoriesPage.goToAddNewCategoryPage();
const pageTitle = await this.pageObjects.addCategoryPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.addCategoryPage.pageTitleCreate);
});
it('should create category and check the categories number', async function () {
const textResult = await this.pageObjects.addCategoryPage.createEditCategory(createCategoryData);
await expect(textResult).to.equal(this.pageObjects.categoriesPage.successfulCreationMessage);
const numberOfCategoriesAfterCreation = await this.pageObjects.categoriesPage.getNumberOfElementInGrid();
await expect(numberOfCategoriesAfterCreation).to.be.equal(numberOfCategories + 1);
});
});
describe('Check created category in monitoring page', async () => {
it('should go to catalog > monitoring page', async function () {
await this.pageObjects.categoriesPage.goToSubMenu(
this.pageObjects.boBasePage.catalogParentLink,
this.pageObjects.boBasePage.monitoringLink,
);
const pageTitle = await this.pageObjects.monitoringPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.monitoringPage.pageTitle);
numberOfEmptyCategories = await this.pageObjects.monitoringPage.resetAndGetNumberOfLines('empty_category');
await expect(numberOfEmptyCategories).to.be.at.least(1);
});
it('should filter categories grid and existence of new category', async function () {
await this.pageObjects.monitoringPage.filterTable(
'empty_category',
'input',
'name',
createCategoryData.name,
);
const textColumn = await this.pageObjects.monitoringPage.getTextColumnFromTable('empty_category', 1, 'name');
await expect(textColumn).to.contains(createCategoryData.name);
});
it('should reset filter in empty categories grid', async function () {
numberOfEmptyCategories = await this.pageObjects.monitoringPage.resetAndGetNumberOfLines('empty_category');
await expect(numberOfEmptyCategories).to.be.at.least(1);
});
});
describe('Delete category from monitoring page', async () => {
it('should filter categories grid', async function () {
await this.pageObjects.monitoringPage.filterTable(
'empty_category',
'input',
'name',
createCategoryData.name,
);
const textColumn = await this.pageObjects.monitoringPage.getTextColumnFromTable('empty_category', 1, 'name');
await expect(textColumn).to.contains(createCategoryData.name);
});
it('should delete category', async function () {
const textResult = await this.pageObjects.monitoringPage.deleteCategoryInGrid('empty_category', 1, 1);
await expect(textResult).to.equal(this.pageObjects.monitoringPage.successfulDeleteMessage);
const pageTitle = await this.pageObjects.categoriesPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.categoriesPage.pageTitle);
});
it('should reset filter check number of categories', async function () {
const numberOfCategoriesAfterDelete = await this.pageObjects.categoriesPage.resetAndGetNumberOfLines();
await expect(numberOfCategoriesAfterDelete).to.be.equal(numberOfCategories);
});
});
});