Add tests for modules/navigation and modules/keyboard-shortcut-menu (#3461)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: KlingerMatheus <klinger.matheus@gitstart.dev>
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useIsSettingsPage } from '../useIsSettingsPage';
|
||||
|
||||
const getWrapper =
|
||||
(initialIndex: 0 | 1) =>
|
||||
({ children }: { children: React.ReactNode }) => (
|
||||
<MemoryRouter
|
||||
initialEntries={['/settings/', '/tasks']}
|
||||
initialIndex={initialIndex}
|
||||
>
|
||||
{children}
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
describe('useIsSettingsPage', () => {
|
||||
it('should return true for pages which has /settings/ in pathname', () => {
|
||||
const { result } = renderHook(() => useIsSettingsPage(), {
|
||||
wrapper: getWrapper(0),
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for other pages which does not have /settings/ in pathname', () => {
|
||||
const { result } = renderHook(() => useIsSettingsPage(), {
|
||||
wrapper: getWrapper(1),
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,31 @@
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useIsTasksPage } from '../useIsTasksPage';
|
||||
|
||||
const getWrapper =
|
||||
(initialIndex: 0 | 1) =>
|
||||
({ children }: { children: React.ReactNode }) => (
|
||||
<MemoryRouter
|
||||
initialEntries={['/settings/', '/tasks']}
|
||||
initialIndex={initialIndex}
|
||||
>
|
||||
{children}
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
describe('useIsSettingsPage', () => {
|
||||
it('should return true for pages which has /tasks in pathname', () => {
|
||||
const { result } = renderHook(() => useIsTasksPage(), {
|
||||
wrapper: getWrapper(1),
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for other pages which does not have /tasks in pathname', () => {
|
||||
const { result } = renderHook(() => useIsTasksPage(), {
|
||||
wrapper: getWrapper(0),
|
||||
});
|
||||
expect(result.current).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user