Skip to content

Commit

Permalink
Merge pull request #341 from AliceO2Group/feature/O2B-387
Browse files Browse the repository at this point in the history
fixed homepage tests
  • Loading branch information
ekertt authored Apr 8, 2021
2 parents ab906dd + 7a95e9f commit c25fba1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
5 changes: 5 additions & 0 deletions lib/public/views/Logs/ActiveColumns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ const activeColumns = (model) => ({
* @return {Object} A collection of columns with parameters for the Log table
*/
export const activeHomeOverviewColumns = (model) => ({
id: {
name: 'Entry ID',
visible: false,
primary: true,
},
title: {
name: 'Title',
visible: true,
Expand Down
70 changes: 50 additions & 20 deletions test/public/home/overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
*/

const chai = require('chai');
const { defaultBefore, defaultAfter, getFirstRow } = require('../defaults');
const {
defaultBefore,
defaultAfter,
getFirstRow,
} = require('../defaults');

const { expect } = chai;

Expand Down Expand Up @@ -47,25 +51,51 @@ module.exports = () => {
firstRowId = await getFirstRow(table, page);

// We expect to find a table
expect(firstRowId).to.equal('rowundefined');
expect(firstRowId).to.equal('row129');
});

/*
* It('can navigate to a log detail page', async () => {
* const firstRow = await page.$('tr.clickable');
* const firstRowId = await firstRow.evaluate((row) => row.id);
* parsedFirstRowId = parseInt(firstRowId.slice('row'.length, firstRowId.length), 10);
*/

/*
* // We expect the entry page to have the same id as the id from the log overview
* await firstRow.evaluate((row) => row.click());
* await page.waitForTimeout(500);
*/

/*
* Const redirectedUrl = await page.url();
* expect(redirectedUrl).to.equal(`${url}/?page=log-detail&id=${parsedFirstRowId}`);
* });
*/
it('shows correct datatypes in respective columns', async () => {
table = await page.$$('tr');
firstRowId = await getFirstRow(table, page);

// Expectations of header texts being of a certain datatype
const headerDatatypes = {
runNumber: (number) => typeof number == 'number',
timeO2Start: (date) => !isNaN(Date.parse(date)),
timeO2End: (date) => !isNaN(Date.parse(date)),
};

// We find the headers matching the datatype keys
const headers = await page.$$('th');
const headerIndices = {};
for (const [index, header] of headers.entries()) {
const headerContent = await page.evaluate((element) => element.id, header);
const matchingDatatype = Object.keys(headerDatatypes).find((key) => headerContent === key);
if (matchingDatatype !== undefined) {
headerIndices[index] = matchingDatatype;
}
}

// We expect every value of a header matching a datatype key to actually be of that datatype
const firstRowCells = await page.$$(`#${firstRowId} td`);
for (const [index, cell] of firstRowCells.entries()) {
if (Object.keys(headerIndices).includes(index)) {
const cellContent = await page.evaluate((element) => element.innerText, cell);
const expectedDatatype = headerDatatypes[headerIndices[index]](cellContent);
expect(expectedDatatype).to.be.true;
}
}
});

it('can navigate to a detail page', async () => {
const firstRow = await page.$('tr.clickable');
const parsedFirstRowId = parseInt(firstRowId.slice('row'.length, firstRowId.length), 10);

// We expect the entry page to have the same id as the id from the log overview
await firstRow.evaluate((row) => row.click());
await page.waitForTimeout(500);

const redirectedUrl = await page.url();
expect(redirectedUrl).to.equal(`${url}/?page=log-detail&id=${parsedFirstRowId}`);
});
};

0 comments on commit c25fba1

Please sign in to comment.