mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 20:17:45 +00:00
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/react';
|
|
import { LocalhostDisclaimer } from '@/components/shared/localhost-disclaimer';
|
|
|
|
const { useAuthMock } = vi.hoisted(() => ({
|
|
useAuthMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('@/contexts/auth-context', () => ({
|
|
useAuth: useAuthMock,
|
|
}));
|
|
|
|
describe('LocalhostDisclaimer', () => {
|
|
beforeEach(() => {
|
|
useAuthMock.mockReset();
|
|
});
|
|
|
|
it('shows the local safety copy for loopback sessions', () => {
|
|
useAuthMock.mockReturnValue({
|
|
authEnabled: false,
|
|
authConfigured: false,
|
|
isLocalAccess: true,
|
|
loading: false,
|
|
});
|
|
|
|
render(<LocalhostDisclaimer />);
|
|
|
|
expect(
|
|
screen.getByText('This dashboard runs locally. All data stays on your machine.')
|
|
).toBeVisible();
|
|
});
|
|
|
|
it('shows the remote read-only copy when auth is disabled for remote access', () => {
|
|
useAuthMock.mockReturnValue({
|
|
authEnabled: false,
|
|
authConfigured: false,
|
|
isLocalAccess: false,
|
|
loading: false,
|
|
});
|
|
|
|
render(<LocalhostDisclaimer />);
|
|
|
|
expect(
|
|
screen.getByText(
|
|
'Remote dashboard access is read-only until you run ccs config auth setup on the host.'
|
|
)
|
|
).toBeVisible();
|
|
expect(screen.queryByLabelText('Dismiss disclaimer')).toBeNull();
|
|
});
|
|
|
|
it('shows the re-enable message when host credentials already exist', () => {
|
|
useAuthMock.mockReturnValue({
|
|
authEnabled: false,
|
|
authConfigured: true,
|
|
isLocalAccess: false,
|
|
loading: false,
|
|
});
|
|
|
|
render(<LocalhostDisclaimer />);
|
|
|
|
expect(
|
|
screen.getByText(
|
|
'Remote dashboard access is read-only because dashboard auth is currently disabled on the host. Re-enable dashboard auth on the host to unlock remote changes.'
|
|
)
|
|
).toBeVisible();
|
|
expect(screen.queryByLabelText('Dismiss disclaimer')).toBeNull();
|
|
});
|
|
});
|