* chore: simple change to trigger new ci * feat: make PR CD work issue #338 * ci: fix target deploy url * ci: improve deployments into just one matrix job * ci: put secret on env * fix: fix nagivation when creating notes and tasks from the home page * test: add sidebar test cases * chore: test files cleanup
67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
// AuthProvider.test.tsx
|
|
import React, { useContext } from 'react';
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { render, act, waitFor, cleanup } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import SidebarProvider from '../../context/SidebarProvider';
|
|
import SidebarContext, { SidebarContextData } from '../../context/SidebarContext';
|
|
|
|
// Create a helper component to consume AuthContext for testing.
|
|
const ConsumerComponent: React.FC = () => {
|
|
const {
|
|
currentPage,
|
|
setNewPage
|
|
} = useContext<SidebarContextData>(SidebarContext);
|
|
|
|
return (
|
|
<div>
|
|
<div data-testid="page">{currentPage}</div>
|
|
<button
|
|
data-testid="setPage"
|
|
onClick={() => {
|
|
setNewPage('/another');
|
|
}}
|
|
>
|
|
Change page
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
describe('SidebarProvider', () => {
|
|
// Reset DOM and mocks for each test.
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
});
|
|
|
|
it('should render the default context values', () => {
|
|
const { getByTestId } = render(
|
|
<SidebarProvider>
|
|
<ConsumerComponent />
|
|
</SidebarProvider>
|
|
);
|
|
|
|
expect(getByTestId('page').textContent).toBe('/home');
|
|
});
|
|
|
|
it('should set a new page after click', async () => {
|
|
const { getByTestId } = render(
|
|
<SidebarProvider>
|
|
<ConsumerComponent />
|
|
</SidebarProvider>
|
|
);
|
|
|
|
await act(async () => {
|
|
userEvent.click(getByTestId('setPage'));
|
|
});
|
|
|
|
await waitFor(() =>
|
|
expect(getByTestId('page').textContent).toBe('/another')
|
|
);
|
|
});
|
|
});
|