diff --git a/test/public/envs/detailsPage.test.js b/test/public/envs/detailsPage.test.js index cb0919a73e..1b7a437fc9 100644 --- a/test/public/envs/detailsPage.test.js +++ b/test/public/envs/detailsPage.test.js @@ -27,6 +27,20 @@ const { resetDatabaseContent } = require('../../utilities/resetDatabaseContent.j const { expect } = chai; +/** + * Navigate directly to the details page of the given environment and wait for it to be rendered + * + * Each test that needs a specific environment loads it itself, so that a failure in one test does not cascade to the next ones + * + * @param {puppeteer.Page} page the puppeteer page + * @param {string} environmentId the id of the environment to display + * @return {Promise} resolves once the environment details are displayed + */ +const goToEnvironmentDetails = async (page, environmentId) => { + await goToPage(page, 'env-details', { queryParameters: { environmentId } }); + await expectInnerText(page, 'h2', `Environment ${environmentId}`); +}; + module.exports = () => { let page; let browser; @@ -46,14 +60,11 @@ module.exports = () => { }); it('Should successfully load environment\'s details page', async () => { - await goToPage(page, 'env-details', { queryParameters: { environmentId: 'TDI59So3d' } }); - await expectInnerText(page, 'h2', 'Environment TDI59So3d'); + await goToEnvironmentDetails(page, 'TDI59So3d'); }); it('Should successfully display the current environment\'s status', async () => { - const statusBadge = await page.waitForSelector('#environment-status-badge'); - expect(await statusBadge.evaluate((element) => element.classList.contains('badge'))).to.be.true; - expect(await statusBadge.evaluate((element) => element.innerText)).to.equal('DESTROYED'); + await expectInnerText(page, '#environment-status-badge.badge', 'DESTROYED'); }); it('Should successfully display the creation date of the environment', async () => { @@ -61,47 +72,47 @@ module.exports = () => { }); it('Should successfully display the history of the environment', async () => { - const historyItems = await page.$$('.history-item'); - expect(historyItems).to.have.lengthOf(4); - expect(await historyItems[0].$eval('.badge', (element) => element.innerText)).to.equal('CONFIGURED'); - expect(await historyItems[1].$eval('.badge', (element) => element.innerText)).to.equal('RUNNING'); - expect(await historyItems[2].$eval('.badge', (element) => element.innerText)).to.equal('DEPLOYED'); - expect(await historyItems[3].$eval('.badge', (element) => element.innerText)).to.equal('DESTROYED'); + await page.waitForFunction(() => document.querySelectorAll('.history-item').length === 4); + const historyStatuses = await page.$$eval('.history-item .badge', (badges) => badges.map((badge) => badge.innerText)); + expect(historyStatuses).to.eql(['CONFIGURED', 'RUNNING', 'DEPLOYED', 'DESTROYED']); }); it('Should successfully display the runs related to the environment', async () => { - const runsRows = await page.$$('#runs-pane tbody tr'); - expect(runsRows).to.have.lengthOf(3); - expect(await runsRows[0].$eval('td:first-of-type', (element) => element.innerText)).to.equal('103'); - expect(await runsRows[1].$eval('td:first-of-type', (element) => element.innerText)).to.equal('104'); - expect(await runsRows[2].$eval('td:first-of-type', (element) => element.innerText)).to.equal('105'); + await page.waitForFunction(() => document.querySelectorAll('#runs-pane tbody tr').length === 3); + const runNumbers = await page.$$eval('#runs-pane tbody tr td:first-of-type', (cells) => cells.map((cell) => cell.innerText)); + expect(runNumbers).to.eql(['103', '104', '105']); }); it('should successfully expose a button to create a new log related to the displayed environment', async () => { await waitForNavigation(page, () => pressElement(page, '#create-log')); expectUrlParams(page, { page: 'log-create', environmentIds: 'TDI59So3d', runNumbers: '103,104,105' }); - await page.waitForSelector('input#environments'); - expect(await page.$eval('input#environments', (element) => element.value)).to.equal('TDI59So3d'); - await waitForNavigation(page, () => pressElement(page, '#env-overview')); + await page.waitForFunction(() => document.querySelector('input#environments')?.value === 'TDI59So3d'); }); - it('should successfully provide a tab to display related logs', async () => { - await waitForNavigation(page, () => pressElement(page, '#row8E4aZTjY a:first-of-type')); - await pressElement(page, '#logs-tab'); + it('should successfully navigate from the environments overview to an environment\'s details page', async () => { + await goToPage(page, 'env-overview'); - const tableSelector = '#logs-pane table tbody tr'; - await page.waitForSelector(tableSelector); + /* + * The overview table can be re-rendered (loading state then new rows) between the moment the row is found and the moment it is + * clicked, so use a JS click that finds and clicks the link in one go + */ + await waitForNavigation(page, () => pressElement(page, '#row8E4aZTjY a:first-of-type', true)); + expectUrlParams(page, { page: 'env-details', environmentId: '8E4aZTjY' }); + await expectInnerText(page, 'h2', 'Environment 8E4aZTjY'); + }); - const table = await page.$$(tableSelector); - expect(table).to.lengthOf(3); + it('should successfully provide a tab to display related logs', async () => { + await goToEnvironmentDetails(page, '8E4aZTjY'); + await pressElement(page, '#logs-tab'); - expect(await table[0].evaluate((row) => row.id)).to.equal('row1'); - expect(await table[1].evaluate((row) => row.id)).to.equal('row3'); - expect(await table[2].evaluate((row) => row.id)).to.equal('row4'); + await waitForTableLength(page, 3); + const rowIds = await page.$$eval('#logs-pane table tbody tr', (rows) => rows.map((row) => row.id)); + expect(rowIds).to.eql(['row1', 'row3', 'row4']); }); - it('should successfully provide a tab to display environment configuration', async () => { + it('should successfully display a message when environment has no raw configuration', async () => { + await goToEnvironmentDetails(page, '8E4aZTjY'); await pressElement(page, '#raw-configuration-tab'); await expectInnerText( @@ -109,45 +120,30 @@ module.exports = () => { '#raw-configuration-pane', 'No raw configuration stored for this environment. It might have been stored in one of the logs', ); + }); - await waitForNavigation(page, () => pressElement(page, '#env-overview')); - await waitForNavigation(page, () => pressElement(page, '#rowDxi029djX a:first-of-type')); + it('should successfully provide a tab to display environment configuration', async () => { + await goToEnvironmentDetails(page, 'Dxi029djX'); await pressElement(page, '#raw-configuration-tab'); - await expectInnerText( - page, - '#raw-configuration-pane table #rowccdb_enabled-key-text', - 'ccdb_enabled', - ); - await expectInnerText( - page, - '#raw-configuration-pane table #rowccdb_enabled-value-text', - 'true', - ); - await expectInnerText( - page, - '#raw-configuration-pane table #rowdcs_enabled-key-text', - 'dcs_enabled', - ); - await expectInnerText( - page, - '#raw-configuration-pane table #rowdcs_enabled-value-text', - 'false', - ); + await expectInnerText(page, '#raw-configuration-pane table #rowccdb_enabled-key-text', 'ccdb_enabled'); + await expectInnerText(page, '#raw-configuration-pane table #rowccdb_enabled-value-text', 'true'); + await expectInnerText(page, '#raw-configuration-pane table #rowdcs_enabled-key-text', 'dcs_enabled'); + await expectInnerText(page, '#raw-configuration-pane table #rowdcs_enabled-value-text', 'false'); + }); - await waitForNavigation(page, () => pressElement(page, '#env-overview')); - await waitForNavigation(page, () => pressElement(page, '#rowCmCvjNbg a:first-of-type')); + it('should successfully display environment configuration sorted by key', async () => { + await goToEnvironmentDetails(page, 'CmCvjNbg'); await pressElement(page, '#raw-configuration-tab'); await waitForTableLength(page, 20); - expect(await page.evaluate(() => { - const cellContents = Array.from(document.querySelectorAll('table tbody tr td:first-child')).map((element) => element.innerText); - return cellContents.every((v, i) => !i || v.localeCompare(cellContents[i - 1]) >= 0); - })).to.be.true; + const keys = await page.$$eval('#raw-configuration-pane table tbody tr td:first-child', (cells) => cells.map((cell) => cell.innerText)); + expect(keys).to.eql([...keys].sort((keyA, keyB) => keyA.localeCompare(keyB))); }); it('should successfully display FLP and ECS links', async () => { - const containerSelector = '.flex-row.w-100.g2.items-baseline.mb3'; + await goToEnvironmentDetails(page, 'CmCvjNbg'); + const containerSelector = 'h3.flex-row.w-100.g2.items-baseline.mb3'; await expectLink(page, `${containerSelector} a:nth-of-type(1)`, { href: