diff --git a/src/optimizer-page/CourseOptimizerPage.test.js b/src/optimizer-page/CourseOptimizerPage.test.js index fdcd2396d..46f1b2da3 100644 --- a/src/optimizer-page/CourseOptimizerPage.test.js +++ b/src/optimizer-page/CourseOptimizerPage.test.js @@ -194,7 +194,7 @@ describe('CourseOptimizerPage', () => { }); }); - it('should show only manual links when manualLinks filter is selected', async () => { + it('should show only manual links when manualLinks filter is selected and show all links when clicked again', async () => { const { getByText, getByLabelText, @@ -215,6 +215,16 @@ describe('CourseOptimizerPage', () => { expect(queryByText('Test Broken Links')).not.toBeInTheDocument(); expect(queryByText('Test Locked Links')).not.toBeInTheDocument(); }); + + // Click the manual links checkbox again to clear the filter + fireEvent.click(getByLabelText(scanResultsMessages.manualLabel.defaultMessage)); + + // Assert that all links are displayed after clearing the filter + await waitFor(() => { + expect(getByText('Test Broken Links')).toBeInTheDocument(); + expect(getByText('Test Manual Links')).toBeInTheDocument(); + expect(getByText('Test Locked Links')).toBeInTheDocument(); + }); }); it('should show only manual & locked links when manual & locked Links filters are selected, ignore broken links', async () => { @@ -267,5 +277,51 @@ describe('CourseOptimizerPage', () => { expect(getByText('Test Locked Links')).toBeInTheDocument(); }); }); + + it('should show only manual links when the broken chip is clicked and show all links when clear filters button is clicked', async () => { + const { + getByText, + getByLabelText, + getByTestId, + queryByText, + container, + } = await setupOptimizerPage(); + // Select broken & manual link checkboxes + fireEvent.click(getByLabelText(scanResultsMessages.brokenLabel.defaultMessage)); + fireEvent.click(getByLabelText(scanResultsMessages.manualLabel.defaultMessage)); + + const collapsibleTrigger = container.querySelector('.collapsible-trigger'); + expect(collapsibleTrigger).toBeInTheDocument(); + fireEvent.click(collapsibleTrigger); + + // Assert that all links are displayed + await waitFor(() => { + expect(getByText('Test Broken Links')).toBeInTheDocument(); + expect(getByText('Test Manual Links')).toBeInTheDocument(); + expect(queryByText('Test Locked Links')).not.toBeInTheDocument(); + }); + + // Click on the "Broken" chip to filter the results + const brokenChip = getByTestId('chip-brokenLinks'); + fireEvent.click(brokenChip); + + // Assert that only manual links are displayed + await waitFor(() => { + expect(queryByText('Test Broken Links')).not.toBeInTheDocument(); + expect(getByText('Test Manual Links')).toBeInTheDocument(); + expect(queryByText('Test Locked Links')).not.toBeInTheDocument(); + }); + + // Click the "Clear filters" button + const clearFiltersButton = getByText(scanResultsMessages.clearFilters.defaultMessage); + fireEvent.click(clearFiltersButton); + + // Assert that all links are displayed after clearing filters + await waitFor(() => { + expect(getByText('Test Broken Links')).toBeInTheDocument(); + expect(getByText('Test Manual Links')).toBeInTheDocument(); + expect(getByText('Test Locked Links')).toBeInTheDocument(); + }); + }); }); }); diff --git a/src/optimizer-page/scan-results/ScanResults.tsx b/src/optimizer-page/scan-results/ScanResults.tsx index 7ca463cf5..c4dc73929 100644 --- a/src/optimizer-page/scan-results/ScanResults.tsx +++ b/src/optimizer-page/scan-results/ScanResults.tsx @@ -4,6 +4,7 @@ import { Chip, Button, useCheckboxSetValues, + useToggle, } from '@openedx/paragon'; import { ArrowDropDown, @@ -34,7 +35,7 @@ interface Props { const ScanResults: FC = ({ data }) => { const intl = useIntl(); - const [isModalOpen, setModalOpen] = useState(false); + const [isOpen, open, close] = useToggle(false); const initialFilters = { brokenLinks: false, lockedLinks: false, @@ -76,7 +77,7 @@ const ScanResults: FC = ({ data }) => {