e2ed
Version:
E2E testing framework over Playwright
58 lines (57 loc) • 3.01 kB
JavaScript
;
/* eslint-disable no-console */
Object.defineProperty(exports, "__esModule", { value: true });
exports.chooseTestRun = void 0;
const assertValueIsDefined_1 = require("./assertValueIsDefined");
const render_1 = require("./render");
const assertValueIsDefined = assertValueIsDefined_1.assertValueIsDefined;
const MaybeApiStatistics = render_1.MaybeApiStatistics;
const TestRunDetails = render_1.TestRunDetails;
/**
* 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
const chooseTestRun = (runHash) => {
const { e2edRightColumnContainer } = reportClientState;
if (!e2edRightColumnContainer) {
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) {
console.error('Cannot find first child element in right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later');
return;
}
if (!(previousHash in testRunDetailsElementsByHash) &&
!previousTestRunDetailsElement.classList.contains('empty-state')) {
testRunDetailsElementsByHash[previousHash] = previousTestRunDetailsElement;
}
if (runHash in testRunDetailsElementsByHash) {
const e2edTestRunDetailsElement = testRunDetailsElementsByHash[runHash];
assertValueIsDefined(e2edTestRunDetailsElement);
previousTestRunDetailsElement.replaceWith(e2edTestRunDetailsElement);
return;
}
let rightColumnHtml = jsx.createElement(MaybeApiStatistics, { runHash: runHash });
if (rightColumnHtml.length === 0) {
const { fullTestRuns } = reportClientState;
const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash);
if (fullTestRun === undefined) {
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 = jsx.createElement(TestRunDetails, { fullTestRun: fullTestRun });
}
e2edRightColumnContainer.innerHTML = String(rightColumnHtml);
const nextTestRunDetailsElement = e2edRightColumnContainer.firstElementChild;
testRunDetailsElementsByHash[runHash] = nextTestRunDetailsElement;
};
exports.chooseTestRun = chooseTestRun;