Skip to content

Commit

Permalink
Make logs tests more tolerant when additional unexpected logs are put…
Browse files Browse the repository at this point in the history
… in the DB
  • Loading branch information
jolelievre committed Nov 19, 2024
1 parent 25bd000 commit 9e588b9
Showing 1 changed file with 80 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Sort logs table by : Id, Employee, Severity, Message, Object type, Object ID, Er
describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs table', async () => {
let browserContext: BrowserContext;
let page: Page;
let numberOfLogs: number = 0;
let numberOfLogs = 0;
const today = utilsDate.getDateFormat('mm/dd/yyyy');

// before and after functions
Expand Down Expand Up @@ -69,8 +69,8 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
const textResult = await logsPage.eraseAllLogs(page);
expect(textResult).to.equal(logsPage.successfulUpdateMessage);

numberOfLogs = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfLogs).to.be.equal(0);
const numberOfElements = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfElements).to.be.equal(0);
});

// Login and logout 11 times to have 11 logs
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
await testContext.addContextItem(this, 'testIdentifier', 'checkLogsNumber', baseContext);

const numberOfElements = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfElements).to.be.equal(11);
expect(numberOfElements).to.be.greaterThanOrEqual(11);
});
});

Expand All @@ -125,36 +125,40 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
const pageTitle = await logsPage.getPageTitle(page);
expect(pageTitle).to.contains(logsPage.pageTitle);

const numberOfElements = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfElements).to.be.equal(numberOfLogs + 11);
numberOfLogs = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfLogs).to.be.greaterThanOrEqual(11);
});

it('should change the items number to 10 per page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'changeItemNumberTo10', baseContext);

const pagesNb = Math.ceil(numberOfLogs / 10);
const paginationNumber = await logsPage.selectPaginationLimit(page, 10);
expect(paginationNumber).to.contains('(page 1 / 2)');
expect(paginationNumber).to.contains(`(page 1 / ${pagesNb})`);
});

it('should click on next', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnNext', baseContext);

const pagesNb = Math.ceil(numberOfLogs / 10);
const paginationNumber = await logsPage.paginationNext(page);
expect(paginationNumber).to.contains('(page 2 / 2)');
expect(paginationNumber).to.contains(`(page 2 / ${pagesNb})`);
});

it('should click on previous', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'clickOnPrevious', baseContext);

const pagesNb = Math.ceil(numberOfLogs / 10);
const paginationNumber = await logsPage.paginationPrevious(page);
expect(paginationNumber).to.contains('(page 1 / 2)');
expect(paginationNumber).to.contains(`(page 1 / ${pagesNb})`);
});

it('should change the items number to 20 per page', async function () {
await testContext.addContextItem(this, 'testIdentifier', 'changeItemNumberTo20', baseContext);

const pagesNb = Math.ceil(numberOfLogs / 20);
const paginationNumber = await logsPage.selectPaginationLimit(page, 20);
expect(paginationNumber).to.contains('(page 1 / 1)');
expect(paginationNumber).to.contains(`(page 1 / ${pagesNb})`);
});
});

Expand All @@ -167,7 +171,8 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
testIdentifier: 'filterById',
filterType: 'input',
filterBy: 'id_log',
filterValue: '50',
filterValue: 'numberOfLogs',
expectedCount: 1,
},
},
{
Expand All @@ -177,15 +182,27 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
filterType: 'input',
filterBy: 'employee',
filterValue: dataEmployees.defaultEmployee.lastName,
expectedCount: null,
},
},
{
args:
{
testIdentifier: 'filterBySeverity',
testIdentifier: 'filterBySeverityError',
filterType: 'input',
filterBy: 'severity',
filterValue: 'Error',
expectedCount: 0,
},
},
{
args:
{
testIdentifier: 'filterBySeverityInformativeOnly',
filterType: 'input',
filterBy: 'severity',
filterValue: 'Informative Only',
expectedCount: 'numberOfLogs',
},
},
{
Expand All @@ -194,7 +211,8 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
testIdentifier: 'filterByMessage',
filterType: 'input',
filterBy: 'message',
filterValue: 'Back office',
filterValue: 'Remember me',
expectedCount: 11,
},
},
{
Expand All @@ -204,53 +222,87 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
filterType: 'input',
filterBy: 'object_type',
filterValue: 'Cart',
expectedCount: 0,
},
},
{
args:
{
testIdentifier: 'filterByObjectID',
testIdentifier: 'filterByObjectIDTwo',
filterType: 'input',
filterBy: 'object_id',
filterValue: '2',
expectedCount: 0,
},
},
{
args:
{
testIdentifier: 'filterByObjectIDZero',
filterType: 'input',
filterBy: 'object_id',
filterValue: '0',
expectedCount: 'numberOfLogs',
},
},
{
args:
{
testIdentifier: 'filterByErrorCode',
testIdentifier: 'filterByErrorCodeOne',
filterType: 'input',
filterBy: 'error_code',
filterValue: '1',
expectedCount: 0,
},
},
{
args:
{
testIdentifier: 'filterByErrorCodeZero',
filterType: 'input',
filterBy: 'error_code',
filterValue: '0',
expectedCount: 'numberOfLogs',
},
},
].forEach((test) => {
it(`should filter by ${test.args.filterBy} '${test.args.filterValue}'`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.testIdentifier}`, baseContext);

const testValue = test.args.filterValue === 'numberOfLogs' ? String(numberOfLogs) : test.args.filterValue;
await logsPage.filterLogs(
page,
test.args.filterType,
test.args.filterBy,
test.args.filterValue,
testValue,
);

const expectedCount = test.args.expectedCount === 'numberOfLogs' ? numberOfLogs : test.args.expectedCount;
const numberOfLogsAfterFilter = await logsPage.getNumberOfElementInGrid(page);

expect(numberOfLogsAfterFilter).to.be.at.most(numberOfLogs + 11);
// If expected count is null, we don't expect any particular value
if (expectedCount !== null) {
expect(numberOfLogsAfterFilter).to.be.eq(expectedCount);
}

// There may be several pages of result, but we only check the first one
const elementsOnPage = Math.min(numberOfLogsAfterFilter, 20);

for (let i = 1; i <= numberOfLogsAfterFilter; i++) {
const textColumn = await logsPage.getTextColumn(page, i, test.args.filterBy);
if (expectedCount >= 1) {
for (let i = 1; i <= elementsOnPage; i++) {
const textColumn = await logsPage.getTextColumn(page, i, test.args.filterBy);

expect(textColumn).to.contains(test.args.filterValue);
// Lower case mostly needed because of Informative Only ("Only" in filter values, but "only" in column values)
expect(textColumn.toLowerCase()).to.contains(testValue.toLowerCase());
}
}
});

it('should reset all filters', async function () {
await testContext.addContextItem(this, 'testIdentifier', `${test.args.testIdentifier}Reset`, baseContext);

const numberOfLogsAfterReset = await logsPage.resetAndGetNumberOfLines(page);
expect(numberOfLogsAfterReset).to.equal(numberOfLogs + 11);
expect(numberOfLogsAfterReset).to.greaterThanOrEqual(11);
});
});

Expand All @@ -259,10 +311,13 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab

await logsPage.filterLogsByDate(page, today, today);

const numberOfEmailsAfterFilter = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfEmailsAfterFilter).to.be.at.most(numberOfLogs + 11);
const numberOfLogsAfterFilter = await logsPage.getNumberOfElementInGrid(page);
expect(numberOfLogsAfterFilter).to.be.at.greaterThanOrEqual(11);

// There may be several pages of result, but we only check the first one
const elementsOnPage = Math.min(numberOfLogsAfterFilter, 20);

for (let row: number = 1; row <= numberOfEmailsAfterFilter; row++) {
for (let row: number = 1; row <= elementsOnPage; row++) {
const textColumn = await logsPage.getTextColumn(page, row, 'date_add');
expect(textColumn).to.contains(today);
}
Expand All @@ -272,7 +327,7 @@ describe('BO - Advanced Parameters - Logs : Filter, sort and pagination logs tab
await testContext.addContextItem(this, 'testIdentifier', 'resetFilterAfterFilterByDate', baseContext);

const numberOfLogsAfterReset = await logsPage.resetAndGetNumberOfLines(page);
expect(numberOfLogsAfterReset).to.equal(numberOfLogs + 11);
expect(numberOfLogsAfterReset).to.greaterThanOrEqual(11);
});
});

Expand Down

0 comments on commit 9e588b9

Please sign in to comment.