2022-06-06 23:23:21 +03:00
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import { render, screen } from '@testing-library/react';
|
2021-09-20 22:23:39 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2021-12-25 12:49:12 +03:00
|
|
|
import {
|
|
|
|
RealTimeUpdatesSettings as RealTimeUpdatesSettingsOptions,
|
|
|
|
Settings,
|
|
|
|
} from '../../src/settings/reducers/settings';
|
2022-05-28 11:47:39 +03:00
|
|
|
import { RealTimeUpdatesSettings } from '../../src/settings/RealTimeUpdatesSettings';
|
2021-09-20 22:23:39 +03:00
|
|
|
|
2021-12-25 12:49:12 +03:00
|
|
|
describe('<RealTimeUpdatesSettings />', () => {
|
2021-09-20 22:23:39 +03:00
|
|
|
const toggleRealTimeUpdates = jest.fn();
|
|
|
|
const setRealTimeUpdatesInterval = jest.fn();
|
2022-06-06 23:23:21 +03:00
|
|
|
const setUp = (realTimeUpdates: Partial<RealTimeUpdatesSettingsOptions> = {}) => ({
|
|
|
|
user: userEvent.setup(),
|
|
|
|
...render(
|
2021-12-25 12:49:12 +03:00
|
|
|
<RealTimeUpdatesSettings
|
2022-06-06 23:23:21 +03:00
|
|
|
settings={Mock.of<Settings>({ realTimeUpdates })}
|
2021-09-20 22:23:39 +03:00
|
|
|
toggleRealTimeUpdates={toggleRealTimeUpdates}
|
|
|
|
setRealTimeUpdatesInterval={setRealTimeUpdatesInterval}
|
|
|
|
/>,
|
2022-06-06 23:23:21 +03:00
|
|
|
),
|
|
|
|
});
|
2021-09-20 22:23:39 +03:00
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it('renders enabled real time updates as expected', () => {
|
2022-06-06 23:23:21 +03:00
|
|
|
setUp({ enabled: true });
|
|
|
|
|
|
|
|
expect(screen.getByLabelText(/^Enable or disable real-time updates./)).toBeChecked();
|
|
|
|
expect(screen.getByText(/^Real-time updates are currently being/)).toHaveTextContent('processed');
|
|
|
|
expect(screen.getByText(/^Real-time updates are currently being/)).not.toHaveTextContent('ignored');
|
|
|
|
expect(screen.getByText('Real-time updates frequency (in minutes):')).not.toHaveAttribute(
|
|
|
|
'class',
|
|
|
|
expect.stringContaining('text-muted'),
|
|
|
|
);
|
|
|
|
expect(screen.getByLabelText('Real-time updates frequency (in minutes):')).not.toHaveAttribute('disabled');
|
|
|
|
expect(screen.getByText('Updates will be reflected in the UI as soon as they happen.')).toBeInTheDocument();
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it('renders disabled real time updates as expected', () => {
|
2022-06-06 23:23:21 +03:00
|
|
|
setUp({ enabled: false });
|
|
|
|
|
|
|
|
expect(screen.getByLabelText(/^Enable or disable real-time updates./)).not.toBeChecked();
|
|
|
|
expect(screen.getByText(/^Real-time updates are currently being/)).not.toHaveTextContent('processed');
|
|
|
|
expect(screen.getByText(/^Real-time updates are currently being/)).toHaveTextContent('ignored');
|
|
|
|
expect(screen.getByText('Real-time updates frequency (in minutes):')).toHaveAttribute(
|
|
|
|
'class',
|
|
|
|
expect.stringContaining('text-muted'),
|
|
|
|
);
|
|
|
|
expect(screen.getByLabelText('Real-time updates frequency (in minutes):')).toHaveAttribute('disabled');
|
|
|
|
expect(screen.queryByText('Updates will be reflected in the UI as soon as they happen.')).not.toBeInTheDocument();
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[1, 'minute'],
|
|
|
|
[2, 'minutes'],
|
|
|
|
[10, 'minutes'],
|
|
|
|
[100, 'minutes'],
|
2021-09-20 23:00:34 +03:00
|
|
|
])('shows expected children when interval is greater than 0', (interval, minutesWord) => {
|
2022-06-06 23:23:21 +03:00
|
|
|
setUp({ enabled: true, interval });
|
2021-09-20 22:23:39 +03:00
|
|
|
|
2022-06-06 23:23:21 +03:00
|
|
|
expect(screen.getByText(/^Updates will be reflected in the UI every/)).toHaveTextContent(
|
|
|
|
`${interval} ${minutesWord}`,
|
2021-09-20 22:23:39 +03:00
|
|
|
);
|
2022-06-06 23:23:21 +03:00
|
|
|
expect(screen.getByLabelText('Real-time updates frequency (in minutes):')).toHaveValue(interval);
|
|
|
|
expect(screen.queryByText('Updates will be reflected in the UI as soon as they happen.')).not.toBeInTheDocument();
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
|
2022-03-26 14:17:42 +03:00
|
|
|
it.each([[undefined], [0]])('shows expected children when interval is 0 or undefined', (interval) => {
|
2022-06-06 23:23:21 +03:00
|
|
|
setUp({ enabled: true, interval });
|
2021-09-20 22:23:39 +03:00
|
|
|
|
2022-06-06 23:23:21 +03:00
|
|
|
expect(screen.queryByText(/^Updates will be reflected in the UI every/)).not.toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Updates will be reflected in the UI as soon as they happen.')).toBeInTheDocument();
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 23:23:21 +03:00
|
|
|
it('updates real time updates when typing on input', async () => {
|
|
|
|
const { user } = setUp({ enabled: true });
|
2021-09-20 22:23:39 +03:00
|
|
|
|
|
|
|
expect(setRealTimeUpdatesInterval).not.toHaveBeenCalled();
|
2022-06-06 23:23:21 +03:00
|
|
|
await user.type(screen.getByLabelText('Real-time updates frequency (in minutes):'), '5');
|
|
|
|
expect(setRealTimeUpdatesInterval).toHaveBeenCalledWith(5);
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
|
2022-06-06 23:23:21 +03:00
|
|
|
it('toggles real time updates on switch change', async () => {
|
|
|
|
const { user } = setUp({ enabled: true });
|
2021-09-20 22:23:39 +03:00
|
|
|
|
|
|
|
expect(toggleRealTimeUpdates).not.toHaveBeenCalled();
|
2022-06-06 23:23:21 +03:00
|
|
|
await user.click(screen.getByText(/^Enable or disable real-time updates./));
|
2021-09-20 22:23:39 +03:00
|
|
|
expect(toggleRealTimeUpdates).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|