16659: Added copy to clipboard button for the api token
[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 { shallow, configure } from "enzyme";
7 import * as Adapter from "enzyme-adapter-react-16";
8 import * as CopyToClipboard from "react-copy-to-clipboard";
9 import { CurrentTokenDialogComponent } from "./current-token-dialog";
10
11 configure({ adapter: new Adapter() });
12
13 describe("<CurrentTokenDialog />", () => {
14   let props;
15   let wrapper;
16
17   beforeEach(() => {
18     props = {
19       classes: {},
20       data: {
21         currentToken: "123123123123",
22       },
23       dispatch: jest.fn(),
24     };
25   });
26
27   describe("copy to clipboard", () => {
28     beforeEach(() => {
29       wrapper = shallow(<CurrentTokenDialogComponent {...props} />);
30     });
31
32     it("should copy API TOKEN to the clipboard", () => {
33       // when
34       wrapper.find(CopyToClipboard).props().onCopy();
35
36       // then
37       expect(props.dispatch).toHaveBeenCalledWith({
38         payload: {
39           hideDuration: 2000,
40           kind: 1,
41           message: "Token copied to clipboard",
42         },
43         type: "OPEN_SNACKBAR",
44       });
45     });
46   });
47 });