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:
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user