Merge branch '17308-property-editor-fixes'
[arvados-workbench2.git] / src / views-components / current-token-dialog / current-token-dialog.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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 { CurrentTokenDialogComponent } from './current-token-dialog';
11
12 configure({ adapter: new Adapter() });
13
14 jest.mock('toggle-selection', () => () => () => null);
15
16 describe('<CurrentTokenDialog />', () => {
17   let props;
18   let wrapper;
19
20   beforeEach(() => {
21     props = {
22       classes: {},
23       data: {
24         currentToken: '123123123123',
25       },
26       open: true,
27       dispatch: jest.fn(),
28     };
29   });
30
31   describe('copy to clipboard', () => {
32     beforeEach(() => {
33       wrapper = mount(<CurrentTokenDialogComponent {...props} />);
34     });
35
36     it('should copy API TOKEN to the clipboard', () => {
37       // when
38       wrapper.find(CopyToClipboard).find(Button).simulate('click');
39
40       // and
41       expect(props.dispatch).toHaveBeenCalledWith({
42         payload: {
43           hideDuration: 2000,
44           kind: 1,
45           message: 'Token copied to clipboard',
46         },
47         type: 'OPEN_SNACKBAR',
48       });
49     });
50   });
51 });