Added filtering dropdown to short URLs filtering bar

This commit is contained in:
Alejandro Celaya
2022-12-23 20:15:52 +01:00
parent b00f6fadf8
commit e790360de9
4 changed files with 47 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import { endOfDay, formatISO, startOfDay } from 'date-fns';
import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom';
import { ShortUrlsFilteringBar as filteringBarCreator } from '../../src/short-urls/ShortUrlsFilteringBar';
import { ReachableServer, SelectedServer } from '../../src/servers/data';
import { Settings } from '../../src/settings/reducers/settings';
import { DateRange } from '../../src/utils/helpers/dateIntervals';
import { formatDate } from '../../src/utils/helpers/date';
import { renderWithEvents } from '../__helpers__/setUpTest';
@@ -30,6 +31,7 @@ describe('<ShortUrlsFilteringBar />', () => {
selectedServer={selectedServer ?? Mock.all<SelectedServer>()}
order={{}}
handleOrderBy={handleOrderBy}
settings={Mock.of<Settings>({ visits: {} })}
/>
</MemoryRouter>,
);
@@ -114,6 +116,24 @@ describe('<ShortUrlsFilteringBar />', () => {
expect(navigate).toHaveBeenCalledWith(expect.stringContaining(expectedRedirectTagsMode));
});
it.each([
['', 'excludeBots=true'],
['excludeBots=false', 'excludeBots=true'],
['excludeBots=true', 'excludeBots=false'],
])('allows to toggle excluding bots through filtering dropdown', async (search, expectedQuery) => {
const { user } = setUp(
search,
Mock.of<ReachableServer>({ version: '3.4.0' }),
);
const toggleBots = async (name = 'Exclude bots visits') => {
await user.click(screen.getByRole('button', { name: 'Filters' }));
await user.click(await screen.findByRole('menuitem', { name }));
};
await toggleBots();
expect(navigate).toHaveBeenCalledWith(expect.stringContaining(expectedQuery));
});
it('handles order through dropdown', async () => {
const { user } = setUp();
const clickMenuItem = async (name: string | RegExp) => {