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
This commit is contained in:
committed by
Muhammad Faraz Maqsood
parent
c77c4f3c91
commit
e8463f7a6a
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
Chip,
|
||||
Button,
|
||||
useCheckboxSetValues,
|
||||
useToggle,
|
||||
} from '@openedx/paragon';
|
||||
import {
|
||||
ArrowDropDown,
|
||||
@@ -34,7 +35,7 @@ interface Props {
|
||||
|
||||
const ScanResults: FC<Props> = ({ 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<Props> = ({ data }) => {
|
||||
<Button
|
||||
ref={setButtonRef}
|
||||
variant="outline-primary"
|
||||
onClick={() => setModalOpen(true)}
|
||||
onClick={open}
|
||||
disabled={false}
|
||||
iconAfter={ArrowDropDown}
|
||||
className="rounded-sm justify-content-between cadence-button"
|
||||
@@ -86,8 +87,10 @@ const ScanResults: FC<Props> = ({ data }) => {
|
||||
</header>
|
||||
</div>
|
||||
<FilterModal
|
||||
isOpen={isModalOpen}
|
||||
onClose={() => setModalOpen(false)}
|
||||
isOpen={isOpen}
|
||||
// ignoring below line because filter modal doesn't have close button
|
||||
// istanbul ignore next
|
||||
onClose={close}
|
||||
onApply={setFilters}
|
||||
positionRef={buttonRef}
|
||||
filterOptions={filterOptions}
|
||||
@@ -105,6 +108,7 @@ const ScanResults: FC<Props> = ({ data }) => {
|
||||
{activeFilters.map(filter => (
|
||||
<Chip
|
||||
key={filter}
|
||||
data-testid={`chip-${filter}`}
|
||||
iconAfter={CloseSmall}
|
||||
iconAfterAlt="icon-after"
|
||||
className="scan-results-active-filters-chip"
|
||||
|
||||
Reference in New Issue
Block a user