UNPKG

e2ed

Version:

E2E testing framework over Playwright

58 lines (57 loc) 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.chooseTestRun = chooseTestRun; const assertValueIsDefined_1 = require("./assertValueIsDefined"); const maybeRenderApiStatistics_1 = require("./maybeRenderApiStatistics"); const render_1 = require("./render"); const assertValueIsDefined = assertValueIsDefined_1.assertValueIsDefined; const maybeRenderApiStatistics = maybeRenderApiStatistics_1.maybeRenderApiStatistics; const renderTestRunDetails = render_1.renderTestRunDetails; /** * Chooses `TestRun` (render chosen `TestRun` in right panel). * This base client function should not use scope variables (except other base functions). * @internal */ // eslint-disable-next-line max-statements function chooseTestRun(runHash) { const { e2edRightColumnContainer } = reportClientState; if (e2edRightColumnContainer === undefined) { // eslint-disable-next-line no-console console.error('Cannot find right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later'); return; } const previousHash = window.location.hash.replaceAll('#', ''); window.location.hash = runHash; if (reportClientState.testRunDetailsElementsByHash === undefined) { reportClientState.testRunDetailsElementsByHash = Object.create(null); } const { testRunDetailsElementsByHash } = reportClientState; const previousTestRunDetailsElement = e2edRightColumnContainer.firstElementChild; if (!previousTestRunDetailsElement) { return; } if (!(previousHash in testRunDetailsElementsByHash) && !previousTestRunDetailsElement.classList.contains('test-details-empty')) { testRunDetailsElementsByHash[previousHash] = previousTestRunDetailsElement; } if (runHash in testRunDetailsElementsByHash) { const e2edTestRunDetailsElement = testRunDetailsElementsByHash[runHash]; assertValueIsDefined(e2edTestRunDetailsElement); previousTestRunDetailsElement.replaceWith(e2edTestRunDetailsElement); return; } let rightColumnHtml = maybeRenderApiStatistics(runHash); if (rightColumnHtml === undefined) { const { fullTestRuns } = reportClientState; const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash); if (fullTestRun === undefined) { // eslint-disable-next-line no-console console.error(`Cannot find test run with hash ${runHash} in JSON report data. Probably JSON report data for this test run not yet loaded. Please try click again later`); return; } rightColumnHtml = renderTestRunDetails(fullTestRun); } e2edRightColumnContainer.innerHTML = String(rightColumnHtml); const nextTestRunDetailsElement = e2edRightColumnContainer.firstElementChild; testRunDetailsElementsByHash[runHash] = nextTestRunDetailsElement; }