From edcdf0ae72c56bf4aa05f93ed2877faa3a5e75c4 Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Thu, 13 Jun 2024 09:10:14 -0400 Subject: [PATCH 1/1] 21621: Add unit test for json copy to clipboard Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- .../actions/copy-to-clipboard-action.test.tsx | 2 +- .../src/views/process-panel/process-io-card.test.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/workbench2/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx b/services/workbench2/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx index 898287399d..9b6828b6cc 100644 --- a/services/workbench2/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx +++ b/services/workbench2/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx @@ -33,4 +33,4 @@ describe('CopyToClipboardAction', () => { // and expect(props.onClick).toHaveBeenCalled(); }); -}); \ No newline at end of file +}); diff --git a/services/workbench2/src/views/process-panel/process-io-card.test.tsx b/services/workbench2/src/views/process-panel/process-io-card.test.tsx index 38061e3f06..33dea66e46 100644 --- a/services/workbench2/src/views/process-panel/process-io-card.test.tsx +++ b/services/workbench2/src/views/process-panel/process-io-card.test.tsx @@ -14,11 +14,15 @@ import { DefaultView } from "components/default-view/default-view"; import { DefaultVirtualCodeSnippet } from "components/default-code-snippet/default-virtual-code-snippet"; import { ProcessOutputCollectionFiles } from './process-output-collection-files'; import { MemoryRouter } from 'react-router-dom'; +import { CopyIcon } from 'components/icon/icon'; +import copy from 'copy-to-clipboard'; // Mock collection files component since it just needs to exist jest.mock('views/process-panel/process-output-collection-files'); // Mock autosizer for the io panel virtual list jest.mock('react-virtualized-auto-sizer', () => ({ children }: any) => children({ height: 600, width: 600 })); +// Mock copy to clipboard +jest.mock('copy-to-clipboard'); configure({ adapter: new Adapter() }); @@ -92,7 +96,7 @@ describe('renderers', () => { expect(panel.find(DefaultView).text()).toEqual('No parameters found'); }); - it('shows main process with raw', () => { + it('shows main process with raw and allows copying json', () => { // when const raw = {some: 'data'}; let panel = mount( @@ -112,6 +116,10 @@ describe('renderers', () => { expect(panel.find(CircularProgress).exists()).toBeFalsy(); expect(panel.find(Tab).length).toBe(1); expect(panel.find(DefaultVirtualCodeSnippet).text()).toContain(JSON.stringify(raw, null, 2).replace(/\n/g, '')); + + // when + panel.find(CopyIcon).simulate('click'); + expect(copy).toHaveBeenCalledWith(JSON.stringify(raw, null, 2), undefined); }); it('shows main process with params', () => { -- 2.30.2