1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-18 13:48:58 +02:00
This commit is contained in:
sjaanus 2025-07-02 14:08:01 +03:00
parent d1915522d8
commit 40a5371d61
No known key found for this signature in database
GPG Key ID: 20E007C0248BA7FF

View File

@ -1,12 +1,23 @@
import { renderHook } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { useEventLogFilters } from './EventLogFilters.tsx';
const allFilterKeys = ['from', 'to', 'createdBy', 'type', 'project', 'feature'];
allFilterKeys.sort();
const renderWithRouter = (callback: () => any, initialEntries = ['/']) => {
return renderHook(callback, {
wrapper: ({ children }) => (
<MemoryRouter initialEntries={initialEntries}>
{children}
</MemoryRouter>
),
});
};
test('When you have no projects or flags, you should not get a project or flag filters', () => {
const { result } = renderHook(() => useEventLogFilters([], []));
const { result } = renderWithRouter(() => useEventLogFilters([], []));
const filterKeys = result.current.map((filter) => filter.filterKey);
filterKeys.sort();
@ -15,7 +26,7 @@ test('When you have no projects or flags, you should not get a project or flag f
});
test('When you have no projects, you should not get a project filter', () => {
const { result } = renderHook(() =>
const { result } = renderWithRouter(() =>
useEventLogFilters(
[],
// @ts-expect-error: omitting other properties we don't need
@ -29,7 +40,7 @@ test('When you have no projects, you should not get a project filter', () => {
});
test('When you have only one project, you should not get a project filter', () => {
const { result } = renderHook(() =>
const { result } = renderWithRouter(() =>
useEventLogFilters([{ id: 'a', name: 'A' }], []),
);
const filterKeys = result.current.map((filter) => filter.filterKey);
@ -39,7 +50,7 @@ test('When you have only one project, you should not get a project filter', () =
});
test('When you have two one project, you should not get a project filter', () => {
const { result } = renderHook(() =>
const { result } = renderWithRouter(() =>
useEventLogFilters(
[
{ id: 'a', name: 'A' },
@ -53,3 +64,20 @@ test('When you have two one project, you should not get a project filter', () =>
expect(filterKeys).toContain('project');
});
test('When groupId is in URL params, should include groupId filter', () => {
const { result } = renderWithRouter(
() => useEventLogFilters([], []),
['/?groupId=IS:123'],
);
const filterKeys = result.current.map((filter) => filter.filterKey);
expect(filterKeys).toContain('groupId');
});
test('When no groupId in URL params, should not include groupId filter', () => {
const { result } = renderWithRouter(() => useEventLogFilters([], []));
const filterKeys = result.current.map((filter) => filter.filterKey);
expect(filterKeys).not.toContain('groupId');
});