test: unit-tests integration-tests
-build: test
+build: yarn-install
VERSION=$(VERSION) yarn build
$(DEB_FILE): build
cy.get('[data-cy=collection-files-panel-options-btn]')
.click()
cy.get('[data-cy=context-menu]')
- .should('contain', 'Download selected')
- .and(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
+ // .should('contain', 'Download selected')
+ .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
.type('{esc}'); // Collapse the options menu
// File item 'more options' button
cy.get('[data-cy=file-item-options-btn')
})
})
})
-})
\ No newline at end of file
+})
loggedIn: boolean;
status: SessionStatus;
active: boolean;
+ userIsActive: boolean;
apiRevision: number;
}
return this.getStorage().getItem(HOME_CLUSTER) || undefined;
}
+ public getApiClient() {
+ return this.apiClient;
+ }
+
public removeUser() {
this.getStorage().removeItem(USER_EMAIL_KEY);
this.getStorage().removeItem(USER_FIRST_NAME_KEY);
window.location.assign(`${this.baseUrl || ""}/logout?return_to=${currentUrl}`);
}
- public getUserDetails = (): Promise<User> => {
+ public getUserDetails = (showErrors?: boolean): Promise<User> => {
const reqId = uuid();
this.actions.progressFn(reqId, true);
return this.apiClient
})
.catch(e => {
this.actions.progressFn(reqId, false);
- this.actions.errorFn(reqId, e);
+ this.actions.errorFn(reqId, e, showErrors);
throw e;
});
}
clusterId: cfg.uuidPrefix,
remoteHost: cfg.rootUrl,
baseUrl: cfg.baseUrl,
- name: user ? getUserDisplayName(user): '',
+ name: user ? getUserDisplayName(user) : '',
email: user ? user.email : '',
+ userIsActive: user ? user.isActive : false,
token: this.getApiToken(),
loggedIn: true,
active: true,
import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
import { RootState } from "~/store/store";
import { ServiceRepository, createServices, setAuthorizationHeader } from "~/services/services";
-import Axios from "axios";
+import Axios, { AxiosInstance } from "axios";
import { User, getUserDisplayName } from "~/models/user";
import { authActions } from "~/store/auth/auth-action";
import {
import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
import * as jsSHA from "jssha";
-const getClusterConfig = async (origin: string): Promise<Config | null> => {
+const getClusterConfig = async (origin: string, apiClient: AxiosInstance): Promise<Config | null> => {
let configFromDD: Config | undefined;
try {
- const dd = (await Axios.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
+ const dd = (await apiClient.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
configFromDD = {
baseUrl: normalizeURLPath(dd.baseUrl),
keepWebServiceUrl: dd.keepWebServiceUrl,
};
} catch { }
- // Try the new public config endpoint
+ // Try public config endpoint
try {
- const config = (await Axios.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
+ const config = (await apiClient.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
return { ...buildConfig(config), apiRevision: configFromDD ? configFromDD.apiRevision : 0 };
} catch { }
return null;
};
-const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> => {
+const getRemoteHostConfig = async (remoteHost: string, useApiClient?: AxiosInstance): Promise<Config | null> => {
+ const apiClient = useApiClient || Axios.create({ headers: {} });
+
let url = remoteHost;
if (url.indexOf('://') < 0) {
url = 'https://' + url;
const origin = new URL(url).origin;
// Maybe it is an API server URL, try fetching config and discovery doc
- let r = await getClusterConfig(origin);
+ let r = await getClusterConfig(origin, apiClient);
if (r !== null) {
return r;
}
// Maybe it is a Workbench2 URL, try getting config.json
try {
- r = await getClusterConfig((await Axios.get<any>(`${origin}/config.json`)).data.API_HOST);
+ r = await getClusterConfig((await apiClient.get<any>(`${origin}/config.json`)).data.API_HOST, apiClient);
if (r !== null) {
return r;
}
// Maybe it is a Workbench1 URL, try getting status.json
try {
- r = await getClusterConfig((await Axios.get<any>(`${origin}/status.json`)).data.apiBaseURL);
+ r = await getClusterConfig((await apiClient.get<any>(`${origin}/status.json`)).data.apiBaseURL, apiClient);
if (r !== null) {
return r;
}
const svc = createServices(config, { progressFn: () => { }, errorFn: () => { } });
setAuthorizationHeader(svc, saltedToken);
- const user = await svc.authService.getUserDetails();
+ const user = await svc.authService.getUserDetails(false);
return {
user,
token: saltedToken,
};
};
-export const validateSession = (session: Session, activeSession: Session) =>
+export const validateSession = (session: Session, activeSession: Session, useApiClient?: AxiosInstance) =>
async (dispatch: Dispatch): Promise<Session> => {
dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED }));
session.loggedIn = false;
session.baseUrl = baseUrl;
session.token = token;
session.email = user.email;
+ session.userIsActive = user.isActive;
session.uuid = user.uuid;
session.name = getUserDisplayName(user);
session.loggedIn = true;
};
let fail: Error | null = null;
- const config = await getRemoteHostConfig(session.remoteHost);
+ const config = await getRemoteHostConfig(session.remoteHost, useApiClient);
if (config !== null) {
dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config }));
try {
return session;
};
-export const validateSessions = () =>
+export const validateSessions = (useApiClient?: AxiosInstance) =>
async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
const sessions = getState().auth.sessions;
const activeSession = getActiveSession(sessions);
override it using Dispatch<any>. This
pattern is used in a bunch of different
places in Workbench2. */
- await dispatch(validateSession(session, activeSession));
+ await dispatch(validateSession(session, activeSession, useApiClient));
} catch (e) {
- dispatch(snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- kind: SnackbarKind.ERROR
- }));
+ // Don't do anything here. User may get
+ // spammed with multiple messages that are not
+ // helpful. They can see the individual
+ // errors by going to site manager and trying
+ // to toggle the session.
}
}
}
status: SessionStatus.VALIDATED,
active: false,
email: user.email,
+ userIsActive: user.isActive,
name: getUserDisplayName(user),
uuid: user.uuid,
baseUrl: config.baseUrl,
(dispatch: Dispatch<any>) => {
const sessions = authService.buildSessions(config, user);
dispatch(authActions.SET_SESSIONS(sessions));
- dispatch(validateSessions());
+ dispatch(validateSessions(authService.getApiClient()));
};
export const loadSiteManagerPanel = () =>
import { ServiceRepository, createServices } from "~/services/services";
import { configureStore, RootStore } from "../store";
import { createBrowserHistory } from "history";
-import { mockConfig } from '~/common/config';
+import { mockConfig, DISCOVERY_DOC_PATH, } from '~/common/config';
import { ApiActions } from "~/services/api/api-actions";
import { ACCOUNT_LINK_STATUS_KEY } from '~/services/link-account-service/link-account-service';
import Axios from "axios";
prefs: {}
});
+ axiosMock
+ .onGet("https://xc59z.arvadosapi.com/discovery/v1/apis/arvados/v1/rest")
+ .reply(200, {
+ baseUrl: "https://xc59z.arvadosapi.com/arvados/v1",
+ keepWebServiceUrl: "",
+ remoteHosts: {},
+ rootUrl: "https://xc59z.arvadosapi.com",
+ uuidPrefix: "xc59z",
+ websocketUrl: "",
+ workbenchUrl: "",
+ workbench2Url: "",
+ revision: 12345678
+ });
+
importMocks.push(ImportMock.mockFunction(servicesModule, 'createServices', services));
// Only test the case when a link account operation is not being cancelled
"rootUrl": "https://zzzzz.arvadosapi.com",
"uuidPrefix": "zzzzz",
},
+ "xc59z": mockConfig({
+ apiRevision: 12345678,
+ baseUrl: "https://xc59z.arvadosapi.com/arvados/v1",
+ rootUrl: "https://xc59z.arvadosapi.com",
+ uuidPrefix: "xc59z"
+ })
},
remoteHosts: {
zzzzz: "zzzzz.arvadosapi.com",
"name": "John Doe",
"apiRevision": 12345678,
"uuid": "zzzzz-tpzed-abcefg",
+ "userIsActive": true
}, {
"active": false,
"baseUrl": "",
// TODO: Add remaining action tests
/*
- it('should fire external url to login', () => {
- const initialState = undefined;
- window.location.assign = jest.fn();
- reducer(initialState, authActions.LOGIN());
- expect(window.location.assign).toBeCalledWith(
- `/login?return_to=${window.location.protocol}//${window.location.host}/token`
- );
- });
-
- it('should fire external url to logout', () => {
- const initialState = undefined;
- window.location.assign = jest.fn();
- reducer(initialState, authActions.LOGOUT());
- expect(window.location.assign).toBeCalledWith(
- `/logout?return_to=${location.protocol}//${location.host}`
- );
- });
- */
+ it('should fire external url to login', () => {
+ const initialState = undefined;
+ window.location.assign = jest.fn();
+ reducer(initialState, authActions.LOGIN());
+ expect(window.location.assign).toBeCalledWith(
+ `/login?return_to=${window.location.protocol}//${window.location.host}/token`
+ );
+ });
+
+ it('should fire external url to logout', () => {
+ const initialState = undefined;
+ window.location.assign = jest.fn();
+ reducer(initialState, authActions.LOGOUT());
+ expect(window.location.assign).toBeCalledWith(
+ `/logout?return_to=${location.protocol}//${location.host}`
+ );
+ });
+ */
});
import { ContextMenuActionSet } from "~/views-components/context-menu/context-menu-action-set";
import { collectionPanelFilesAction, openMultipleFilesRemoveDialog } from "~/store/collection-panel/collection-panel-files/collection-panel-files-actions";
import { openCollectionPartialCopyDialog, openCollectionPartialCopyToSelectedCollectionDialog } from '~/store/collections/collection-partial-copy-actions';
-import { DownloadCollectionFileAction } from "~/views-components/context-menu/actions/download-collection-file-action";
+// import { DownloadCollectionFileAction } from "~/views-components/context-menu/actions/download-collection-file-action";
export const readOnlyCollectionFilesActionSet: ContextMenuActionSet = [[
{
dispatch(collectionPanelFilesAction.UNSELECT_ALL_COLLECTION_FILES());
}
},
- {
- component: DownloadCollectionFileAction,
- execute: () => { return; }
- },
+ // { // Disabled for now as we need to create backend version of this feature which will be less buggy
+ // component: DownloadCollectionFileAction,
+ // execute: () => { return; }
+ // },
{
name: "Create a new collection with selected",
execute: dispatch => {
--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import axios from 'axios';
+import { configure, shallow } from "enzyme";
+import * as Adapter from 'enzyme-adapter-react-16';
+import { ListItem } from '@material-ui/core';
+import * as JSZip from 'jszip';
+import { DownloadAction } from './download-action';
+
+configure({ adapter: new Adapter() });
+
+jest.mock('axios');
+
+jest.mock('file-saver', () => ({
+ saveAs: jest.fn(),
+}));
+
+const mock = {
+ file: jest.fn(),
+ generateAsync: jest.fn().mockImplementation(() => Promise.resolve('test')),
+};
+
+jest.mock('jszip', () => jest.fn().mockImplementation(() => mock));
+
+describe('<DownloadAction />', () => {
+ let props;
+ let zip;
+
+ beforeEach(() => {
+ props = {};
+ zip = new JSZip();
+ (axios as any).get.mockImplementationOnce(() => Promise.resolve({ data: '1234' }));
+ });
+
+ it('should return null if missing href or kind of file in props', () => {
+ // when
+ const wrapper = shallow(<DownloadAction {...props} />);
+
+ // then
+ expect(wrapper.html()).toBeNull();
+ });
+
+ it('should return a element', () => {
+ // setup
+ props.href = '#';
+
+ // when
+ const wrapper = shallow(<DownloadAction {...props} />);
+
+ // then
+ expect(wrapper.html()).not.toBeNull();
+ });
+
+ it('should handle download', () => {
+ // setup
+ props = {
+ href: ['file1'],
+ kind: 'files',
+ download: [],
+ currentCollectionUuid: '123412-123123'
+ };
+ const wrapper = shallow(<DownloadAction {...props} />);
+
+ // when
+ wrapper.find(ListItem).simulate('click');
+
+ // then
+ expect(axios.get).toHaveBeenCalledWith(props.href[0]);
+ });
+});
\ No newline at end of file
//
// SPDX-License-Identifier: AGPL-3.0
-import * as React from "react";
-import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
-import { DownloadIcon } from "../../../components/icon/icon";
-import * as JSZip from "jszip";
+import * as React from 'react';
+import { ListItemIcon, ListItemText, ListItem } from '@material-ui/core';
+import { DownloadIcon } from '../../../components/icon/icon';
+import * as JSZip from 'jszip';
import * as FileSaver from 'file-saver';
import axios from 'axios';
const downloadProps = props.download ? { download: props.download } : {};
const createZip = (fileUrls: string[], download: string[]) => {
- const zip = new JSZip();
let id = 1;
- fileUrls.map((href: string) => {
- axios.get(href).then(response => response).then(({ data }: any) => {
- const splittedByDot = href.split('.');
- if (splittedByDot[splittedByDot.length - 1] !== 'json') {
- if (fileUrls.length === id) {
- zip.file(download[id - 1], data);
- zip.generateAsync({ type: 'blob' }).then((content) => {
- FileSaver.saveAs(content, `download-${props.currentCollectionUuid}.zip`);
- });
+ const zip = new JSZip();
+ const filteredFileUrls = fileUrls
+ .filter((href: string) => {
+ const letter = href.split('').pop();
+ return letter !== '/';
+ });
+
+ filteredFileUrls
+ .map((href: string) => {
+ axios.get(href).then(response => response).then(({ data }: any) => {
+ const splittedByDot = href.split('.');
+ if (splittedByDot[splittedByDot.length - 1] !== 'json') {
+ if (filteredFileUrls.length === id) {
+ zip.file(download[id - 1], data);
+ zip.generateAsync({ type: 'blob' }).then((content) => {
+ FileSaver.saveAs(content, `download-${props.currentCollectionUuid}.zip`);
+ });
+ } else {
+ zip.file(download[id - 1], data);
+ zip.generateAsync({ type: 'blob' });
+ }
} else {
- zip.file(download[id - 1], data);
+ zip.file(download[id - 1], JSON.stringify(data));
zip.generateAsync({ type: 'blob' });
}
- } else {
- zip.file(download[id - 1], JSON.stringify(data));
- zip.generateAsync({ type: 'blob' });
- }
- id++;
+ id++;
+ });
});
- });
};
return props.href || props.kind === 'files'
connect((state: RootState) => ({
buttonVisible: isButtonVisible(state)
}), {
- onDetailsPanelToggle: toggleDetailsPanel,
- })(
- withStyles(styles)(
- (props: MainContentBarProps & WithStyles<CssRules> & any) =>
- <Toolbar>
- <Grid container>
- <Grid item xs alignItems="center">
- <Breadcrumbs />
+ onDetailsPanelToggle: toggleDetailsPanel,
+ })(
+ withStyles(styles)(
+ (props: MainContentBarProps & WithStyles<CssRules> & any) =>
+ <Toolbar>
+ <Grid container>
+ <Grid container item xs alignItems="center">
+ <Breadcrumbs />
+ </Grid>
+ <Grid item>
+ <RefreshButton />
+ </Grid>
+ <Grid item>
+ {props.buttonVisible && <Tooltip title="Additional Info">
+ <IconButton color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
+ <DetailsIcon />
+ </IconButton>
+ </Tooltip>}
+ </Grid>
</Grid>
- <Grid item>
- <RefreshButton />
- </Grid>
- <Grid item>
- {props.buttonVisible && <Tooltip title="Additional Info">
- <IconButton color="inherit" className={props.classes.infoTooltip} onClick={props.onDetailsPanelToggle}>
- <DetailsIcon />
- </IconButton>
- </Tooltip>}
- </Grid>
- </Grid>
- </Toolbar>
- )
- );
+ </Toolbar>
+ )
+ );
export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
(props: SearchResultsPanelProps & WithStyles<CssRules, true>) => {
const homeCluster = props.user.uuid.substr(0, 5);
- const loggedIn = props.sessions.filter((ss) => ss.loggedIn);
+ const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
return <DataExplorer
id={SEARCH_RESULTS_PANEL_ID}
onRowClick={props.onItemClick}
disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
onClick={() => toggleSession(session)}>
- {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")}
+ {validating ? "Validating"
+ : (session.loggedIn ?
+ (session.userIsActive ? "Logged in" : "Inactive")
+ : "Logged out")}
</Button>
</TableCell>
<TableCell>