Files
CollabTable/shared/packages/web-ui/tests/NotificationStack.test.ts
T
Gabriel20xx 0ff94f9b10
Lint / Lint (push) Successful in 32s
Docker / Docker Build & Push (push) Failing after 2m22s
Tests / Go backend (push) Failing after 1m2s
Tests / Dashboard checks (push) Failing after 35s
ci: expand shared package validation and test coverage
- Add lint, formatting, vet, and publish workflow checks
- Run Go database tests with PostgreSQL and add Java tests
- Make consumer sync opt-in; update docs and Go dependency
2026-10-19 21:46:52 +00:00

39 lines
1.6 KiB
TypeScript

import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/svelte';
import { afterEach, describe, expect, it, vi } from 'vitest';
import NotificationStack from '../src/lib/components/NotificationStack.svelte';
import { notifications, notify } from '../src/lib/notifications.svelte';
// The icon library compiles over a thousand components on import; the icons are not under test.
vi.mock('@lucide/svelte', () => {
const Icon = (): void => {};
return { CircleAlert: Icon, CircleCheck: Icon, Info: Icon, OctagonAlert: Icon, X: Icon };
});
afterEach(() => {
cleanup();
for (const entry of [...notifications.entries]) notifications.dismiss(entry.id);
});
describe('NotificationStack', () => {
it('renders each notification with its variant and message', async () => {
render(NotificationStack);
notify.success('Saved', 0);
notify.error('Failed', 0);
await waitFor(() => expect(screen.getByText('Saved')).toBeTruthy());
expect(screen.getByText('Failed')).toBeTruthy();
const variants = [...document.querySelectorAll('.sc-notification')].map((node) =>
node.getAttribute('data-variant'),
);
expect(variants).toEqual(['success', 'error']);
expect(screen.getByRole('status').getAttribute('aria-live')).toBe('polite');
});
it('dismisses a notification from its close button', async () => {
render(NotificationStack);
notify.info('Dismiss me', 0);
await waitFor(() => expect(screen.getByText('Dismiss me')).toBeTruthy());
await fireEvent.click(screen.getByLabelText('Dismiss notification'));
expect(notifications.entries).toHaveLength(0);
});
});