2025-12-25 16:09:51 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Tests for API Toast Helper Utility
|
|
|
|
|
|
* FE-TEST-004: Test API toast helper utility functions
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
|
|
import { InternalAxiosRequestConfig } from 'axios';
|
|
|
|
|
|
import {
|
|
|
|
|
|
withSuccessToast,
|
|
|
|
|
|
withoutErrorToast,
|
|
|
|
|
|
showSuccessToast,
|
|
|
|
|
|
showErrorToast,
|
|
|
|
|
|
showInfoToast,
|
|
|
|
|
|
showWarningToast,
|
|
|
|
|
|
} from './apiToastHelper';
|
|
|
|
|
|
|
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 18:39:18 +00:00
|
|
|
|
// Mock @/utils/toast (lazy wrapper around react-hot-toast)
|
|
|
|
|
|
// vi.mock is hoisted — factory must NOT reference outer variables
|
|
|
|
|
|
vi.mock('@/utils/toast', () => {
|
|
|
|
|
|
const fn = Object.assign(vi.fn(), {
|
2025-12-25 16:09:51 +00:00
|
|
|
|
success: vi.fn(),
|
|
|
|
|
|
error: vi.fn(),
|
|
|
|
|
|
loading: vi.fn(),
|
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 18:39:18 +00:00
|
|
|
|
});
|
|
|
|
|
|
return { default: fn };
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
|
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 18:39:18 +00:00
|
|
|
|
// Import the mocked module to get reference for assertions
|
|
|
|
|
|
import toast from '@/utils/toast';
|
2025-12-25 16:09:51 +00:00
|
|
|
|
|
|
|
|
|
|
describe('apiToastHelper utilities', () => {
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
vi.clearAllMocks();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('withSuccessToast', () => {
|
|
|
|
|
|
it('should add success toast flag to config', () => {
|
|
|
|
|
|
const config: InternalAxiosRequestConfig = {
|
|
|
|
|
|
url: '/api/test',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
};
|
|
|
|
|
|
const result = withSuccessToast(config);
|
|
|
|
|
|
expect((result as any)._showSuccessToast).toBe(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should add custom success message', () => {
|
|
|
|
|
|
const config: InternalAxiosRequestConfig = {
|
|
|
|
|
|
url: '/api/test',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
};
|
|
|
|
|
|
const result = withSuccessToast(config, 'Custom success');
|
|
|
|
|
|
expect((result as any)._successMessage).toBe('Custom success');
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('withoutErrorToast', () => {
|
|
|
|
|
|
it('should add disable toast flag to config', () => {
|
|
|
|
|
|
const config: InternalAxiosRequestConfig = {
|
|
|
|
|
|
url: '/api/test',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
};
|
|
|
|
|
|
const result = withoutErrorToast(config);
|
|
|
|
|
|
expect((result as any)._disableToast).toBe(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('showSuccessToast', () => {
|
|
|
|
|
|
it('should call toast.success', () => {
|
|
|
|
|
|
showSuccessToast('Success message');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast.success).toHaveBeenCalledWith('Success message', {
|
|
|
|
|
|
duration: undefined,
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should call toast.success with duration', () => {
|
|
|
|
|
|
showSuccessToast('Success message', 5000);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast.success).toHaveBeenCalledWith('Success message', {
|
|
|
|
|
|
duration: 5000,
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('showErrorToast', () => {
|
|
|
|
|
|
it('should call toast.error', () => {
|
|
|
|
|
|
showErrorToast('Error message');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast.error).toHaveBeenCalledWith('Error message', {
|
|
|
|
|
|
duration: undefined,
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should call toast.error with duration', () => {
|
|
|
|
|
|
showErrorToast('Error message', 5000);
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast.error).toHaveBeenCalledWith('Error message', {
|
|
|
|
|
|
duration: 5000,
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('showInfoToast', () => {
|
|
|
|
|
|
it('should call toast with info icon', () => {
|
|
|
|
|
|
showInfoToast('Info message');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast).toHaveBeenCalledWith('Info message', {
|
|
|
|
|
|
duration: undefined,
|
|
|
|
|
|
icon: 'ℹ️',
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('showWarningToast', () => {
|
|
|
|
|
|
it('should call toast with warning icon', () => {
|
|
|
|
|
|
showWarningToast('Warning message');
|
2026-01-13 18:47:57 +00:00
|
|
|
|
expect(toast).toHaveBeenCalledWith('Warning message', {
|
|
|
|
|
|
duration: undefined,
|
|
|
|
|
|
icon: '⚠️',
|
|
|
|
|
|
});
|
2025-12-25 16:09:51 +00:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|