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

41 lines
1.4 KiB
TypeScript
Raw Normal View History

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2021-07-12 17:34:58 +03:00
import { AppUpdateBanner } from '../../src/common/AppUpdateBanner';
describe('<AppUpdateBanner />', () => {
const toggle = jest.fn();
const forceUpdate = jest.fn();
const setUp = () => ({
user: userEvent.setup(),
...render(<AppUpdateBanner isOpen toggle={toggle} forceUpdate={forceUpdate} />),
});
2021-07-12 17:34:58 +03:00
afterEach(jest.clearAllMocks);
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
});
});