diff --git a/client/src/pages/JourneyPublicPage.test.tsx b/client/src/pages/JourneyPublicPage.test.tsx index bae0156d0..840e27feb 100644 --- a/client/src/pages/JourneyPublicPage.test.tsx +++ b/client/src/pages/JourneyPublicPage.test.tsx @@ -437,6 +437,59 @@ describe('JourneyPublicPage', () => { }); }); + it('loads a protected journey after a correct password and keeps it locked after a wrong one', async () => { + let unlocked = false; + const user = userEvent.setup(); + server.use( + http.get('/api/public/journey/test-share-token', () => unlocked + ? HttpResponse.json(mockJourneyData) + : HttpResponse.json({ code: 'JOURNEY_PASSWORD_REQUIRED' }, { status: 401 })), + http.post('/api/public/journey/test-share-token/unlock', async ({ request }) => { + const body = await request.json() as { password: string }; + unlocked = body.password === 'trail guide'; + return unlocked + ? HttpResponse.json({ success: true }) + : HttpResponse.json({ code: 'JOURNEY_PASSWORD_INVALID' }, { status: 401 }); + }), + ); + render(); + + const password = await screen.findByLabelText('Password'); + const submit = screen.getByRole('button', { name: 'Unlock' }); + expect(submit).toBeDisabled(); + await user.type(password, 'incorrect'); + await user.click(submit); + expect(await screen.findByRole('alert')).toHaveTextContent('That password is incorrect.'); + expect(screen.queryByText('Shibuya Crossing')).not.toBeInTheDocument(); + + await user.clear(password); + await user.type(password, 'trail guide'); + await user.click(submit); + expect(await screen.findByRole('heading', { level: 1, name: 'Tokyo 2026' })).toBeInTheDocument(); + }); + + it('offers email subscriptions and confirms receipt of the request', async () => { + const user = userEvent.setup(); + const subscribe = vi.fn(); + server.use( + http.get('/api/public/journey/test-share-token', () => + HttpResponse.json({ ...mockJourneyData, interaction: { comments: false, subscribe: true } })), + http.post('/api/public/journey/test-share-token/subscribe', async ({ request }) => { + subscribe(await request.json()); + return HttpResponse.json({ success: true }); + }), + ); + render(); + + await user.click(await screen.findByRole('button', { name: 'Subscribe' })); + const dialog = within(screen.getByRole('dialog')); + await user.type(dialog.getByLabelText(/e.?mail/i), 'reader@example.com'); + await user.click(dialog.getByRole('button', { name: 'Subscribe' })); + + expect(await dialog.findByText('Check your inbox')).toBeInTheDocument(); + expect(subscribe).toHaveBeenCalledWith(expect.objectContaining({ email: 'reader@example.com' })); + }); + it('closes an open entry when the reader navigates to another shared journey', async () => { mockIsMobile.value = true; setupSuccess();