Skip to content

Commit cd19ffe

Browse files
authored
Pcf 661 subtests render (#962)
* handle params for subtest testVersion * add render test for mann-whitney-u testVersion in subtest * add render test for mann-whitney-u testVersion in subtest * add another test to check if mann-whitney-u test_version subtests render via url params, and baseMean newMean render on subtests
1 parent b4bcad5 commit cd19ffe

File tree

8 files changed

+143
-26
lines changed

8 files changed

+143
-26
lines changed

src/__tests__/CompareResults/SubtestsResultsView.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ describe('SubtestsResultsView Component Tests', () => {
8989
expect(document.body).toMatchSnapshot();
9090
});
9191

92+
it('should render the subtests results view with mann-whitney-u testVersions in url', async () => {
93+
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
94+
const { subtestsResult } = getTestData();
95+
setup({
96+
element: (
97+
<SubtestsResultsView title={Strings.metaData.pageTitle.subtests} />
98+
),
99+
route: '/subtests-compare-results/',
100+
search:
101+
'?baseRev=f49863193c13c1def4db2dd3ea9c5d6bd9d517a7&baseRepo=mozilla-central&newRev=2cb6128d7dca8c9a9266b3505d64d55ac1bcc8a8&newRepo=mozilla-central&framework=1&baseParentSignature=4774487&newParentSignature=4774487&test_version=mann-whitney-u',
102+
subtestsResult,
103+
});
104+
105+
const expandRowButton = await screen.findAllByTestId(/ExpandMoreIcon/);
106+
await user.click(expandRowButton[0]);
107+
expect(
108+
await screen.findByText(/Goodness of Fit Test/i),
109+
).toBeInTheDocument();
110+
111+
await user.click(expandRowButton[1]);
112+
const openedSubtests = await screen.findAllByText(/Normality Test/i);
113+
expect(openedSubtests).toHaveLength(2);
114+
});
115+
92116
it('should request authorization code when "Retrigger" button is clicked', async () => {
93117
const { subtestsResult } = getTestData();
94118
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });

src/__tests__/CompareResults/SubtestsRevisionRow.test.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ReactElement } from 'react';
22

33
import fetchMock from '@fetch-mock/jest';
4+
import userEvent from '@testing-library/user-event';
45

56
import { loader } from '../../components/CompareResults/loader';
67
import SubtestsRevisionRow from '../../components/CompareResults/SubtestsResults/SubtestsRevisionRow';
@@ -116,4 +117,61 @@ describe('SubtestsRevisionRow Component', () => {
116117
expect(screen.queryByText(/firefox/i)).not.toBeInTheDocument();
117118
expect(screen.queryByText(/chrome/i)).not.toBeInTheDocument();
118119
});
120+
121+
it('renders subtests results with mann-whitney-u testVersion', async () => {
122+
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
123+
const { subtestsResult } = getTestData();
124+
const mockGridTemplateColumns = '1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr';
125+
renderWithRoute(
126+
<SubtestsRevisionRow
127+
result={subtestsResult[0]}
128+
gridTemplateColumns={mockGridTemplateColumns}
129+
replicates={false}
130+
testVersion='mann-whitney-u'
131+
/>,
132+
);
133+
const expandRowButton = await screen.findByTestId(/ExpandMoreIcon/);
134+
await user.click(expandRowButton);
135+
136+
expect(
137+
await screen.findByText(/Goodness of Fit Test/i),
138+
).toBeInTheDocument();
139+
expect(await screen.findByText(/Normality Test/i)).toBeInTheDocument();
140+
});
141+
142+
it('renders subtests results defaulting to student-t with no testVersion', async () => {
143+
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
144+
const { subtestsResult } = getTestData();
145+
const mockGridTemplateColumns = '1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr';
146+
renderWithRoute(
147+
<SubtestsRevisionRow
148+
result={subtestsResult[0]}
149+
gridTemplateColumns={mockGridTemplateColumns}
150+
replicates={false}
151+
/>,
152+
);
153+
const expandRowButton = await screen.findByTestId(/ExpandMoreIcon/);
154+
await user.click(expandRowButton);
155+
156+
expect(await screen.findByText(/Difference of means/i)).toBeInTheDocument();
157+
});
158+
159+
it('should display baseMean and newMean in subtests for student-t testVersion', async () => {
160+
const { subtestsResult } = getTestData();
161+
const mockGridTemplateColumns = '1fr 1fr 1fr 1fr 1fr 1fr 1fr 1fr';
162+
renderWithRoute(
163+
<SubtestsRevisionRow
164+
result={subtestsResult[0]}
165+
gridTemplateColumns={mockGridTemplateColumns}
166+
replicates={false}
167+
/>,
168+
);
169+
170+
const roles = await screen.findAllByRole('cell');
171+
const baseMean = roles[1]?.childNodes[0];
172+
expect(baseMean).toHaveTextContent('971.38');
173+
174+
const newMean = roles[3]?.childNodes[0];
175+
expect(newMean).toHaveTextContent('982.41');
176+
});
119177
});

src/__tests__/CompareResults/__snapshots__/SubtestsResultsView.test.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
21262126
aria-invalid="false"
21272127
aria-label="Search by title"
21282128
class="MuiInputBase-input MuiOutlinedInput-input MuiInputBase-inputSizeSmall MuiInputBase-inputAdornedStart MuiInputBase-inputAdornedEnd css-3v3un6-MuiInputBase-input-MuiOutlinedInput-input"
2129-
id="_r_9v_"
2129+
id="_r_b7_"
21302130
placeholder="Filter results"
21312131
type="search"
21322132
value=""
@@ -2585,7 +2585,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
25852585
role="cell"
25862586
>
25872587
<button
2588-
aria-controls="_r_a5_"
2588+
aria-controls="_r_bd_"
25892589
aria-expanded="false"
25902590
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorPrimary MuiIconButton-sizeSmall css-1pgb59k-MuiButtonBase-root-MuiIconButton-root"
25912591
tabindex="0"
@@ -2737,7 +2737,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
27372737
role="cell"
27382738
>
27392739
<button
2740-
aria-controls="_r_a8_"
2740+
aria-controls="_r_bg_"
27412741
aria-expanded="false"
27422742
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorPrimary MuiIconButton-sizeSmall css-1pgb59k-MuiButtonBase-root-MuiIconButton-root"
27432743
tabindex="0"
@@ -2900,7 +2900,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
29002900
role="cell"
29012901
>
29022902
<button
2903-
aria-controls="_r_ab_"
2903+
aria-controls="_r_bj_"
29042904
aria-expanded="false"
29052905
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorPrimary MuiIconButton-sizeSmall css-1pgb59k-MuiButtonBase-root-MuiIconButton-root"
29062906
tabindex="0"
@@ -3063,7 +3063,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
30633063
role="cell"
30643064
>
30653065
<button
3066-
aria-controls="_r_ae_"
3066+
aria-controls="_r_bm_"
30673067
aria-expanded="false"
30683068
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorPrimary MuiIconButton-sizeSmall css-1pgb59k-MuiButtonBase-root-MuiIconButton-root"
30693069
tabindex="0"
@@ -3215,7 +3215,7 @@ exports[`SubtestsViewCompareOverTime Component Tests should render the subtests
32153215
role="cell"
32163216
>
32173217
<button
3218-
aria-controls="_r_ah_"
3218+
aria-controls="_r_bp_"
32193219
aria-expanded="false"
32203220
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorPrimary MuiIconButton-sizeSmall css-1pgb59k-MuiButtonBase-root-MuiIconButton-root"
32213221
tabindex="0"

src/components/CompareResults/RevisionRow.tsx

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ import { style } from 'typestyle';
1515

1616
import { RetriggerButton } from './Retrigger/RetriggerButton';
1717
import RevisionRowExpandable from './RevisionRowExpandable';
18-
import { compareView, compareOverTimeView } from '../../common/constants';
18+
import {
19+
compareView,
20+
compareOverTimeView,
21+
MANN_WHITNEY_U,
22+
} from '../../common/constants';
1923
import { Strings } from '../../resources/Strings';
2024
import { FontSize, Spacing } from '../../styles';
21-
import type { CompareResultsItem, PlatformShortName } from '../../types/state';
25+
import type {
26+
CompareResultsItem,
27+
MannWhitneyResultsItem,
28+
PlatformShortName,
29+
} from '../../types/state';
2230
import { TestVersion } from '../../types/types';
2331
import { formatNumber } from '../../utils/format';
2432
import {
@@ -147,7 +155,10 @@ const confidenceIcons = {
147155
High: <KeyboardArrowUpIcon sx={{ color: 'icons.success' }} />,
148156
};
149157

150-
const getSubtestsCompareWithBaseLink = (result: CompareResultsItem) => {
158+
const getSubtestsCompareWithBaseLink = (
159+
result: CompareResultsItem | MannWhitneyResultsItem,
160+
testVersion: TestVersion,
161+
) => {
151162
const params = new URLSearchParams({
152163
baseRev: result.base_rev,
153164
baseRepo: result.base_repository_name,
@@ -156,12 +167,16 @@ const getSubtestsCompareWithBaseLink = (result: CompareResultsItem) => {
156167
framework: String(result.framework_id),
157168
baseParentSignature: String(result.base_signature_id),
158169
newParentSignature: String(result.new_signature_id),
170+
test_version: testVersion,
159171
});
160172

161173
return `/subtests-compare-results?${params.toString()}`;
162174
};
163175

164-
const getSubtestsCompareOverTimeLink = (result: CompareResultsItem) => {
176+
const getSubtestsCompareOverTimeLink = (
177+
result: CompareResultsItem | MannWhitneyResultsItem,
178+
testVersion: TestVersion,
179+
) => {
165180
// Fetching the interval value directly from the URL avoids a
166181
// spurious render due to react-router context changing. It's not usually a
167182
// problem, but because this component can have a lot of instances, this is a
@@ -187,6 +202,7 @@ const getSubtestsCompareOverTimeLink = (result: CompareResultsItem) => {
187202
selectedTimeRange: interval,
188203
baseParentSignature: String(result.base_signature_id),
189204
newParentSignature: String(result.new_signature_id),
205+
test_version: testVersion,
190206
});
191207

192208
return `/subtests-compare-over-time-results?${params.toString()}`;
@@ -198,9 +214,7 @@ function RevisionRow(props: RevisionRowProps) {
198214
const { result, view, gridTemplateColumns, replicates, testVersion } = props;
199215
const {
200216
platform,
201-
base_avg_value: baseAvgValue,
202217
base_measurement_unit: baseUnit,
203-
new_avg_value: newAvgValue,
204218
new_measurement_unit: newUnit,
205219
is_improvement: improvement,
206220
is_regression: regression,
@@ -221,7 +235,14 @@ function RevisionRow(props: RevisionRowProps) {
221235
? baseRunsReplicates.length
222236
: baseRuns.length;
223237
const newRunsCount = replicates ? newRunsReplicates.length : newRuns.length;
224-
238+
const baseAvgValue =
239+
testVersion === MANN_WHITNEY_U
240+
? (result as MannWhitneyResultsItem).base_standard_stats.mean
241+
: (result as CompareResultsItem).base_avg_value;
242+
const newAvgValue =
243+
testVersion === MANN_WHITNEY_U
244+
? (result as MannWhitneyResultsItem).new_standard_stats.mean
245+
: (result as CompareResultsItem).new_avg_value;
225246
const [expanded, setExpanded] = useState(false);
226247

227248
const toggleIsExpanded = () => {
@@ -231,8 +252,8 @@ function RevisionRow(props: RevisionRowProps) {
231252
// Note that the return type is different depending on the view we're in
232253
const subtestsCompareLink =
233254
view === compareView
234-
? getSubtestsCompareWithBaseLink(result)
235-
: getSubtestsCompareOverTimeLink(result);
255+
? getSubtestsCompareWithBaseLink(result, testVersion)
256+
: getSubtestsCompareOverTimeLink(result, testVersion);
236257

237258
return (
238259
<>
@@ -283,13 +304,13 @@ function RevisionRow(props: RevisionRowProps) {
283304
: 'none',
284305
}}
285306
className={`status-hint ${determineStatusHintClass(
286-
improvement,
287-
regression,
307+
!!improvement,
308+
!!regression,
288309
)}`}
289310
>
290311
{improvement ? <ThumbUpIcon color='success' /> : null}
291312
{regression ? <ThumbDownIcon color='error' /> : null}
292-
{determineStatus(improvement, regression)}
313+
{determineStatus(!!improvement, !!regression)}
293314
</Box>
294315
</div>
295316
<div className='delta cell' role='cell'>
@@ -346,7 +367,10 @@ function RevisionRow(props: RevisionRowProps) {
346367
data-testid='retrigger-jobs-button'
347368
>
348369
<div className='retrigger-button-container'>
349-
<RetriggerButton result={result} variant='icon' />
370+
<RetriggerButton
371+
result={result as CompareResultsItem}
372+
variant='icon'
373+
/>
350374
</div>
351375
</div>
352376
</div>
@@ -388,7 +412,7 @@ function RevisionRow(props: RevisionRowProps) {
388412
}
389413

390414
interface RevisionRowProps {
391-
result: CompareResultsItem;
415+
result: CompareResultsItem | MannWhitneyResultsItem;
392416
gridTemplateColumns: string;
393417
view: typeof compareView | typeof compareOverTimeView;
394418
replicates: boolean;

src/components/CompareResults/SubtestsResults/SubtestsResultsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ type ResultsTableProps = {
174174
filteringSearchTerm: string;
175175
resultsPromise: CompareResultsItem[] | Promise<CompareResultsItem[]>;
176176
replicates: boolean;
177-
testVersion: TestVersion;
177+
testVersion?: TestVersion;
178178
};
179179

180180
function SubtestsResultsTable({

src/components/CompareResults/SubtestsResults/SubtestsRevisionRow.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IconButton, Box } from '@mui/material';
1212
import { style } from 'typestyle';
1313

1414
import RevisionRowExpandable from '.././RevisionRowExpandable';
15+
import { STUDENT_T } from '../../../common/constants';
1516
import { Strings } from '../../../resources/Strings';
1617
import { FontSize, Spacing } from '../../../styles';
1718
import type { CompareResultsItem } from '../../../types/state';
@@ -249,7 +250,7 @@ function SubtestsRevisionRow(props: RevisionRowProps) {
249250
<RevisionRowExpandable
250251
id={id}
251252
result={result}
252-
testVersion={testVersion}
253+
testVersion={testVersion ?? STUDENT_T}
253254
/>
254255
)}
255256
</>
@@ -260,7 +261,7 @@ interface RevisionRowProps {
260261
result: CompareResultsItem;
261262
gridTemplateColumns: string;
262263
replicates: boolean;
263-
testVersion: TestVersion;
264+
testVersion?: TestVersion;
264265
}
265266

266267
export default SubtestsRevisionRow;

src/components/CompareResults/SubtestsResults/SubtestsTableContent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SubtestsRevisionRow from './SubtestsRevisionRow';
2+
import { STUDENT_T } from '../../../common/constants';
23
import type { CompareResultsItem } from '../../../types/state';
34
import { TestVersion } from '../../../types/types';
45

@@ -23,7 +24,7 @@ function SubtestsTableContent(props: SubtestsTableContentProps) {
2324
result={result}
2425
gridTemplateColumns={rowGridTemplateColumns}
2526
replicates={replicates}
26-
testVersion={testVersion}
27+
testVersion={testVersion ?? STUDENT_T}
2728
/>
2829
))}
2930
</>
@@ -35,7 +36,7 @@ interface SubtestsTableContentProps {
3536
identifier: string;
3637
rowGridTemplateColumns: string;
3738
replicates: boolean;
38-
testVersion: TestVersion;
39+
testVersion?: TestVersion;
3940
}
4041

4142
export default SubtestsTableContent;

0 commit comments

Comments
 (0)