1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 // This mocks react-copy-to-clipboard's dependency module to avoid warnings
6 // from jest when running tests. As we're not testing copy-to-clipboard, it's
7 // safe to just mock it.
8 // https://github.com/nkbt/react-copy-to-clipboard/issues/106#issuecomment-605227151
9 jest.mock('copy-to-clipboard', () => {
13 import React from 'react';
14 import { Button } from '@material-ui/core';
15 import { mount, configure } from 'enzyme';
16 import Adapter from 'enzyme-adapter-react-16';
17 import CopyToClipboard from 'react-copy-to-clipboard';
18 import { TokenDialogComponent } from './token-dialog';
19 import { combineReducers, createStore } from 'redux';
20 import { Provider } from 'react-redux';
22 configure({ adapter: new Adapter() });
24 jest.mock('toggle-selection', () => () => () => null);
26 describe('<CurrentTokenDialog />', () => {
35 apiHost: 'example.com',
40 const initialAuthState = {
41 localCluster: "zzzzz",
42 remoteHostsConfig: {},
46 store = createStore(combineReducers({
47 auth: (state: any = initialAuthState, action: any) => state,
51 describe('Get API Token dialog', () => {
54 <Provider store={store}>
55 <TokenDialogComponent {...props} />
60 it('should include API host and token', () => {
61 expect(wrapper.html()).toContain('export ARVADOS_API_HOST=example.com');
62 expect(wrapper.html()).toContain('export ARVADOS_API_TOKEN=xxxtokenxxx');
65 it('should show the token expiration if present', () => {
66 expect(props.tokenExpiration).toBeUndefined();
67 expect(wrapper.html()).toContain('This token does not have an expiration date');
69 const someDate = '2140-01-01T00:00:00.000Z'
70 props.tokenExpiration = new Date(someDate);
72 <Provider store={store}>
73 <TokenDialogComponent {...props} />
75 expect(wrapper.html()).toContain(props.tokenExpiration.toLocaleString());
78 it('should show a create new token button when allowed', () => {
79 expect(props.canCreateNewTokens).toBeFalsy();
80 expect(wrapper.html()).not.toContain('GET NEW TOKEN');
82 props.canCreateNewTokens = true;
84 <Provider store={store}>
85 <TokenDialogComponent {...props} />
87 expect(wrapper.html()).toContain('GET NEW TOKEN');
91 describe('Copy link to clipboard button', () => {
94 <Provider store={store}>
95 <TokenDialogComponent {...props} />
99 it('should copy API TOKEN to the clipboard', () => {
101 wrapper.find(CopyToClipboard).find(Button).simulate('click');
104 expect(props.dispatch).toHaveBeenCalledWith({
108 message: 'Shell code block copied',
110 type: 'OPEN_SNACKBAR',