fix(journey): read a day kept meanwhile again to offer replace, date the phone row in the app language

This commit is contained in:
Maurice
2026-10-21 15:18:01 +02:00
parent 5116f7be2c
commit fbf6cd2840
3 changed files with 27 additions and 4 deletions
@@ -1,4 +1,4 @@
// FE-JRN-RECORDING-DAY-001 to FE-JRN-RECORDING-DAY-007
// FE-JRN-RECORDING-DAY-001 to FE-JRN-RECORDING-DAY-008
//
// JRN-01: taking one day's recorded route over, for the desktop dialog and the
// phone sheet alike. Nothing is kept before the button, what is kept is the
@@ -123,6 +123,25 @@ describe('useJourneyRecordingDay', () => {
expect(toast.error).not.toHaveBeenCalled();
});
it('FE-JRN-RECORDING-DAY-008: a day someone else kept meanwhile is read again and offers Replace, not a Keep that fails', async () => {
repo.preview.mockResolvedValue(buildRecordingPreview());
repo.save.mockRejectedValue(httpError('recording_exists'));
const { result, onKept, onClose } = setup();
await waitFor(() => expect(result.current.action).toBe('keep'));
repo.preview.mockResolvedValue(
buildRecordingPreview({ stored: buildRecordedDay({ contentHash: 'b'.repeat(64) }) })
);
await act(() => result.current.save());
expect(toast.error).toHaveBeenCalledWith('This journey already keeps another recording of that day.');
await waitFor(() => expect(result.current.action).toBe('replace'));
expect(repo.preview).toHaveBeenCalledTimes(2);
expect(result.current.changedSincePreview).toBe(false);
expect(onKept).not.toHaveBeenCalled();
expect(onClose).not.toHaveBeenCalled();
});
it('FE-JRN-RECORDING-DAY-006: says why the day could not be read, and what was recorded nothing of has nothing to keep', async () => {
repo.preview.mockRejectedValueOnce(httpError('not_connected'));
const { result } = setup();
@@ -106,11 +106,15 @@ export function useJourneyRecordingDay({
toast.success(t(action === 'replace' ? 'journey.recording.replacedToast' : 'journey.recording.keptToast'));
onClose();
} catch (err) {
if (recordingErrorCode(err) === 'recording_changed') {
const code = recordingErrorCode(err);
if (code === 'recording_changed') {
setChangedSincePreview(true);
retry();
} else {
toast.error(recordingErrorText(err, t));
// Someone kept the day meanwhile: read it again so the dialog shows
// their version and offers Replace instead of a Keep that cannot work.
if (code === 'recording_exists') retry();
}
} finally {
setBusy(null);
@@ -40,7 +40,7 @@ import MJourneyRecordingSheet from './MJourneyRecordingSheet'
*/
export default function MJourneyDetail({ journeyId, embedded = false }: JourneyDetailOptions = {}) {
const {
id, navigate, toast, t,
id, navigate, toast, t, locale,
current, loading,
canEditEntries, canEditJourney,
view, setView,
@@ -515,7 +515,7 @@ export default function MJourneyDetail({ journeyId, embedded = false }: JourneyD
<MListRow
icon={Route}
label={t('journey.recording.takeOverDay', {
date: new Date(entries[activeIndex].entry_date + 'T00:00:00').toLocaleDateString(undefined, { day: 'numeric', month: 'long' }),
date: new Date(entries[activeIndex].entry_date + 'T00:00:00').toLocaleDateString(locale, { day: 'numeric', month: 'long' }),
})}
onClick={() => { setShowActionMenu(false); recordings.open(entries[activeIndex].entry_date) }}
/>