fix: SearchableSelect matches value across string/number types

Insurance option values are strings (String(insurance_id)) while the patient
profile prefill is a number, so strict === matching left بیمه پایه/تکمیلی
showing the placeholder on load — the saved insurance was invisible and looked
unsaved even though PATCH persisted it. Match with String(o.value) ===
String(value) so numeric prefills bind to string-valued options (and vice
versa); null/'' still selects nothing. Verified live: selects now display the
saved insurance after reload.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-07-16 11:16:22 +03:30
co-authored by Claude Opus 4.8
parent 2e2b63f72d
commit f5b0ddc69e
2 changed files with 38 additions and 1 deletions
@@ -0,0 +1,33 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import SearchableSelect from './SearchableSelect';
vi.mock('../../stores/uiStore', () => ({ useUiStore: () => false }));
const insuranceOpts = [
{ value: '176', label: 'تامین اجتماعی' },
{ value: '178', label: 'بیمه ارتش' },
];
describe('SearchableSelect — تطبیق مقدار', () => {
it('مقدار number با گزینهٔ string تطبیق می‌خورد (id بیمه)', () => {
render(<SearchableSelect options={insuranceOpts} value={176} onChange={() => {}} />);
expect(screen.getByText('تامین اجتماعی')).toBeInTheDocument();
});
it('مقدار string با گزینهٔ string تطبیق می‌خورد', () => {
render(<SearchableSelect options={insuranceOpts} value={'178'} onChange={() => {}} />);
expect(screen.getByText('بیمه ارتش')).toBeInTheDocument();
});
it('مقدار number با گزینهٔ number تطبیق می‌خورد', () => {
render(<SearchableSelect options={[{ value: 9, label: 'یزد' }]} value={9} onChange={() => {}} />);
expect(screen.getByText('یزد')).toBeInTheDocument();
});
it('null/خالی → هیچ گزینه‌ای انتخاب نمی‌شود (placeholder)', () => {
render(<SearchableSelect options={insuranceOpts} value={null} onChange={() => {}} placeholder="انتخاب کنید..." />);
expect(screen.getByText('انتخاب کنید...')).toBeInTheDocument();
expect(screen.queryByText('تامین اجتماعی')).not.toBeInTheDocument();
});
});