Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132import { beforeEach, describe, expect, it, vi } from 'vitest';import { errAsync, okAsync } from 'neverthrow';import { announce } from '@design-system';import { ApiError } from './api';import { errorStatus, saveStatus } from './saveStatus';
vi.mock('@design-system', () => ({ announce: vi.fn() }));
describe('saveStatus', () => { beforeEach(() => vi.clearAllMocks());
it('applies the value, announces politely and returns the ok message', async () => { const apply = vi.fn(); const status = await saveStatus(okAsync({ id: '7' }), 'Saved', apply); expect(status).toBe('Saved'); expect(apply).toHaveBeenCalledWith({ id: '7' }); expect(announce).toHaveBeenCalledWith('Saved'); });
it('returns the error line and announces it assertively on failure', async () => { const status = await saveStatus(errAsync(new ApiError('boom', 500)), 'Saved'); expect(status).toContain('boom'); expect(announce).toHaveBeenCalledWith(status, 'assertive'); });
it('errorStatus formats and announces a lone error', () => { const status = errorStatus(new ApiError('nope', 400)); expect(status).toContain('nope'); expect(announce).toHaveBeenCalledWith(status, 'assertive'); });});