11import { assertValueIsDefined as clientAssertValueIsDefined } from './assertValueIsDefined' ;
2- import { renderTestRunDetails as clientRenderTestRunDetails } from './render' ;
3-
4- import type { ReportClientState , RunHash } from '../../../types/internal' ;
2+ import {
3+ renderApiStatistics as clientRenderApiStatistics ,
4+ renderTestRunDetails as clientRenderTestRunDetails ,
5+ } from './render' ;
6+
7+ import type {
8+ ApiStatisticsReportHash ,
9+ ReportClientState ,
10+ RunHash ,
11+ SafeHtml ,
12+ } from '../../../types/internal' ;
513
614const assertValueIsDefined : typeof clientAssertValueIsDefined = clientAssertValueIsDefined ;
15+ const renderApiStatistics = clientRenderApiStatistics ;
716const renderTestRunDetails = clientRenderTestRunDetails ;
817
9- declare const e2edTestRunDetailsContainer : HTMLElement ;
18+ declare const e2edRightColumnContainer : HTMLElement ;
1019declare const reportClientState : ReportClientState ;
1120
1221/**
13- * Chooses TestRun (render chosen TestRun in right panel).
22+ * Chooses ` TestRun` (render chosen ` TestRun` in right panel).
1423 * This base client function should not use scope variables (except other base functions).
1524 * @internal
1625 */
26+ // eslint-disable-next-line max-statements
1727export function chooseTestRun ( runHash : RunHash ) : void {
1828 const previousHash = window . location . hash as RunHash ;
1929
2030 window . location . hash = runHash ;
2131
2232 if ( reportClientState . testRunDetailsElementsByHash === undefined ) {
23- reportClientState . testRunDetailsElementsByHash = { } ;
33+ reportClientState . testRunDetailsElementsByHash = Object . create ( null ) as { } ;
2434 }
2535
2636 const { testRunDetailsElementsByHash} = reportClientState ;
2737
28- const previousTestRunDetailsElement =
29- e2edTestRunDetailsContainer . firstElementChild as HTMLElement ;
38+ const previousTestRunDetailsElement = e2edRightColumnContainer . firstElementChild as HTMLElement ;
3039
3140 if ( ! ( previousHash in testRunDetailsElementsByHash ) ) {
3241 testRunDetailsElementsByHash [ previousHash ] = previousTestRunDetailsElement ;
@@ -42,23 +51,48 @@ export function chooseTestRun(runHash: RunHash): void {
4251 return ;
4352 }
4453
45- const { fullTestRuns} = reportClientState ;
46- const fullTestRun = fullTestRuns . find ( ( testRun ) => testRun . runHash === runHash ) ;
54+ const pagesHash : ApiStatisticsReportHash = 'api-statistics-pages' ;
55+ const requestsHash : ApiStatisticsReportHash = 'api-statistics-requests' ;
56+ const resourcesHash : ApiStatisticsReportHash = 'api-statistics-resources' ;
4757
48- if ( fullTestRun === undefined ) {
49- // eslint-disable-next-line no-console
50- console . error (
51- `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` ,
52- ) ;
58+ let rightColumnHtml : SafeHtml | undefined ;
5359
54- return ;
55- }
60+ const hash = String ( runHash ) ;
61+
62+ if ( hash === pagesHash || hash === requestsHash || hash === resourcesHash ) {
63+ const { reportClientData} = reportClientState ;
64+
65+ if ( reportClientData === undefined ) {
66+ // eslint-disable-next-line no-console
67+ console . error (
68+ `Cannot find report client data in JSON report data (tried to click "${ runHash } "). Probably JSON report data not yet completely loaded. Please try click again later` ,
69+ ) ;
70+
71+ return ;
72+ }
5673
57- const testRunDetailsHtml = renderTestRunDetails ( fullTestRun ) ;
74+ const { apiStatistics} = reportClientData ;
75+
76+ rightColumnHtml = renderApiStatistics ( { apiStatistics, hash} ) ;
77+ } else {
78+ const { fullTestRuns} = reportClientState ;
79+ const fullTestRun = fullTestRuns . find ( ( testRun ) => testRun . runHash === runHash ) ;
80+
81+ if ( fullTestRun === undefined ) {
82+ // eslint-disable-next-line no-console
83+ console . error (
84+ `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` ,
85+ ) ;
86+
87+ return ;
88+ }
89+
90+ rightColumnHtml = renderTestRunDetails ( fullTestRun ) ;
91+ }
5892
59- e2edTestRunDetailsContainer . innerHTML = String ( testRunDetailsHtml ) ;
93+ e2edRightColumnContainer . innerHTML = String ( rightColumnHtml ) ;
6094
61- const nextTestRunDetailsElement = e2edTestRunDetailsContainer . firstElementChild as HTMLElement ;
95+ const nextTestRunDetailsElement = e2edRightColumnContainer . firstElementChild as HTMLElement ;
6296
6397 testRunDetailsElementsByHash [ runHash ] = nextTestRunDetailsElement ;
6498}
0 commit comments