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:
gitstart-twenty
2024-01-17 16:00:58 +01:00
committed by GitHub
parent 4fa9e18920
commit 808100fdd5
3 changed files with 145 additions and 0 deletions

View File

@ -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);
});
});

View File

@ -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);
});
});