The engine from tasks 06 and 07 could find slots and hold them, but nothing in the panel could actually book one. - Search, hold, confirm stay three separate steps because they are three separate states: between seeing a slot and taking it the seat is still open, and between taking and confirming there is a deadline - HoldCountdown reads the server's expires_at rather than starting its own timer at render: browser clock skew and network latency both cost seconds, and those seconds are exactly where a hold is lost. It turns urgent under a minute and tells the parent the moment it lapses - Per-role resource swap offers only the resources the engine returned for that same slot. Listing every resource in the branch would let an operator pick one that was never free and collect a 409 - An empty result is not an error: the reason code renders as a sentence saying what to change - Confirm requires a doctor and stays disabled until one is chosen — the endpoint rejects it anyway, and finding that out after the hold clock has been running is the wrong time Reached from the appointments page as a separate action rather than folded into the existing form: its search comes from the intersection of resource calendars, not from one doctor's slots, and merging the two would confuse both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { render, screen, act } from '@testing-library/react';
|
|
import HoldCountdown from './HoldCountdown';
|
|
|
|
describe('HoldCountdown', () => {
|
|
beforeEach(() => vi.useFakeTimers());
|
|
afterEach(() => vi.useRealTimers());
|
|
|
|
const nowSeconds = () => Math.floor(Date.now() / 1000);
|
|
|
|
it('counts down from the server expiry', () => {
|
|
render(<HoldCountdown expiresAt={nowSeconds() + 125} onExpired={() => {}} />);
|
|
|
|
expect(screen.getByText(/2:05/)).toBeInTheDocument();
|
|
|
|
act(() => { vi.advanceTimersByTime(5000); });
|
|
|
|
expect(screen.getByText(/2:00/)).toBeInTheDocument();
|
|
});
|
|
|
|
/** ⭐ رزروی که در سکوت منقضی شود، اپراتور را با یک ۴۰۹ بیتوضیح تنها میگذارد. */
|
|
it('reports expiry to the parent exactly once it lapses', () => {
|
|
const onExpired = vi.fn();
|
|
render(<HoldCountdown expiresAt={nowSeconds() + 2} onExpired={onExpired} />);
|
|
|
|
expect(onExpired).not.toHaveBeenCalled();
|
|
|
|
act(() => { vi.advanceTimersByTime(3000); });
|
|
|
|
expect(onExpired).toHaveBeenCalled();
|
|
expect(screen.getByText('مهلت تمام شد')).toBeInTheDocument();
|
|
});
|
|
|
|
it('switches to the urgent style under a minute', () => {
|
|
const { container } = render(<HoldCountdown expiresAt={nowSeconds() + 30} onExpired={() => {}} />);
|
|
|
|
expect(container.querySelector('.badge.red')).not.toBeNull();
|
|
});
|
|
});
|