diff --git a/app/javascript/components/ObservationModal.jsx b/app/javascript/components/ObservationModal.jsx index 2bb95553e0..8e731119ff 100644 --- a/app/javascript/components/ObservationModal.jsx +++ b/app/javascript/components/ObservationModal.jsx @@ -17,7 +17,7 @@ const CHOICES = WHEN_CHOICES.filter(([choice]) => choice !== 'yesterday'); export default function ObservationModal({planting, kinds, observation, onClose, onSaved}) { const editing = Boolean(observation); const today = localToday(); - const [kind, setKind] = useState(editing ? (observation.kind || 'other') : ''); + const [kind, setKind] = useState((editing && observation.kind) || 'other'); const [when, setWhen] = useState(!editing || observation.observed_on === today ? 'today' : 'other'); const [customDate, setCustomDate] = useState(editing ? observation.observed_on : today); const [description, setDescription] = useState((editing && observation.description) || ''); diff --git a/app/javascript/components/ObservationModal.test.jsx b/app/javascript/components/ObservationModal.test.jsx index 5167a022d9..c1e9f25fe4 100644 --- a/app/javascript/components/ObservationModal.test.jsx +++ b/app/javascript/components/ObservationModal.test.jsx @@ -28,9 +28,22 @@ const body = (fetch) => JSON.parse(fetch.mock.calls[0][1].body).observation; describe('ObservationModal', () => { afterEach(() => vi.unstubAllGlobals()); - it('will not save until a kind is chosen', () => { + it('selects Other by default', () => { setup(); - expect(screen.getByRole('button', {name: 'Add observation'})).toBeDisabled(); + expect(screen.getByLabelText('Other')).toBeChecked(); + }); + + it('allows saving without choosing a kind', () => { + setup(); + expect(screen.getByRole('button', {name: 'Add observation'})).toBeEnabled(); + }); + + it('saves a note without choosing a kind', async () => { + const fetch = stubFetch({ok: true, data: {garden: {id: 1}}}); + setup(); + await userEvent.type(screen.getByLabelText(/Note/), 'New leaves'); + await userEvent.click(screen.getByRole('button', {name: 'Add observation'})); + expect(body(fetch)).toEqual({kind: null, description: 'New leaves'}); }); it('saves the kind and note for today, leaving the time to the server', async () => { diff --git a/spec/features/plantings/observations_spec.rb b/spec/features/plantings/observations_spec.rb index 2f80c718fc..8aac8645b6 100644 --- a/spec/features/plantings/observations_spec.rb +++ b/spec/features/plantings/observations_spec.rb @@ -12,7 +12,7 @@ def choose_kind_and_save(kind, note) within '[role=dialog]' do expect(page).to have_content 'Add observation to lettuce' - expect(page).to have_button 'Add observation', disabled: true + expect(page).to have_button 'Add observation', disabled: false find('label', text: kind).click fill_in 'Note', with: note click_button 'Add observation'