feat(mobile): open journal entries to read them, with a pencil into the editor

On the phone everyone who may edit a journey got every entry straight in the
editor, so reading the journal meant scrolling a form and risking a stray
edit. An existing entry now opens as its read view: its date and time head
it, the story, place, the chosen mood and weather follow, and the entry's
settings (draft, route) and locked fields stay out of the way. A pencil in the
header switches to the editor without closing the sheet. New entries and
suggestions open in the editor as before, and a viewer's sheet is unchanged.

Addresses discussion #3007.
This commit is contained in:
Maurice
2026-11-27 23:10:00 +01:00
parent 9ea489ac97
commit 59b8d00373
4 changed files with 127 additions and 26 deletions
@@ -1,4 +1,4 @@
// FE-MOB-JDET-001 to FE-MOB-JDET-052
// FE-MOB-JDET-001 to FE-MOB-JDET-055
import { describe, it, expect, beforeEach, afterEach, onTestFinished, vi } from 'vitest';
import { setSizeClass } from '../../../helpers/sizeClass';
import { render, screen, fireEvent, waitFor, act } from '../../../helpers/render';
@@ -510,6 +510,22 @@ describe('MJourneyDetail', () => {
expect(hook.setDeleteTarget).toHaveBeenCalledWith(entry);
});
it('FE-MOB-JDET-054: an editor opens an existing entry to read it, and the pencil turns it into the editor (#3007)', () => {
setup({ editingEntry: buildEntry({ id: 4 }) });
expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'true');
expect(mocks.captured.entrySheet.onMoveEarlier).toBeUndefined();
act(() => (mocks.captured.entrySheet.onEdit as () => void)());
expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'false');
expect(mocks.captured.entrySheet.onEdit).toBeUndefined();
});
it('FE-MOB-JDET-055: a new entry and a suggestion open in the editor straight away', () => {
setup({ editingEntry: buildEntry({ id: 0 }) });
expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'false');
expect(mocks.captured.entrySheet.onEdit).toBeUndefined();
});
it('FE-MOB-JDET-023: a read-only viewer gets the sheet without a delete action', () => {
setup({ canEditEntries: false, editingEntry: buildEntry({ id: 4 }) });
expect(screen.getByTestId('entry-sheet')).toHaveAttribute('data-readonly', 'true');
@@ -252,6 +252,7 @@ interface MountOptions {
upload?: UploadFn;
strict?: boolean;
photoProviders?: { id: string; name: string }[];
onEdit?: () => void;
}
const defaultUpload: UploadFn = async (_entryId, files, cbs) => {
@@ -272,6 +273,7 @@ function mountSheet(sheetEntry: JourneyEntry, opts: MountOptions = {}) {
galleryPhotos={opts.galleryPhotos ?? []}
quickCapture={opts.quickCapture ?? false}
readOnly={opts.readOnly ?? false}
onEdit={opts.onEdit}
userId={42}
trips={[]}
photoProviders={opts.photoProviders}
@@ -976,6 +978,44 @@ describe('MJourneyEntrySheet read-only', () => {
});
});
// FE-MOB-JENTRY-060 to FE-MOB-JENTRY-061: an editor reading an entry (#3007).
describe('MJourneyEntrySheet reading view', () => {
it('FE-MOB-JENTRY-060: reads as the entry, with its date and time on top and the way into the editor', async () => {
const onEdit = vi.fn();
const user = userEvent.setup();
mountSheet(buildEntry({
id: 5,
title: 'Roman holiday',
entry_date: '2026-04-16',
entry_time: '10:30',
location_name: 'Rome',
mood: 'good',
stats_excluded: false,
location_lat: 41.9,
location_lng: 12.5,
}), { readOnly: true, onEdit });
expect(screen.getByText(/10:30/)).toBeInTheDocument();
expect(screen.queryByText('Date')).not.toBeInTheDocument();
expect(screen.queryByRole('switch', { name: 'Leave out of the route' })).not.toBeInTheDocument();
expect(screen.queryByRole('switch', { name: 'Draft' })).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Good' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Neutral' })).not.toBeInTheDocument();
expect(screen.queryByText('Weather')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'Edit' }));
expect(onEdit).toHaveBeenCalledTimes(1);
});
it('FE-MOB-JENTRY-061: a viewer without the editor keeps the locked sheet it always had', () => {
mountSheet(buildEntry({ id: 5, mood: 'good' }), { readOnly: true });
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Neutral' })).toBeDisabled();
});
});
// FE-MOB-JENTRY-051 to FE-MOB-JENTRY-054: leaving a stop off the printed route
// (#2064), the phone sheet's half of the switch the desktop editor has.