a23bbcf9eb7e336b447d9a1c21c0855d6809030f
[arvados-workbench2.git] / src / components / file-tree / file-thumbnail.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { configure, mount } from "enzyme";
7 import { FileThumbnail } from "./file-thumbnail";
8 import { CollectionFileType } from '../../models/collection-file';
9 import * as Adapter from 'enzyme-adapter-react-16';
10 import { Provider } from "react-redux";
11 import { combineReducers, createStore } from "redux";
12
13 configure({ adapter: new Adapter() });
14
15 jest.mock('is-image', () => ({
16     'default': () => true,
17 }));
18
19 let store;
20
21 describe("<FileThumbnail />", () => {
22     let file;
23
24     beforeEach(() => {
25         const initialAuthState = {
26             config: {
27                 keepWebServiceUrl: 'http://example.com/',
28                 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
29             }
30         }
31         store = createStore(combineReducers({
32             auth: (state: any = initialAuthState, action: any) => state,
33         }));
34
35         file = {
36             name: 'test-image',
37             type: CollectionFileType.FILE,
38             url: 'http://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/zzzzz-gj3su-0123456789abcde/xxxxxxtokenxxxxx/test-image.jpg',
39             size: 300
40         };
41     });
42
43     it("renders file thumbnail with proper src", () => {
44         const fileThumbnail = mount(<Provider store={store}><FileThumbnail file={file} /></Provider>);
45         expect(fileThumbnail.html()).toBe('<img class="Component-thumbnail-1" alt="test-image" src="http://zzzzz-4zz18-0123456789abcde.collections.example.com/test-image.jpg?api_token=v2/zzzzz-gj3su-0123456789abcde/xxxxxxtokenxxxxx">');
46     });
47 });