mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
harden
This commit is contained in:
parent
d04aa83258
commit
dcd6dc00f4
83 changed files with 1797 additions and 390 deletions
33
webclient/src/components/Guard/AuthGuard.spec.tsx
Normal file
33
webclient/src/components/Guard/AuthGuard.spec.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { screen } from '@testing-library/react';
|
||||
import { renderWithProviders, connectedState, disconnectedState } from '../../__test-utils__';
|
||||
import AuthGuard from './AuthGuard';
|
||||
|
||||
vi.mock('@app/hooks', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@app/hooks')>();
|
||||
return { ...actual, useWebClient: vi.fn(() => ({})) };
|
||||
});
|
||||
|
||||
describe('AuthGuard', () => {
|
||||
it('redirects to LOGIN when disconnected', () => {
|
||||
renderWithProviders(<AuthGuard />, {
|
||||
preloadedState: disconnectedState,
|
||||
route: '/server',
|
||||
});
|
||||
|
||||
// Navigate triggers a route change — AuthGuard itself renders no text.
|
||||
// We verify it doesn't render any meaningful content.
|
||||
expect(screen.queryByRole('button')).toBeNull();
|
||||
expect(screen.queryByRole('heading')).toBeNull();
|
||||
});
|
||||
|
||||
it('renders nothing visible when connected', () => {
|
||||
const { container } = renderWithProviders(<AuthGuard />, {
|
||||
preloadedState: connectedState,
|
||||
route: '/server',
|
||||
});
|
||||
|
||||
// AuthGuard renders an empty fragment when connected.
|
||||
// The only DOM is from provider wrappers (e.g. ToastProvider's container div).
|
||||
expect(container.textContent).toBe('');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue