From aa54643713cea56e965303408153c505ec92e67b Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Mon, 30 Nov 2026 15:08:22 +0800 Subject: [PATCH] fix(trips): add titles to Unsplash search thumbnails --- client/src/components/Trips/TripFormModal.test.tsx | 2 ++ client/src/components/Trips/TripFormModal.tsx | 1 + client/src/mobile/screens/dashboard/MNewTripSheet.tsx | 8 +++++++- client/tests/unit/mobile/dashboard/MNewTripSheet.test.tsx | 8 ++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/src/components/Trips/TripFormModal.test.tsx b/client/src/components/Trips/TripFormModal.test.tsx index 78876c296..afbb3d96c 100644 --- a/client/src/components/Trips/TripFormModal.test.tsx +++ b/client/src/components/Trips/TripFormModal.test.tsx @@ -379,6 +379,7 @@ describe('TripFormModal', () => { await user.type(screen.getByPlaceholderText(/Summer in Japan/i), 'Alpine Trip'); await user.type(screen.getByPlaceholderText('Search destination photos'), 'alps'); await user.click(screen.getByRole('button', { name: /Search Unsplash/i })); + expect(await screen.findByAltText('Mountain lake')).toHaveAttribute('title', 'Mountain lake'); await user.click(await screen.findByRole('button', { name: /Use Unsplash photo by Alice/i })); const submitBtn = screen.getAllByText('Create New Trip').find(el => el.closest('button'))!; @@ -777,6 +778,7 @@ describe('TripFormModal', () => { const photoBtn = await screen.findByRole('button', { name: 'Use Unsplash photo by Unsplash' }); expect(photoBtn.querySelector('img')).toHaveAttribute('alt', ''); + expect(photoBtn.querySelector('img')).not.toHaveAttribute('title'); expect(photoBtn.querySelector('span')).toBeNull(); // An empty url is not selectable — nothing is staged. diff --git a/client/src/components/Trips/TripFormModal.tsx b/client/src/components/Trips/TripFormModal.tsx index 5de06d886..01dde9e49 100644 --- a/client/src/components/Trips/TripFormModal.tsx +++ b/client/src/components/Trips/TripFormModal.tsx @@ -494,6 +494,7 @@ export default function TripFormModal({ {photo.description diff --git a/client/src/mobile/screens/dashboard/MNewTripSheet.tsx b/client/src/mobile/screens/dashboard/MNewTripSheet.tsx index 2859f8700..b35028c9c 100644 --- a/client/src/mobile/screens/dashboard/MNewTripSheet.tsx +++ b/client/src/mobile/screens/dashboard/MNewTripSheet.tsx @@ -440,7 +440,13 @@ function CoverField({ cover, title }: { cover: ReturnType - {photo.description + {photo.description {photo.photographer && ( {photo.photographer} diff --git a/client/tests/unit/mobile/dashboard/MNewTripSheet.test.tsx b/client/tests/unit/mobile/dashboard/MNewTripSheet.test.tsx index 6685c76e8..976320c4b 100644 --- a/client/tests/unit/mobile/dashboard/MNewTripSheet.test.tsx +++ b/client/tests/unit/mobile/dashboard/MNewTripSheet.test.tsx @@ -321,7 +321,7 @@ describe('MNewTripSheet', () => { it('FE-MOB-NTSH-017: create mode previews the picked Unsplash photo without a request', async () => { vi.spyOn(tripsApi, 'searchCoverImages').mockResolvedValue({ - photos: [{ id: 'p1', url: 'https://img/full.jpg', thumb: 'https://img/thumb.jpg', photographer: 'Ada' }], + photos: [{ id: 'p1', url: 'https://img/full.jpg', thumb: 'https://img/thumb.jpg', description: 'Icelandic waterfall', photographer: 'Ada' }], }); const update = vi.spyOn(tripsApi, 'update'); render( {}} onSave={() => {}} />); @@ -330,6 +330,7 @@ describe('MNewTripSheet', () => { fireEvent.click(screen.getByRole('button', { name: 'Search Unsplash' })); const pick = await screen.findByRole('button', { name: 'Use Unsplash photo by Ada' }); + expect(screen.getByAltText('Icelandic waterfall')).toHaveAttribute('title', 'Icelandic waterfall'); expect(screen.getByText('Ada')).toBeInTheDocument(); fireEvent.click(pick); @@ -355,7 +356,10 @@ describe('MNewTripSheet', () => { fireEvent.change(screen.getByPlaceholderText('e.g. Summer in Japan'), { target: { value: 'Iceland' } }); fireEvent.click(screen.getByRole('button', { name: 'Search Unsplash' })); - fireEvent.click(await screen.findByRole('button', { name: 'Use Unsplash photo by Unsplash' })); + const pick = await screen.findByRole('button', { name: 'Use Unsplash photo by Unsplash' }); + expect(pick.querySelector('img')).toHaveAttribute('alt', ''); + expect(pick.querySelector('img')).not.toHaveAttribute('title'); + fireEvent.click(pick); fireEvent.click(screen.getByRole('button', { name: 'Create New Trip' })); await waitFor(() => expect(update).toHaveBeenCalledWith(77, { cover_image: 'https://img/full.jpg' }));