shlink-web-client/test/common/AppUpdateBanner.test.tsx

46 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

2023-12-31 21:59:56 +03:00
import { act, screen, waitFor } from '@testing-library/react';
2021-07-12 17:34:58 +03:00
import { AppUpdateBanner } from '../../src/common/AppUpdateBanner';
2023-09-30 11:20:28 +03:00
import { checkAccessibility } from '../__helpers__/accessibility';
2022-07-10 20:44:49 +03:00
import { renderWithEvents } from '../__helpers__/setUpTest';
2021-07-12 17:34:58 +03:00
describe('<AppUpdateBanner />', () => {
2023-05-27 12:57:26 +03:00
const toggle = vi.fn();
const forceUpdate = vi.fn();
2023-12-31 21:59:56 +03:00
const setUp = async () => {
const result = await act(
() => renderWithEvents(<AppUpdateBanner isOpen toggle={toggle} forceUpdate={forceUpdate} />),
);
await waitFor(() => screen.getByRole('alert'));
return result;
};
2021-07-12 17:34:58 +03:00
2023-09-30 11:20:28 +03:00
it('passes a11y checks', () => checkAccessibility(setUp()));
2023-12-31 21:59:56 +03:00
it('renders initial state', async () => {
await setUp();
expect(screen.getByRole('heading')).toHaveTextContent('This app has just been updated!');
expect(screen.queryByText('Restarting...')).not.toBeInTheDocument();
expect(screen.getByText('Restart now')).not.toHaveAttribute('disabled');
2021-07-12 17:34:58 +03:00
});
it('invokes toggle when alert is closed', async () => {
2023-12-31 21:59:56 +03:00
const { user } = await setUp();
expect(toggle).not.toHaveBeenCalled();
await user.click(screen.getByLabelText('Close'));
2021-07-12 17:34:58 +03:00
expect(toggle).toHaveBeenCalled();
});
it('triggers the update when clicking the button', async () => {
2023-12-31 21:59:56 +03:00
const { user } = await setUp();
2021-07-12 17:34:58 +03:00
expect(forceUpdate).not.toHaveBeenCalled();
await user.click(screen.getByText(/^Restart now/));
2021-07-12 17:34:58 +03:00
expect(forceUpdate).toHaveBeenCalled();
expect(await screen.findByText('Restarting...')).toBeInTheDocument();
expect(screen.queryByText(/^Restart now/)).not.toBeInTheDocument();
2021-07-12 17:34:58 +03:00
});
});