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 filter contacts tests #16909

Merged
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
16 changes: 16 additions & 0 deletions tests/puppeteer/campaigns/data/demo/contacts.js
@@ -0,0 +1,16 @@
module.exports = {
Contacts: {
webmaster: {
id: 1,
title: 'Webmaster',
email: 'demo@prestashop.com',
description: 'If a technical problem occurs on this website',
},
customerService: {
id: 2,
title: 'Customer service',
email: 'demo@prestashop.com',
description: 'For any question about a product, an order',
},
},
};
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,89 @@
require('module-alias/register');
// Using chai
const {expect} = require('chai');
const helper = require('@utils/helpers');
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 ContactsPage = require('@pages/BO/shopParameters/contact/index');
// Importing data
const {Contacts} = require('@data/demo/contacts');

let browser;
let page;
let numberOfContacts = 0;

// Init objects needed
const init = async function () {
return {
boBasePage: new BOBasePage(page),
loginPage: new LoginPage(page),
dashboardPage: new DashboardPage(page),
contactsPage: new ContactsPage(page),
};
};

// Filter Contacts
describe('Filter Contacts', async () => {
// before and after functions
before(async function () {
browser = await helper.createBrowser();
page = await helper.newTab(browser);
this.pageObjects = await init();
NeOMakinG marked this conversation as resolved.
Show resolved Hide resolved
});
after(async () => {
await helper.closeBrowser(browser);
});

// Login into BO and go to contact page
loginCommon.loginBO();

it('should go to \'Shop parameters>Contact\' page', async function () {
await this.pageObjects.boBasePage.goToSubMenu(
this.pageObjects.boBasePage.shopParametersParentLink,
this.pageObjects.boBasePage.contactLink,
);
await this.pageObjects.boBasePage.closeSfToolBar();
const pageTitle = await this.pageObjects.contactsPage.getPageTitle();
await expect(pageTitle).to.contains(this.pageObjects.contactsPage.pageTitle);
});

it('should reset all filters and get number of contacts in BO', async function () {
numberOfContacts = await this.pageObjects.contactsPage.resetAndGetNumberOfLines();
await expect(numberOfContacts).to.be.above(0);
});
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
// 1 : Filter Contacts with all inputs and selects in grid table
describe('Filter Contacts', async () => {
const tests = [
{args: {filterBy: 'id_contact', filterValue: Contacts.webmaster.id}},
{args: {filterBy: 'name', filterValue: Contacts.customerService.title}},
{args: {filterBy: 'email', filterValue: Contacts.webmaster.email}},
{args: {filterBy: 'description', filterValue: Contacts.customerService.description}},
];

tests.forEach((test) => {
it(`should filter by ${test.args.filterBy} '${test.args.filterValue}'`, async function () {
await this.pageObjects.contactsPage.filterContacts(
test.args.filterBy,
test.args.filterValue,
);
const numberOfContactsAfterFilter = await this.pageObjects.contactsPage.getNumberOfElementInGrid();
await expect(numberOfContactsAfterFilter).to.be.at.most(numberOfContacts);
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
for (let i = 1; i <= numberOfContactsAfterFilter; i++) {
const textColumn = await this.pageObjects.contactsPage.getTextColumnFromTableContacts(
i,
test.args.filterBy,
);
await expect(textColumn).to.contains(test.args.filterValue);
}
});

it('should reset all filters', async function () {
const numberOfContactsAfterReset = await this.pageObjects.contactsPage.resetAndGetNumberOfLines();
await expect(numberOfContactsAfterReset).to.equal(numberOfContacts);
});
});
});
});
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions tests/puppeteer/pages/BO/BObasePage.js
Expand Up @@ -75,6 +75,8 @@ module.exports = class BOBasePage extends CommonPage {
// Shop Parameters
this.shopParametersParentLink = '#subtab-ShopParameters';
this.shopParametersGeneralLink = '#subtab-AdminParentPreferences';
// Contact
this.contactLink = '#subtab-AdminParentStores';

// Advanced Parameters
this.advancedParametersLink = '#subtab-AdminAdvancedParameters';
Expand Down
79 changes: 79 additions & 0 deletions tests/puppeteer/pages/BO/shopParameters/contact/index.js
@@ -0,0 +1,79 @@
require('module-alias/register');
const BOBasePage = require('@pages/BO/BObasePage');

module.exports = class Contacts extends BOBasePage {
constructor(page) {
super(page);

this.pageTitle = 'Contacts';

// Selectors
// List of contacts
this.contactsGridPanel = '#contact_grid_panel';
this.contactsGridTitle = `${this.contactsGridPanel} h3.card-header-title`;
this.contactsListForm = '#contact_grid';
this.contactsListTableRow = `${this.contactsListForm} tbody tr:nth-child(%ROW)`;
this.contactsListTableColumn = `${this.contactsListTableRow} td.column-%COLUMN`;
// Filters
this.contactFilterInput = `${this.contactsListForm} #contact_%FILTERBY`;
this.filterSearchButton = `${this.contactsListForm} button[name='contact[actions][search]']`;
this.filterResetButton = `${this.contactsListForm} button[name='contact[actions][reset]']`;
}

/*
Methods
*/

/**
* Reset input filters
* @return {Promise<integer>}
*/
async resetFilter() {
if (!(await this.elementNotVisible(this.filterResetButton, 2000))) {
await this.clickAndWaitForNavigation(this.filterResetButton);
}
}

/**
* get number of elements in grid
* @return {Promise<integer>}
*/
async getNumberOfElementInGrid() {
return this.getNumberFromText(this.contactsGridTitle);
}

/**
* Reset Filter And get number of elements in list
* @return {Promise<integer>}
*/
async resetAndGetNumberOfLines() {
await this.resetFilter();
return this.getNumberOfElementInGrid();
}

/**
* Filter list of contacts
* @param filterBy, column to filter
* @param value, value to filter with
* @return {Promise<void>}
*/
async filterContacts(filterBy, value = '') {
await this.setValue(this.contactFilterInput.replace('%FILTERBY', filterBy), value.toString());
// click on search
await this.clickAndWaitForNavigation(this.filterSearchButton);
}

/**
* get text from a column
* @param row, row in table
* @param column, which column
* @return {Promise<textContent>}
*/
async getTextColumnFromTableContacts(row, column) {
return this.getTextContent(
this.contactsListTableColumn
.replace('%ROW', row)
.replace('%COLUMN', column),
);
}
};
nesrineabdmouleh marked this conversation as resolved.
Show resolved Hide resolved