veza/apps/web/src/hooks/useToast.test.ts
senke 37981c2c17 chore(refactor/sumi-migration): commit pending changes — tests, stream server, dist_verification
- apps/web: test updates (Vitest/setup), playbackAnalyticsService, TrackGrid, serviceErrorHandler
- veza-common: logging, metrics, traits, validation, random
- veza-stream-server: audio pipeline, codecs, cache, monitoring, routes
- apps/web/dist_verification: refresh build assets (content-hashed filenames)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 19:39:18 +01:00

99 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { renderHook } from '@testing-library/react';
import { useToast } from './useToast';
// Mock @/utils/toast (lazy wrapper around react-hot-toast)
// vi.mock is hoisted, so we use vi.hoisted to define the mock function
const { mockToastFn } = vi.hoisted(() => {
const fn = Object.assign(vi.fn(), {
success: vi.fn(),
error: vi.fn(),
});
return { mockToastFn: fn };
});
vi.mock('@/utils/toast', () => ({
default: mockToastFn,
}));
describe('useToast', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('should return toast functions', () => {
const { result } = renderHook(() => useToast());
expect(result.current.success).toBeDefined();
expect(result.current.error).toBeDefined();
expect(result.current.warning).toBeDefined();
expect(result.current.info).toBeDefined();
expect(result.current.toast).toBeDefined();
});
it('should call toast.success for success type', () => {
const { result } = renderHook(() => useToast());
result.current.success('Success message');
expect(mockToastFn.success).toHaveBeenCalledWith('Success message', {
duration: undefined,
});
});
it('should call toast.success with duration', () => {
const { result } = renderHook(() => useToast());
result.current.success('Success message', 5000);
expect(mockToastFn.success).toHaveBeenCalledWith('Success message', {
duration: 5000,
});
});
it('should call toast.error for error type', () => {
const { result } = renderHook(() => useToast());
result.current.error('Error message');
expect(mockToastFn.error).toHaveBeenCalledWith('Error message', {
duration: undefined,
});
});
it('should call toast with warning icon for warning type', () => {
const { result } = renderHook(() => useToast());
result.current.warning('Warning message');
expect(mockToastFn).toHaveBeenCalledWith('Warning message', {
icon: '⚠️',
duration: undefined,
});
});
it('should call toast with info icon for info type', () => {
const { result } = renderHook(() => useToast());
result.current.info('Info message');
expect(mockToastFn).toHaveBeenCalledWith('Info message', {
icon: '',
duration: undefined,
});
});
it('should call toast.success for custom toast object with success type', () => {
const { result } = renderHook(() => useToast());
result.current.toast({
message: 'Custom message',
type: 'success',
duration: 3000,
});
expect(mockToastFn.success).toHaveBeenCalledWith('Custom message', {
duration: 3000,
});
});
});