From 9dadad58b9f52edc70f404e87f02be9f71ae8212 Mon Sep 17 00:00:00 2001 From: Joshua Kitenge Date: Thu, 5 Dec 2024 15:25:22 +0000 Subject: [PATCH] address review comments --- cypress/e2e/with_mock_data/items.cy.ts | 4 +- src/api/api.types.tsx | 2 +- src/api/images.test.tsx | 12 ++++++ src/api/images.tsx | 11 +++-- ...eInformationDialog.component.test.tsx.snap | 2 +- .../images/galleryLightbox.component.tsx | 3 +- src/common/images/imageGallery.component.tsx | 16 ++++++- .../imageInformationDialog.component.tsx | 3 +- .../images/thumbnailImage.component.test.tsx | 4 +- .../images/thumbnailImage.component.tsx | 42 +++++++------------ src/common/preservedTableState.component.tsx | 2 +- src/mocks/handlers.ts | 6 ++- 12 files changed, 63 insertions(+), 44 deletions(-) diff --git a/cypress/e2e/with_mock_data/items.cy.ts b/cypress/e2e/with_mock_data/items.cy.ts index d9a3ca47b..9ef8875b6 100644 --- a/cypress/e2e/with_mock_data/items.cy.ts +++ b/cypress/e2e/with_mock_data/items.cy.ts @@ -707,7 +707,7 @@ describe('Items', () => { ).should('exist'); cy.findByText('Gallery').click(); - cy.findByText('The image cannot be loaded').should('exist'); + cy.findByAltText('The image cannot be loaded').should('exist'); }); it('displays and hides filters, applies and clears name filter on gallery view', () => { @@ -800,7 +800,7 @@ describe('Items', () => { cy.findByText('Gallery').click(); - cy.findByText('The image cannot be loaded').click(); + cy.findByAltText('The image cannot be loaded').click(); cy.findByTestId('galleryLightBox').within(() => { cy.findByText('File name: stfc-logo-blue-text.png').should('exist'); cy.findByText('Title: stfc-logo-blue-text').should('exist'); diff --git a/src/api/api.types.tsx b/src/api/api.types.tsx index 3e3089929..1cbd1dd83 100644 --- a/src/api/api.types.tsx +++ b/src/api/api.types.tsx @@ -258,6 +258,6 @@ export interface APIImage thumbnail_base64: string; } -export interface ImageGet extends APIImage { +export interface APIImageWithURL extends APIImage { url: string; } diff --git a/src/api/images.test.tsx b/src/api/images.test.tsx index 164cb41e6..e4a20b8ce 100644 --- a/src/api/images.test.tsx +++ b/src/api/images.test.tsx @@ -32,6 +32,18 @@ describe('images api functions', () => { expect(result.current.data?.length).toEqual(1); }); + + it('sends request to fetch primary image data and returns successful empty list response', async () => { + const { result } = renderHook(() => useGetImages('90', true), { + wrapper: hooksWrapperWithProviders(), + }); + + await waitFor(() => { + expect(result.current.isSuccess).toBeTruthy(); + }); + + expect(result.current.data?.length).toEqual(0); + }); }); describe('useGetImage', () => { diff --git a/src/api/images.tsx b/src/api/images.tsx index 60ff94874..e876c6441 100644 --- a/src/api/images.tsx +++ b/src/api/images.tsx @@ -1,21 +1,20 @@ import { useQuery, UseQueryResult } from '@tanstack/react-query'; import { AxiosError } from 'axios'; import { storageApi } from './api'; -import { APIImage, ImageGet } from './api.types'; +import { APIImage, APIImageWithURL } from './api.types'; -export const getImage = async (id: string): Promise => { +export const getImage = async (id: string): Promise => { return storageApi.get(`/images/${id}`).then((response) => { return response.data; }); }; export const useGetImage = ( - id?: string -): UseQueryResult => { + id: string +): UseQueryResult => { return useQuery({ queryKey: ['Image', id], - queryFn: () => getImage(id ?? ''), - enabled: !!id, + queryFn: () => getImage(id), }); }; diff --git a/src/common/images/__snapshots__/imageInformationDialog.component.test.tsx.snap b/src/common/images/__snapshots__/imageInformationDialog.component.test.tsx.snap index 4fffa0e39..a836d92bc 100644 --- a/src/common/images/__snapshots__/imageInformationDialog.component.test.tsx.snap +++ b/src/common/images/__snapshots__/imageInformationDialog.component.test.tsx.snap @@ -8,7 +8,7 @@ exports[`Image Information dialog Component > renders dialog correctly 1`] = ` aria-hidden="true" />