1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import configureMockStore from 'redux-mock-store'
7 import { Provider } from 'react-redux';
8 import { CollectionFileViewerAction } from './collection-file-viewer-action';
9 import { ContextMenuKind } from '../menu-item-sort';
10 import { createTree, initTreeNode, setNode } from "models/tree";
11 import { getInlineFileUrl, sanitizeToken } from "./helpers";
13 const middlewares = [];
14 const mockStore = configureMockStore(middlewares);
16 describe('CollectionFileViewerAction', () => {
18 const fileUrl = "https://download.host:12345/c=abcde-4zz18-abcdefghijklmno/t=v2/token2/token3/cat.jpg";
19 const insecureKeepInlineUrl = "https://download.host:12345/";
20 const secureKeepInlineUrl = "https://*.collections.host:12345/";
23 let filesTree = createTree();
24 let data = {id: "000", value: {"url": fileUrl}};
25 filesTree = setNode(initTreeNode(data))(filesTree);
30 keepWebServiceUrl: "https://download.host:12345/",
31 keepWebInlineServiceUrl: insecureKeepInlineUrl,
34 TrustAllContent: false
42 menuKind: ContextMenuKind.COLLECTION_FILE_ITEM,
50 collectionPanelFiles: filesTree
54 it('should hide open in new tab when unsafe', () => {
56 const store = mockStore(defaultStore);
59 cy.mount(<Provider store={store}>
60 <CollectionFileViewerAction />
63 // ensure cy.mount has been successful
64 cy.get('[data-cy-root').should('exist');
67 cy.get('[data-cy=open-in-new-tab]').should('have.length', 0);
70 it('should show open in new tab when TrustAllContent=true', () => {
72 let initialState = defaultStore;
73 initialState.auth.config.clusterConfig.Collections.TrustAllContent = true;
74 const store = mockStore(initialState);
77 cy.mount(<Provider store={store}>
78 <CollectionFileViewerAction />
82 cy.get('[data-cy=open-in-new-tab]').should('exist');
85 cy.get('[data-cy=open-in-new-tab]').should(
88 sanitizeToken(getInlineFileUrl(fileUrl, initialState.auth.config.keepWebServiceUrl, initialState.auth.config.keepWebInlineServiceUrl))
92 it('should show open in new tab when inline url is secure', () => {
94 let initialState = defaultStore;
95 initialState.auth.config.keepWebInlineServiceUrl = secureKeepInlineUrl;
96 const store = mockStore(initialState);
99 cy.mount(<Provider store={store}>
100 <CollectionFileViewerAction />
104 cy.get('[data-cy=open-in-new-tab]').should('exist');
107 sanitizeToken(getInlineFileUrl(fileUrl, initialState.auth.config.keepWebServiceUrl, initialState.auth.config.keepWebInlineServiceUrl))