From 55c77cf6945551bbb2500c213be48db84315b445 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Mon, 7 Dec 2020 20:39:33 +0100 Subject: [PATCH] 16812: Fixed img preview for collection items MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- .../file-tree/file-thumbnail.test.tsx | 33 +++++++++++++++++++ src/components/file-tree/file-thumbnail.tsx | 3 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/components/file-tree/file-thumbnail.test.tsx diff --git a/src/components/file-tree/file-thumbnail.test.tsx b/src/components/file-tree/file-thumbnail.test.tsx new file mode 100644 index 00000000..708275bd --- /dev/null +++ b/src/components/file-tree/file-thumbnail.test.tsx @@ -0,0 +1,33 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from "react"; +import { shallow, configure } from "enzyme"; +import { FileThumbnail } from "./file-thumbnail"; +import { CollectionFileType } from '../../models/collection-file'; +import * as Adapter from 'enzyme-adapter-react-16'; + +configure({ adapter: new Adapter() }); + +jest.mock('is-image', () => ({ + 'default': () => true, +})); + +describe("", () => { + let file; + + beforeEach(() => { + file = { + name: 'test-image', + type: CollectionFileType.FILE, + url: 'http://test.com/c=test-hash/t=test-token/test-image.jpg', + size: 300 + }; + }); + + it("renders file thumbnail with proper src", () => { + const fileThumbnail = shallow(); + expect(fileThumbnail.html()).toBe('test-image'); + }); +}); diff --git a/src/components/file-tree/file-thumbnail.tsx b/src/components/file-tree/file-thumbnail.tsx index e1a0d5e0..8ab554a1 100644 --- a/src/components/file-tree/file-thumbnail.tsx +++ b/src/components/file-tree/file-thumbnail.tsx @@ -7,6 +7,7 @@ import isImage from 'is-image'; import { withStyles, WithStyles } from '@material-ui/core'; import { FileTreeData } from '~/components/file-tree/file-tree-data'; import { CollectionFileType } from '~/models/collection-file'; +import { sanitizeToken } from "~/views-components/context-menu/actions/helpers"; export interface FileThumbnailProps { file: FileTreeData; @@ -32,5 +33,5 @@ const ImageFileThumbnail = imageFileThumbnailStyle( {file.name} + src={sanitizeToken(file.url, false)} /> ); -- 2.30.2