mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-23 13:46:45 +02:00
Fix
This commit is contained in:
parent
d1915522d8
commit
40a5371d61
@ -1,12 +1,23 @@
|
|||||||
import { renderHook } from '@testing-library/react';
|
import { renderHook } from '@testing-library/react';
|
||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { useEventLogFilters } from './EventLogFilters.tsx';
|
import { useEventLogFilters } from './EventLogFilters.tsx';
|
||||||
|
|
||||||
const allFilterKeys = ['from', 'to', 'createdBy', 'type', 'project', 'feature'];
|
const allFilterKeys = ['from', 'to', 'createdBy', 'type', 'project', 'feature'];
|
||||||
|
|
||||||
allFilterKeys.sort();
|
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', () => {
|
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);
|
const filterKeys = result.current.map((filter) => filter.filterKey);
|
||||||
filterKeys.sort();
|
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', () => {
|
test('When you have no projects, you should not get a project filter', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderWithRouter(() =>
|
||||||
useEventLogFilters(
|
useEventLogFilters(
|
||||||
[],
|
[],
|
||||||
// @ts-expect-error: omitting other properties we don't need
|
// @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', () => {
|
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' }], []),
|
useEventLogFilters([{ id: 'a', name: 'A' }], []),
|
||||||
);
|
);
|
||||||
const filterKeys = result.current.map((filter) => filter.filterKey);
|
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', () => {
|
test('When you have two one project, you should not get a project filter', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderWithRouter(() =>
|
||||||
useEventLogFilters(
|
useEventLogFilters(
|
||||||
[
|
[
|
||||||
{ id: 'a', name: 'A' },
|
{ 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');
|
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');
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user