Replace local settings UI with the one from shlink-web-component

This commit is contained in:
Alejandro Celaya
2024-05-20 20:03:50 +02:00
parent d4bc9dd62a
commit 202a69bdf5
27 changed files with 88 additions and 1096 deletions

View File

@@ -1,52 +1,14 @@
import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import { SettingsFactory } from '../../src/settings/Settings';
import { render } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { Settings } from '../../src/settings/Settings';
import { checkAccessibility } from '../__helpers__/accessibility';
describe('<Settings />', () => {
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>,
}));
const setUp = (activeRoute = '/') => {
const history = createMemoryHistory();
history.push(activeRoute);
return render(<Router location={history.location} navigator={history}><Settings /></Router>);
};
const setUp = () => render(
<MemoryRouter>
<Settings settings={{}} setSettings={vi.fn()} />
</MemoryRouter>,
);
it('passes a11y checks', () => checkAccessibility(setUp()));
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);
visibleComps.forEach((comp) => expect(screen.getByText(comp)).toBeInTheDocument());
hiddenComps.forEach((comp) => expect(screen.queryByText(comp)).not.toBeInTheDocument());
});
it('renders expected menu', () => {
setUp();
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');
});
});