From: Daniel Kutyła Date: Mon, 17 Aug 2020 18:37:55 +0000 (+0200) Subject: 16659: Added copy of full token, fixed tests X-Git-Tag: 2.1.0~16^2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/bbcdcd7b7582b43ca4853e436df383ff9dda465a 16659: Added copy of full token, fixed tests Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- bbcdcd7b7582b43ca4853e436df383ff9dda465a diff --cc .env index bd410081,bd410081..fd91b99c --- a/.env +++ b/.env @@@ -1,5 -1,5 +1,5 @@@ # Copyright (C) The Arvados Authors. All rights reserved. --# ++# # SPDX-License-Identifier: AGPL-3.0 REACT_APP_ARVADOS_CONFIG_URL=/config.json diff --cc src/views-components/current-token-dialog/current-token-dialog.test.tsx index 188076d7,00000000..eb405e94 mode 100644,000000..100644 --- a/src/views-components/current-token-dialog/current-token-dialog.test.tsx +++ b/src/views-components/current-token-dialog/current-token-dialog.test.tsx @@@ -1,47 -1,0 +1,51 @@@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + - import * as React from "react"; - import { shallow, configure } from "enzyme"; - import * as Adapter from "enzyme-adapter-react-16"; - import * as CopyToClipboard from "react-copy-to-clipboard"; - import { CurrentTokenDialogComponent } from "./current-token-dialog"; ++import * as React from 'react'; ++import { Button } from '@material-ui/core'; ++import { mount, configure } from 'enzyme'; ++import * as Adapter from 'enzyme-adapter-react-16'; ++import * as CopyToClipboard from 'react-copy-to-clipboard'; ++import { CurrentTokenDialogComponent } from './current-token-dialog'; + +configure({ adapter: new Adapter() }); + - describe("", () => { ++jest.mock('toggle-selection', () => () => () => null); ++ ++describe('', () => { + let props; + let wrapper; + + beforeEach(() => { + props = { + classes: {}, + data: { - currentToken: "123123123123", ++ currentToken: '123123123123', + }, ++ open: true, + dispatch: jest.fn(), + }; + }); + - describe("copy to clipboard", () => { ++ describe('copy to clipboard', () => { + beforeEach(() => { - wrapper = shallow(); ++ wrapper = mount(); + }); + - it("should copy API TOKEN to the clipboard", () => { ++ it('should copy API TOKEN to the clipboard', () => { + // when - wrapper.find(CopyToClipboard).props().onCopy(); ++ wrapper.find(CopyToClipboard).find(Button).simulate('click'); + - // then ++ // and + expect(props.dispatch).toHaveBeenCalledWith({ + payload: { + hideDuration: 2000, + kind: 1, - message: "Token copied to clipboard", ++ message: 'Token copied to clipboard', + }, - type: "OPEN_SNACKBAR", ++ type: 'OPEN_SNACKBAR', + }); + }); + }); +}); diff --cc src/views-components/current-token-dialog/current-token-dialog.tsx index 57b228f9,e5208d44..0ea24690 --- a/src/views-components/current-token-dialog/current-token-dialog.tsx +++ b/src/views-components/current-token-dialog/current-token-dialog.tsx @@@ -38,70 -31,51 +38,70 @@@ const styles: StyleRulesCallback & WithStyles; +type CurrentTokenProps = CurrentTokenDialogData & WithDialogProps<{}> & WithStyles & DispatchProp; -export const CurrentTokenDialog = - withStyles(styles)( - connect(getCurrentTokenDialogData)( - withDialog(CURRENT_TOKEN_DIALOG_NAME)( - class extends React.Component { - render() { - const { classes, open, closeDialog, ...data } = this.props; - return - Current Token - - - The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados with the proper permissions. - +export class CurrentTokenDialogComponent extends React.Component { + onCopy = (message: string) => { + this.props.dispatch(snackbarActions.OPEN_SNACKBAR({ + message, + hideDuration: 2000, + kind: SnackbarKind.SUCCESS + })); + } + + getSnippet = ({ apiHost, currentToken }: CurrentTokenDialogData) => + `HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*' - export ARVADOS_API_TOKEN=${currentToken} - export ARVADOS_API_HOST=${apiHost} - unset ARVADOS_API_HOST_INSECURE` ++export ARVADOS_API_TOKEN=${currentToken} ++export ARVADOS_API_HOST=${apiHost} ++unset ARVADOS_API_HOST_INSECURE` + + render() { + const { classes, open, closeDialog, ...data } = this.props; + return + Current Token + + + The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados with the proper permissions. - - For more information see - - Getting an API token. - - ++ + For more information see - ++ + Getting an API token. - ++ + - - - Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your account. - - - - Arvados - virtual machines - do this for you automatically. This setup is needed only when you use the API remotely (e.g., from your own workstation). - - - - - - ; - } + + - Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your klingenc account. - ++ Paste the following lines at a shell prompt to set up the necessary environment for Arvados SDKs to authenticate to your account. ++ + - this.onCopy('Token copied to clipboard')}> ++ this.onCopy('Token copied to clipboard')}> + + + + Arvados + virtual machines + do this for you automatically. This setup is needed only when you use the API remotely (e.g., from your own workstation). - ++ + + + + + ; } -))); +} + +export const CurrentTokenDialog = + withStyles(styles)( + connect(getCurrentTokenDialogData)( + withDialog(CURRENT_TOKEN_DIALOG_NAME)(CurrentTokenDialogComponent))); -const getSnippet = ({ apiHost, currentToken }: CurrentTokenDialogData) => -`HISTIGNORE=$HISTIGNORE:'export ARVADOS_API_TOKEN=*' -export ARVADOS_API_TOKEN=${currentToken} -export ARVADOS_API_HOST=${apiHost} -unset ARVADOS_API_HOST_INSECURE`;