2022-07-10 00:03:21 +03:00
|
|
|
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 />', () => {
|
|
|
|
const toggle = jest.fn();
|
|
|
|
const forceUpdate = jest.fn();
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = () => renderWithEvents(<AppUpdateBanner isOpen toggle={toggle} forceUpdate={forceUpdate} />);
|
2021-07-12 17:34:58 +03:00
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
|
2022-05-03 18:49:42 +03:00
|
|
|
it('renders initial state', () => {
|
2022-05-10 21:54:14 +03:00
|
|
|
setUp();
|
|
|
|
|
2022-05-03 18:49:42 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2022-05-10 21:54:14 +03:00
|
|
|
it('invokes toggle when alert is closed', async () => {
|
|
|
|
const { user } = setUp();
|
|
|
|
|
2022-05-03 18:49:42 +03:00
|
|
|
expect(toggle).not.toHaveBeenCalled();
|
2022-05-10 21:54:14 +03:00
|
|
|
await user.click(screen.getByLabelText('Close'));
|
2021-07-12 17:34:58 +03:00
|
|
|
expect(toggle).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-05-03 18:49:42 +03:00
|
|
|
it('triggers the update when clicking the button', async () => {
|
2022-05-10 21:54:14 +03:00
|
|
|
const { user } = setUp();
|
|
|
|
|
2021-07-12 17:34:58 +03:00
|
|
|
expect(forceUpdate).not.toHaveBeenCalled();
|
2022-05-10 21:54:14 +03:00
|
|
|
await user.click(screen.getByText(/^Restart now/));
|
2021-07-12 17:34:58 +03:00
|
|
|
expect(forceUpdate).toHaveBeenCalled();
|
2022-05-03 18:49:42 +03:00
|
|
|
expect(await screen.findByText('Restarting...')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText(/^Restart now/)).not.toBeInTheDocument();
|
2021-07-12 17:34:58 +03:00
|
|
|
});
|
|
|
|
});
|