Add data-testid to preloader and spinner, add test case for profile.spec

This commit is contained in:
esvyridov
2021-12-23 17:44:45 -06:00
committed by Umputun
parent 78e2be8ea4
commit f4ef0a7e78
3 changed files with 19 additions and 5 deletions
+1 -1
View File
@@ -6,5 +6,5 @@ type Props = {
};
export function Preloader({ className }: Props) {
return <div className={clsx('preloader', className)} aria-label="Loading..." />;
return <div className={clsx('preloader', className)} aria-label="Loading..." data-testid="preloader" />;
}
@@ -171,12 +171,25 @@ describe('<Profile />', () => {
.spyOn(api, 'getUserComments')
.mockImplementation(async () => ({ comments: new Array(10).fill(commentStub), count: 15 }));
const { findByRole, getByRole, queryByRole } = render(<Profile />);
const { findByRole, getByRole, queryByRole, queryByTestId } = render(<Profile />);
expect(await findByRole('button', { name: /load more/i })).toBeInTheDocument();
fireEvent.click(getByRole('button', { name: /load more/i }));
expect(getByRole('presentation')).toHaveClass('spinner');
await waitFor(() => expect(queryByRole('presentation')).not.toBeInTheDocument());
expect(queryByRole('button', { name: /load more/i })).not.toBeInTheDocument();
expect(queryByTestId('spinner')).toBeInTheDocument();
await waitFor(() => {
expect(queryByRole('button', { name: /load more/i })).not.toBeInTheDocument();
});
});
it('preloader should not be rendered after click on load more button', async () => {
jest
.spyOn(api, 'getUserComments')
.mockImplementation(async () => ({ comments: new Array(10).fill(commentStub), count: 15 }));
const { findByRole, queryByTestId } = render(<Profile />);
fireEvent.click(await findByRole('button', { name: /load more/i }));
expect(queryByTestId('preloader')).not.toBeInTheDocument();
});
});
@@ -17,6 +17,7 @@ export function Spinner({ color }: Props) {
className={clsx('spinner', styles.root, { [styles.dark]: color === 'gray' })}
role="presentation"
aria-label={intl.formatMessage(messages.loading)}
data-testid="spinner"
/>
);
}