2022-06-05 12:16:11 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-09-05 10:08:42 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2022-06-05 12:16:11 +03:00
|
|
|
import { createMemoryHistory } from 'history';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { Router } from 'react-router-dom';
|
2023-09-05 10:08:42 +03:00
|
|
|
import { SettingsFactory } from '../../src/settings/Settings';
|
2021-09-20 22:23:39 +03:00
|
|
|
|
|
|
|
describe('<Settings />', () => {
|
2023-09-05 10:08:42 +03:00
|
|
|
const Settings = SettingsFactory(fromPartial({
|
|
|
|
RealTimeUpdatesSettings: () => <span>RealTimeUpdates</span>,
|
|
|
|
ShortUrlCreationSettings: () => <span>ShortUrlCreation</span>,
|
|
|
|
ShortUrlsListSettings: () => <span>ShortUrlsList</span>,
|
|
|
|
UserInterfaceSettings: () => <span>UserInterface</span>,
|
|
|
|
VisitsSettings: () => <span>Visits</span>,
|
|
|
|
TagsSettings: () => <span>Tags</span>,
|
|
|
|
}));
|
2022-06-05 12:16:11 +03:00
|
|
|
const setUp = (activeRoute = '/') => {
|
|
|
|
const history = createMemoryHistory();
|
|
|
|
history.push(activeRoute);
|
|
|
|
return render(<Router location={history.location} navigator={history}><Settings /></Router>);
|
|
|
|
};
|
2021-09-20 22:23:39 +03:00
|
|
|
|
2022-06-05 12:16:11 +03:00
|
|
|
it.each([
|
|
|
|
['/general', {
|
|
|
|
visibleComps: ['UserInterface', 'RealTimeUpdates'],
|
|
|
|
hiddenComps: ['ShortUrlCreation', 'ShortUrlsList', 'Tags', 'Visits'],
|
|
|
|
}],
|
|
|
|
['/short-urls', {
|
|
|
|
visibleComps: ['ShortUrlCreation', 'ShortUrlsList'],
|
|
|
|
hiddenComps: ['UserInterface', 'RealTimeUpdates', 'Tags', 'Visits'],
|
|
|
|
}],
|
|
|
|
['/other-items', {
|
|
|
|
visibleComps: ['Tags', 'Visits'],
|
|
|
|
hiddenComps: ['UserInterface', 'RealTimeUpdates', 'ShortUrlCreation', 'ShortUrlsList'],
|
|
|
|
}],
|
|
|
|
])('renders expected sections based on route', (activeRoute, { visibleComps, hiddenComps }) => {
|
|
|
|
setUp(activeRoute);
|
2021-09-20 22:23:39 +03:00
|
|
|
|
2022-06-05 12:16:11 +03:00
|
|
|
visibleComps.forEach((comp) => expect(screen.getByText(comp)).toBeInTheDocument());
|
|
|
|
hiddenComps.forEach((comp) => expect(screen.queryByText(comp)).not.toBeInTheDocument());
|
2022-02-14 22:04:38 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders expected menu', () => {
|
2022-06-05 12:16:11 +03:00
|
|
|
setUp();
|
2022-02-14 22:04:38 +03:00
|
|
|
|
2022-06-05 12:16:11 +03:00
|
|
|
expect(screen.getByRole('link', { name: 'General' })).toHaveAttribute('href', '/general');
|
|
|
|
expect(screen.getByRole('link', { name: 'Short URLs' })).toHaveAttribute('href', '/short-urls');
|
|
|
|
expect(screen.getByRole('link', { name: 'Other items' })).toHaveAttribute('href', '/other-items');
|
2021-09-20 22:23:39 +03:00
|
|
|
});
|
|
|
|
});
|