From 7295d9306fa0b080836d8f535f0f26cd8d34fcd0 Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:56:14 +0800 Subject: [PATCH] fix(web): name image previewer actions (#40283) --- .../image-previewer/__tests__/index.spec.tsx | 19 +++++++------------ .../datasets/common/image-previewer/index.tsx | 6 ++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/web/app/components/datasets/common/image-previewer/__tests__/index.spec.tsx b/web/app/components/datasets/common/image-previewer/__tests__/index.spec.tsx index ce76a269ad2..29fdb2a9cfa 100644 --- a/web/app/components/datasets/common/image-previewer/__tests__/index.spec.tsx +++ b/web/app/components/datasets/common/image-previewer/__tests__/index.spec.tsx @@ -32,15 +32,11 @@ const images = [ const successfulResponse = () => new Response(new Blob(['test'], { type: 'image/png' })) -const getPreviewButtons = () => { - const [closeButton, previousButton, nextButton] = screen.getAllByRole('button') - - expect(closeButton).toBeInTheDocument() - expect(previousButton).toBeInTheDocument() - expect(nextButton).toBeInTheDocument() - - return { closeButton: closeButton!, previousButton: previousButton!, nextButton: nextButton! } -} +const getPreviewButtons = () => ({ + closeButton: screen.getByRole('button', { name: 'common.operation.close' }), + previousButton: screen.getByRole('button', { name: 'common.pagination.previous' }), + nextButton: screen.getByRole('button', { name: 'common.pagination.next' }), +}) describe('ImagePreviewer', () => { beforeEach(() => { @@ -137,10 +133,9 @@ describe('ImagePreviewer', () => { render() expect(await screen.findByText(/Failed to load image/)).toHaveTextContent(images[0]!.url) - const [, retryButton] = screen.getAllByRole('button') - expect(retryButton).toBeInTheDocument() + const retryButton = screen.getByRole('button', { name: 'common.operation.retry' }) - await user.click(retryButton!) + await user.click(retryButton) expect(await screen.findByRole('img', { name: 'image1.png' })).toBeInTheDocument() expect(mockFetch).toHaveBeenCalledTimes(4) diff --git a/web/app/components/datasets/common/image-previewer/index.tsx b/web/app/components/datasets/common/image-previewer/index.tsx index a334a8a1fe5..597d8e65e08 100644 --- a/web/app/components/datasets/common/image-previewer/index.tsx +++ b/web/app/components/datasets/common/image-previewer/index.tsx @@ -4,6 +4,7 @@ import { Kbd } from '@langgenius/dify-ui/kbd' import { RiArrowLeftLine, RiArrowRightLine, RiCloseLine, RiRefreshLine } from '@remixicon/react' import { formatForDisplay, useHotkey } from '@tanstack/react-hotkeys' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useTranslation } from 'react-i18next' import Loading from '@/app/components/base/loading' import { formatFileSize } from '@/utils/format' @@ -29,6 +30,7 @@ type ImagePreviewerProps = { } const ImagePreviewer = ({ images, initialIndex = 0, onClose }: ImagePreviewerProps) => { + const { t } = useTranslation() const [currentIndex, setCurrentIndex] = useState(initialIndex) const [cachedImages, setCachedImages] = useState>(() => { return images.reduce( @@ -159,6 +161,7 @@ const ImagePreviewer = ({ images, initialIndex = 0, onClose }: ImagePreviewerPro