X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/825ea4fce4ba3568f6105c17e83f4769a9323759..7467e941ed63e8885144e90c9ca11929f738b13a:/src/views-components/token-dialog/token-dialog.test.tsx diff --git a/src/views-components/token-dialog/token-dialog.test.tsx b/src/views-components/token-dialog/token-dialog.test.tsx index 928001ab..400bb1e6 100644 --- a/src/views-components/token-dialog/token-dialog.test.tsx +++ b/src/views-components/token-dialog/token-dialog.test.tsx @@ -2,12 +2,22 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +// This mocks react-copy-to-clipboard's dependency module to avoid warnings +// from jest when running tests. As we're not testing copy-to-clipboard, it's +// safe to just mock it. +// https://github.com/nkbt/react-copy-to-clipboard/issues/106#issuecomment-605227151 +jest.mock('copy-to-clipboard', () => { + return jest.fn(); +}); + +import 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 Adapter from 'enzyme-adapter-react-16'; +import CopyToClipboard from 'react-copy-to-clipboard'; import { TokenDialogComponent } from './token-dialog'; +import { combineReducers, createStore } from 'redux'; +import { Provider } from 'react-redux'; configure({ adapter: new Adapter() }); @@ -16,6 +26,7 @@ jest.mock('toggle-selection', () => () => () => null); describe('', () => { let props; let wrapper; + let store; beforeEach(() => { props = { @@ -25,11 +36,25 @@ describe('', () => { open: true, dispatch: jest.fn(), }; + + const initialAuthState = { + localCluster: "zzzzz", + remoteHostsConfig: {}, + sessions: {}, + }; + + store = createStore(combineReducers({ + auth: (state: any = initialAuthState, action: any) => state, + })); }); describe('Get API Token dialog', () => { beforeEach(() => { - wrapper = mount(); + wrapper = mount( + + + + ); }); it('should include API host and token', () => { @@ -39,12 +64,15 @@ describe('', () => { it('should show the token expiration if present', () => { expect(props.tokenExpiration).toBeUndefined(); - expect(wrapper.html()).not.toContain('Expires at:'); + expect(wrapper.html()).toContain('This token does not have an expiration date'); const someDate = '2140-01-01T00:00:00.000Z' props.tokenExpiration = new Date(someDate); - wrapper = mount(); - expect(wrapper.html()).toContain('Expires at:'); + wrapper = mount( + + + ); + expect(wrapper.html()).toContain(props.tokenExpiration.toLocaleString()); }); it('should show a create new token button when allowed', () => { @@ -52,14 +80,20 @@ describe('', () => { expect(wrapper.html()).not.toContain('GET NEW TOKEN'); props.canCreateNewTokens = true; - wrapper = mount(); + wrapper = mount( + + + ); expect(wrapper.html()).toContain('GET NEW TOKEN'); }); }); describe('copy to clipboard button', () => { beforeEach(() => { - wrapper = mount(); + wrapper = mount( + + + ); }); it('should copy API TOKEN to the clipboard', () => {