Skip to content

Commit

Permalink
test(InterstitialSCreen): increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
anamikaanu96 committed Oct 30, 2024
1 parent e4ce578 commit 146cf51
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { render, screen, act } from '@testing-library/react'; // https://testing-library.com/docs/react-testing-library/intro

import { pkg } from '../../settings';
import { pkg, carbon } from '../../settings';
import uuidv4 from '../../global/js/utils/uuidv4';

import { InterstitialScreen } from '.';
Expand Down Expand Up @@ -191,19 +191,31 @@ describe(componentName, () => {
const listElement1 = step1.closest('li');
const step2 = screen.getByText('Step 2');
const listElement2 = step2.closest('li');
expect(listElement1).toHaveClass('cds--progress-step--current');
expect(listElement2).toHaveClass('cds--progress-step--incomplete');
expect(listElement1).toHaveClass(
`${carbon.prefix}--progress-step--current`
);
expect(listElement2).toHaveClass(
`${carbon.prefix}--progress-step--incomplete`
);
const nextButtonElement = screen.getByText('Next');
expect(nextButtonElement).toHaveClass(`${blockClass}--next-btn`);
await act(() => userEvent.click(nextButtonElement));
expect(listElement1).toHaveClass('cds--progress-step--complete');
expect(listElement2).toHaveClass('cds--progress-step--current');
expect(listElement1).toHaveClass(
`${carbon.prefix}--progress-step--complete`
);
expect(listElement2).toHaveClass(
`${carbon.prefix}--progress-step--current`
);
expect(screen.getByText('Back')).toBeInTheDocument();
const backButtonElement = screen.getByText('Back');
expect(backButtonElement).toHaveClass(`${blockClass}--prev-btn`);
await act(() => userEvent.click(backButtonElement));
expect(listElement1).toHaveClass('cds--progress-step--current');
expect(listElement2).toHaveClass('cds--progress-step--incomplete');
expect(listElement1).toHaveClass(
`${carbon.prefix}--progress-step--current`
);
expect(listElement2).toHaveClass(
`${carbon.prefix}--progress-step--incomplete`
);
});

it('Clicking the close button', async () => {
Expand All @@ -215,13 +227,4 @@ describe(componentName, () => {
await act(() => userEvent.click(closeBtn));
expect(onClose).toBeCalled();
});

it('Pressing escape key for closing the modal', async () => {
renderComponent({
className: blockClass,
interstitialAriaLabel: 'Modal Interstitial Screen',
});
await act(() => userEvent.keyboard('{escape}'));
expect(onClose).toBeCalled();
});
});

0 comments on commit 146cf51

Please sign in to comment.