2023-08-04 23:59:33 +03:00
|
|
|
import type { ShortUrlsListSettings as ShortUrlsSettings } from '@shlinkio/shlink-web-component';
|
2022-07-10 00:03:21 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2021-12-25 12:49:12 +03:00
|
|
|
import { ShortUrlsListSettings } from '../../src/settings/ShortUrlsListSettings';
|
2023-09-30 11:45:52 +03:00
|
|
|
import { checkAccessibility } from '../__helpers__/accessibility';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2021-12-24 16:15:28 +03:00
|
|
|
|
2021-12-25 12:49:12 +03:00
|
|
|
describe('<ShortUrlsListSettings />', () => {
|
2023-05-27 12:57:26 +03:00
|
|
|
const setSettings = vi.fn();
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (shortUrlsList?: ShortUrlsSettings) => renderWithEvents(
|
2023-04-13 22:48:29 +03:00
|
|
|
<ShortUrlsListSettings settings={fromPartial({ shortUrlsList })} setShortUrlsListSettings={setSettings} />,
|
2022-07-10 00:03:21 +03:00
|
|
|
);
|
2021-12-24 16:15:28 +03:00
|
|
|
|
2023-09-30 11:45:52 +03:00
|
|
|
it('passes a11y checks', () => checkAccessibility(setUp()));
|
|
|
|
|
2021-12-24 16:15:28 +03:00
|
|
|
it.each([
|
2022-06-06 23:38:07 +03:00
|
|
|
[undefined, 'Order by: Created at - DESC'],
|
2023-08-14 13:15:57 +03:00
|
|
|
[fromPartial<ShortUrlsSettings>({}), 'Order by: Created at - DESC'],
|
|
|
|
[fromPartial<ShortUrlsSettings>({ defaultOrdering: {} }), 'Order by...'],
|
|
|
|
[fromPartial<ShortUrlsSettings>({ defaultOrdering: { field: 'longUrl', dir: 'DESC' } }), 'Order by: Long URL - DESC'],
|
|
|
|
[fromPartial<ShortUrlsSettings>({ defaultOrdering: { field: 'visits', dir: 'ASC' } }), 'Order by: Visits - ASC'],
|
2021-12-24 16:15:28 +03:00
|
|
|
])('shows expected ordering', (shortUrlsList, expectedOrder) => {
|
2022-06-06 23:38:07 +03:00
|
|
|
setUp(shortUrlsList);
|
|
|
|
expect(screen.getByRole('button')).toHaveTextContent(expectedOrder);
|
2021-12-24 16:15:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-06-06 23:38:07 +03:00
|
|
|
['Clear selection', undefined, undefined],
|
|
|
|
['Long URL', 'longUrl', 'ASC'],
|
|
|
|
['Visits', 'visits', 'ASC'],
|
|
|
|
['Title', 'title', 'ASC'],
|
|
|
|
])('invokes setSettings when ordering changes', async (name, field, dir) => {
|
|
|
|
const { user } = setUp();
|
2021-12-24 16:15:28 +03:00
|
|
|
|
|
|
|
expect(setSettings).not.toHaveBeenCalled();
|
2022-06-06 23:38:07 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
|
|
|
await user.click(screen.getByRole('menuitem', { name }));
|
2021-12-24 16:15:28 +03:00
|
|
|
expect(setSettings).toHaveBeenCalledWith({ defaultOrdering: { field, dir } });
|
|
|
|
});
|
|
|
|
});
|