fix(appointments): a resource is a view inside its doctor, and never slot-based
Two reported bugs, one root cause: resource tabs were built as a rival selection to the doctor rather than a narrower view within them. Selecting a resource cleared the doctor. The auto-select effect then quietly put the *first* doctor back, so anyone working under the second doctor was thrown to the first and lost that doctor's own booking. Selecting a resource now leaves the doctor alone; only picking a doctor clears the resource. A resource tab also still rendered the doctor's slot timeline, just with no data. Resources have no slotted weekly schedule — their calendar comes from service duration and real occupancy — so showing a slot grid promises times the booking engine does not recognise. The resource tab now renders its own panel: that day's appointments on the resource plus a service booking entry point. Both regressions are pinned by tests, and both were checked by reverting each fix in turn. The first attempt at the doctor-retention test passed even with the bug restored, because the auto-select effect masked it; it was rewritten to use the second doctor, where the bounce is observable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { renderWithProviders } from '../test/utils';
|
||||
|
||||
vi.mock('../lib/api', () => ({
|
||||
@@ -121,6 +122,39 @@ describe('AppointmentsPage — پروفایل کلینیک چندپزشکه', ()
|
||||
expect(screen.queryByText('دکتر بیبرنامه')).toBeNull();
|
||||
});
|
||||
|
||||
/**
|
||||
* باگ گزارششده: انتخاب منبع، پزشک را پاک میکرد. افکتِ «انتخاب خودکار اولین پزشک»
|
||||
* بلافاصله پزشکی را برمیگرداند، ولی **اولین** پزشک را — پس کاربری که روی پزشک دوم
|
||||
* بود به پزشک اول میپرید و نوبتدهی همان پزشک را از دست میداد.
|
||||
*/
|
||||
it('انتخاب منبع، کاربر را روی همان پزشک نگه میدارد', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(<AppointmentsPage />);
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'دکتر رضایی' }));
|
||||
const own = await screen.findByRole('button', { name: 'لیزر دکتر رضایی' });
|
||||
await user.click(own);
|
||||
|
||||
// هنوز منابعِ پزشک دوم فهرست میشوند، نه منابع پزشک اول.
|
||||
expect(await screen.findByRole('button', { name: 'لیزر دکتر رضایی' })).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'لیزر CO2' })).toBeNull();
|
||||
});
|
||||
|
||||
/** باگ گزارششده: نمای منبع نباید اسلاتی باشد. */
|
||||
it('نمای منبع سرویسی است و تایملاین اسلاتی ندارد', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithProviders(<AppointmentsPage />);
|
||||
|
||||
await screen.findByText('دکتر محمدی');
|
||||
await user.click(await screen.findByRole('button', { name: 'لیزر CO2' }));
|
||||
|
||||
expect(await screen.findByText(/نوبتدهی این منبع سرویسی است/)).toBeInTheDocument();
|
||||
expect(screen.getByText('افزودن نوبت سرویس')).toBeInTheDocument();
|
||||
// ورودی اسلاتی نباید باشد.
|
||||
expect(screen.queryByText('افزودن نوبت سریع')).toBeNull();
|
||||
expect(screen.queryByText('این روز تعطیل است')).toBeNull();
|
||||
});
|
||||
|
||||
it('auto-selects the first doctor so the timeline loads its slots', async () => {
|
||||
renderWithProviders(<AppointmentsPage />);
|
||||
await screen.findByText('دکتر محمدی');
|
||||
|
||||
Reference in New Issue
Block a user