- 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>
99 lines
2.7 KiB
TypeScript
99 lines
2.7 KiB
TypeScript
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,
|
||
});
|
||
});
|
||
});
|