soulsync/webui/src/components/primitives/primitives.test.tsx
Antti Kettunen 2a7c03f398
refactor(webui): merge primitives into one module
- fold Show and Notice into a single primitives module with one shared stylesheet
- keep the primitives barrel export intact while shrinking the folder footprint
- consolidate the primitive tests into one combined suite
2026-05-24 21:17:22 +03:00

52 lines
1.4 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Notice, Show } from './primitives';
describe('Show', () => {
it('renders children when the condition is true', () => {
render(
<Show when={true}>
<span>Visible</span>
</Show>,
);
expect(screen.getByText('Visible')).toBeInTheDocument();
});
it('renders fallback when the condition is false', () => {
render(
<Show fallback={<span>Hidden</span>} when={false}>
<span>Visible</span>
</Show>,
);
expect(screen.getByText('Hidden')).toBeInTheDocument();
expect(screen.queryByText('Visible')).not.toBeInTheDocument();
});
it('supports render-prop children', () => {
render(<Show when="Ada">{(name) => <span>{name}</span>}</Show>);
expect(screen.getByText('Ada')).toBeInTheDocument();
});
});
describe('Notice', () => {
it('renders as a note by default', () => {
render(<Notice>Fallback message</Notice>);
expect(screen.getByText('Fallback message')).toHaveAttribute('role', 'note');
expect(screen.getByText('Fallback message')).toHaveAttribute('data-tone', 'info');
});
it('supports tone overrides', () => {
render(
<Notice tone="warning">
<span>Provider fallback</span>
</Notice>,
);
expect(screen.getByRole('note')).toHaveAttribute('data-tone', 'warning');
});
});