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

38 lines
1.3 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
2021-07-12 17:34:58 +03:00
import { AppUpdateBanner } from '../../src/common/AppUpdateBanner';
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();
const setUp = () => renderWithEvents(<AppUpdateBanner isOpen toggle={toggle} forceUpdate={forceUpdate} />);
2021-07-12 17:34:58 +03:00
2023-05-27 12:57:26 +03:00
afterEach(vi.clearAllMocks);
2021-07-12 17:34:58 +03:00
it('renders initial state', () => {
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 () => {
const { user } = 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 () => {
const { user } = 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
});
});