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';
20 configure({ adapter: new Adapter() });
22 jest.mock('toggle-selection', () => () => () => null);
24 describe('<CurrentTokenDialog />', () => {
32 apiHost: 'example.com',
38 describe('Get API Token dialog', () => {
40 wrapper = mount(<TokenDialogComponent {...props} />);
43 it('should include API host and token', () => {
44 expect(wrapper.html()).toContain('export ARVADOS_API_HOST=example.com');
45 expect(wrapper.html()).toContain('export ARVADOS_API_TOKEN=xxxtokenxxx');
48 it('should show the token expiration if present', () => {
49 expect(props.tokenExpiration).toBeUndefined();
50 expect(wrapper.html()).toContain('This token does not have an expiration date');
52 const someDate = '2140-01-01T00:00:00.000Z'
53 props.tokenExpiration = new Date(someDate);
54 wrapper = mount(<TokenDialogComponent {...props} />);
55 expect(wrapper.html()).toContain(props.tokenExpiration.toLocaleString());
58 it('should show a create new token button when allowed', () => {
59 expect(props.canCreateNewTokens).toBeFalsy();
60 expect(wrapper.html()).not.toContain('GET NEW TOKEN');
62 props.canCreateNewTokens = true;
63 wrapper = mount(<TokenDialogComponent {...props} />);
64 expect(wrapper.html()).toContain('GET NEW TOKEN');
68 describe('copy to clipboard button', () => {
70 wrapper = mount(<TokenDialogComponent {...props} />);
73 it('should copy API TOKEN to the clipboard', () => {
75 wrapper.find(CopyToClipboard).find(Button).simulate('click');
78 expect(props.dispatch).toHaveBeenCalledWith({
82 message: 'Shell code block copied',
84 type: 'OPEN_SNACKBAR',