2024-03-10 12:22:01 +00:00
|
|
|
import { render } from '@testing-library/react';
|
2021-12-20 17:21:19 +00:00
|
|
|
|
|
|
|
import { LoadingButton } from './LoadingButton';
|
|
|
|
|
|
|
|
test('when isLoading is true should show spinner and loading text', async () => {
|
|
|
|
const loadingText = 'loading';
|
|
|
|
const children = 'not visible';
|
|
|
|
|
2022-11-28 02:00:28 +00:00
|
|
|
const { queryByText, findByText, container } = render(
|
2024-04-11 00:11:38 +00:00
|
|
|
<LoadingButton loadingText={loadingText} isLoading data-cy="loading-button">
|
2021-12-20 17:21:19 +00:00
|
|
|
{children}
|
|
|
|
</LoadingButton>
|
|
|
|
);
|
|
|
|
|
2022-11-28 02:00:28 +00:00
|
|
|
const spinner = container.querySelector('svg');
|
|
|
|
expect(spinner).toBeVisible();
|
|
|
|
|
2021-12-20 17:21:19 +00:00
|
|
|
const buttonLabel = queryByText(children);
|
|
|
|
expect(buttonLabel).toBeNull();
|
|
|
|
|
|
|
|
const loadingTextElem = await findByText(loadingText);
|
|
|
|
expect(loadingTextElem).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should show children when false', async () => {
|
|
|
|
const loadingText = 'loading';
|
|
|
|
const children = 'visible';
|
|
|
|
|
2022-11-28 02:00:28 +00:00
|
|
|
const { queryByText, container } = render(
|
2024-04-11 00:11:38 +00:00
|
|
|
<LoadingButton
|
|
|
|
loadingText={loadingText}
|
|
|
|
isLoading={false}
|
|
|
|
data-cy="loading-button"
|
|
|
|
>
|
2021-12-20 17:21:19 +00:00
|
|
|
{children}
|
|
|
|
</LoadingButton>
|
|
|
|
);
|
|
|
|
|
|
|
|
const buttonLabel = queryByText(children);
|
|
|
|
expect(buttonLabel).toBeVisible();
|
|
|
|
|
2022-11-28 02:00:28 +00:00
|
|
|
const spinner = container.querySelector('svg');
|
2021-12-20 17:21:19 +00:00
|
|
|
expect(spinner).toBeNull();
|
|
|
|
|
|
|
|
const loadingTextElem = queryByText(loadingText);
|
|
|
|
expect(loadingTextElem).toBeNull();
|
|
|
|
});
|