Skip to content

Commit e8463f7

Browse files
Muhammad Faraz  MaqsoodFaraz32123
authored andcommitted
feat: add more unit tests for code coverage
- add more unit tests for code coverage to cover more use cases - ignore Modal close in code coverage as our modal does not have close button
1 parent c77c4f3 commit e8463f7

2 files changed

Lines changed: 65 additions & 5 deletions

File tree

src/optimizer-page/CourseOptimizerPage.test.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('CourseOptimizerPage', () => {
194194
});
195195
});
196196

197-
it('should show only manual links when manualLinks filter is selected', async () => {
197+
it('should show only manual links when manualLinks filter is selected and show all links when clicked again', async () => {
198198
const {
199199
getByText,
200200
getByLabelText,
@@ -215,6 +215,16 @@ describe('CourseOptimizerPage', () => {
215215
expect(queryByText('Test Broken Links')).not.toBeInTheDocument();
216216
expect(queryByText('Test Locked Links')).not.toBeInTheDocument();
217217
});
218+
219+
// Click the manual links checkbox again to clear the filter
220+
fireEvent.click(getByLabelText(scanResultsMessages.manualLabel.defaultMessage));
221+
222+
// Assert that all links are displayed after clearing the filter
223+
await waitFor(() => {
224+
expect(getByText('Test Broken Links')).toBeInTheDocument();
225+
expect(getByText('Test Manual Links')).toBeInTheDocument();
226+
expect(getByText('Test Locked Links')).toBeInTheDocument();
227+
});
218228
});
219229

220230
it('should show only manual & locked links when manual & locked Links filters are selected, ignore broken links', async () => {
@@ -267,5 +277,51 @@ describe('CourseOptimizerPage', () => {
267277
expect(getByText('Test Locked Links')).toBeInTheDocument();
268278
});
269279
});
280+
281+
it('should show only manual links when the broken chip is clicked and show all links when clear filters button is clicked', async () => {
282+
const {
283+
getByText,
284+
getByLabelText,
285+
getByTestId,
286+
queryByText,
287+
container,
288+
} = await setupOptimizerPage();
289+
// Select broken & manual link checkboxes
290+
fireEvent.click(getByLabelText(scanResultsMessages.brokenLabel.defaultMessage));
291+
fireEvent.click(getByLabelText(scanResultsMessages.manualLabel.defaultMessage));
292+
293+
const collapsibleTrigger = container.querySelector('.collapsible-trigger');
294+
expect(collapsibleTrigger).toBeInTheDocument();
295+
fireEvent.click(collapsibleTrigger);
296+
297+
// Assert that all links are displayed
298+
await waitFor(() => {
299+
expect(getByText('Test Broken Links')).toBeInTheDocument();
300+
expect(getByText('Test Manual Links')).toBeInTheDocument();
301+
expect(queryByText('Test Locked Links')).not.toBeInTheDocument();
302+
});
303+
304+
// Click on the "Broken" chip to filter the results
305+
const brokenChip = getByTestId('chip-brokenLinks');
306+
fireEvent.click(brokenChip);
307+
308+
// Assert that only manual links are displayed
309+
await waitFor(() => {
310+
expect(queryByText('Test Broken Links')).not.toBeInTheDocument();
311+
expect(getByText('Test Manual Links')).toBeInTheDocument();
312+
expect(queryByText('Test Locked Links')).not.toBeInTheDocument();
313+
});
314+
315+
// Click the "Clear filters" button
316+
const clearFiltersButton = getByText(scanResultsMessages.clearFilters.defaultMessage);
317+
fireEvent.click(clearFiltersButton);
318+
319+
// Assert that all links are displayed after clearing filters
320+
await waitFor(() => {
321+
expect(getByText('Test Broken Links')).toBeInTheDocument();
322+
expect(getByText('Test Manual Links')).toBeInTheDocument();
323+
expect(getByText('Test Locked Links')).toBeInTheDocument();
324+
});
325+
});
270326
});
271327
});

src/optimizer-page/scan-results/ScanResults.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Chip,
55
Button,
66
useCheckboxSetValues,
7+
useToggle,
78
} from '@openedx/paragon';
89
import {
910
ArrowDropDown,
@@ -34,7 +35,7 @@ interface Props {
3435

3536
const ScanResults: FC<Props> = ({ data }) => {
3637
const intl = useIntl();
37-
const [isModalOpen, setModalOpen] = useState(false);
38+
const [isOpen, open, close] = useToggle(false);
3839
const initialFilters = {
3940
brokenLinks: false,
4041
lockedLinks: false,
@@ -76,7 +77,7 @@ const ScanResults: FC<Props> = ({ data }) => {
7677
<Button
7778
ref={setButtonRef}
7879
variant="outline-primary"
79-
onClick={() => setModalOpen(true)}
80+
onClick={open}
8081
disabled={false}
8182
iconAfter={ArrowDropDown}
8283
className="rounded-sm justify-content-between cadence-button"
@@ -86,8 +87,10 @@ const ScanResults: FC<Props> = ({ data }) => {
8687
</header>
8788
</div>
8889
<FilterModal
89-
isOpen={isModalOpen}
90-
onClose={() => setModalOpen(false)}
90+
isOpen={isOpen}
91+
// ignoring below line because filter modal doesn't have close button
92+
// istanbul ignore next
93+
onClose={close}
9194
onApply={setFilters}
9295
positionRef={buttonRef}
9396
filterOptions={filterOptions}
@@ -105,6 +108,7 @@ const ScanResults: FC<Props> = ({ data }) => {
105108
{activeFilters.map(filter => (
106109
<Chip
107110
key={filter}
111+
data-testid={`chip-${filter}`}
108112
iconAfter={CloseSmall}
109113
iconAfterAlt="icon-after"
110114
className="scan-results-active-filters-chip"

0 commit comments

Comments
 (0)