Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/javascript/components/ObservationModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) || '');
Expand Down
17 changes: 15 additions & 2 deletions app/javascript/components/ObservationModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/features/plantings/observations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down