diff --git a/src/__tests__/CompareResults/ResultsView.test.tsx b/src/__tests__/CompareResults/ResultsView.test.tsx index b647ad7b0..216585bdf 100644 --- a/src/__tests__/CompareResults/ResultsView.test.tsx +++ b/src/__tests__/CompareResults/ResultsView.test.tsx @@ -591,4 +591,28 @@ describe('Results View', () => { expect(screen.queryByText('Results')).not.toBeInTheDocument(); expect(screen.getByText(titleName)).toBeInTheDocument(); }); + + it('toggles all rows when the Expand all checkbox is clicked', async () => { + const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); + renderWithRoute(); + + await screen.findByRole('table'); + + const expandAllCheckbox = screen.getByRole('checkbox', { + name: /Expand all/i, + }); + expect(expandAllCheckbox).not.toBeChecked(); + expect(screen.queryAllByTestId(/ExpandLessIcon/)).toHaveLength(0); + + await user.click(expandAllCheckbox); + expect(expandAllCheckbox).toBeChecked(); + const expandLessIcons = await screen.findAllByTestId(/ExpandLessIcon/); + expect(expandLessIcons.length).toBeGreaterThan(0); + + await user.click(expandAllCheckbox); + expect(expandAllCheckbox).not.toBeChecked(); + await waitFor(() => { + expect(screen.queryAllByTestId(/ExpandLessIcon/)).toHaveLength(0); + }); + }); }); diff --git a/src/__tests__/CompareResults/RevisionRow.test.tsx b/src/__tests__/CompareResults/RevisionRow.test.tsx index 1ad9eccc3..8b4c2be4f 100644 --- a/src/__tests__/CompareResults/RevisionRow.test.tsx +++ b/src/__tests__/CompareResults/RevisionRow.test.tsx @@ -85,6 +85,7 @@ describe('', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); const shortNameNode = await screen.findByText(shortName); @@ -123,6 +124,7 @@ describe('Subtest count pills', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -151,6 +153,7 @@ describe('Subtest count pills', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -172,6 +175,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); @@ -199,6 +203,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -220,6 +225,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); @@ -236,6 +242,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); const expandRow = await screen.findByTestId(/ExpandMoreIcon/); @@ -256,6 +263,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -284,6 +292,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -305,6 +314,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -323,6 +333,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -350,6 +361,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); @@ -369,6 +381,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); @@ -397,6 +410,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='student-t' + expandAll={false} />, ); @@ -435,6 +449,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); const roles = await screen.findAllByRole('cell'); @@ -451,6 +466,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); const roles = await screen.findAllByRole('cell'); @@ -468,6 +484,7 @@ describe('Expanded row', () => { gridTemplateColumns='none' replicates={false} testVersion='mann-whitney-u' + expandAll={false} />, ); const roles = await screen.findAllByRole('cell'); @@ -476,3 +493,66 @@ describe('Expanded row', () => { }); }); }); + +describe('expandAll prop', () => { + it('starts expanded when expandAll is true', async () => { + const { + testCompareData: [rowData], + } = getTestData(); + + renderWithRoute( + , + ); + + expect(await screen.findByTestId(/ExpandLessIcon/)).toBeInTheDocument(); + }); + + it('starts collapsed when expandAll is false', async () => { + const { + testCompareData: [rowData], + } = getTestData(); + + renderWithRoute( + , + ); + + expect(await screen.findByTestId(/ExpandMoreIcon/)).toBeInTheDocument(); + }); + + it('lets the user individually collapse a row that was force-expanded', async () => { + const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); + const { + testCompareData: [rowData], + } = getTestData(); + + renderWithRoute( + , + ); + + const collapseButton = await screen.findByTestId(/ExpandLessIcon/); + await user.click(collapseButton); + + expect(await screen.findByTestId(/ExpandMoreIcon/)).toBeInTheDocument(); + }); +}); diff --git a/src/__tests__/CompareResults/__snapshots__/OverTimeResultsView.test.tsx.snap b/src/__tests__/CompareResults/__snapshots__/OverTimeResultsView.test.tsx.snap index 470b689ae..bb3eff989 100644 --- a/src/__tests__/CompareResults/__snapshots__/OverTimeResultsView.test.tsx.snap +++ b/src/__tests__/CompareResults/__snapshots__/OverTimeResultsView.test.tsx.snap @@ -13,7 +13,7 @@ exports[`Results View The table should match snapshot and other elements should class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-row MuiGrid-spacing-xs-2 f1wpas00 css-13620ud-MuiGrid-root" >
+
+ +
+
+ +
+
+ +
@@ -82,6 +89,7 @@ interface Props { view: typeof compareView | typeof compareOverTimeView; replicates: boolean; testVersion: TestVersion; + expandAll: boolean; } export default TableRevisionContent;