1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Button } from '@material-ui/core';
7 import { mount, configure } from 'enzyme';
8 import * as Adapter from 'enzyme-adapter-react-16';
9 import * as CopyToClipboard from 'react-copy-to-clipboard';
10 import { TokenDialogComponent } from './token-dialog';
12 configure({ adapter: new Adapter() });
14 jest.mock('toggle-selection', () => () => () => null);
16 describe('<CurrentTokenDialog />', () => {
24 apiHost: 'example.com',
30 describe('Get API Token dialog', () => {
32 wrapper = mount(<TokenDialogComponent {...props} />);
35 it('should include API host and token', () => {
36 expect(wrapper.html()).toContain('export ARVADOS_API_HOST=example.com');
37 expect(wrapper.html()).toContain('export ARVADOS_API_TOKEN=xxxtokenxxx');
40 it('should show the token expiration if present', () => {
41 expect(props.tokenExpiration).toBeUndefined();
42 expect(wrapper.html()).toContain('This token does not have an expiration date');
44 const someDate = '2140-01-01T00:00:00.000Z'
45 props.tokenExpiration = new Date(someDate);
46 wrapper = mount(<TokenDialogComponent {...props} />);
47 expect(wrapper.html()).toContain(props.tokenExpiration.toLocaleString());
50 it('should show a create new token button when allowed', () => {
51 expect(props.canCreateNewTokens).toBeFalsy();
52 expect(wrapper.html()).not.toContain('GET NEW TOKEN');
54 props.canCreateNewTokens = true;
55 wrapper = mount(<TokenDialogComponent {...props} />);
56 expect(wrapper.html()).toContain('GET NEW TOKEN');
60 describe('copy to clipboard button', () => {
62 wrapper = mount(<TokenDialogComponent {...props} />);
65 it('should copy API TOKEN to the clipboard', () => {
67 wrapper.find(CopyToClipboard).find(Button).simulate('click');
70 expect(props.dispatch).toHaveBeenCalledWith({
74 message: 'Shell code block copied',
76 type: 'OPEN_SNACKBAR',