From 504f8745120ff2c2af59859a3aa6d67f68b5e0d7 Mon Sep 17 00:00:00 2001 From: Carina Ursu Date: Tue, 14 Feb 2023 12:05:53 -0800 Subject: [PATCH] chore: fix tests Signed-off-by: Carina Ursu --- .../ExecutionDetails/test/TaskNames.test.tsx | 66 ++++++++++++++++++- .../Tables/test/NodeExecutionRow.test.tsx | 22 ++++--- .../Tables/test/NodeExecutionsTable.test.tsx | 7 +- .../LaunchForm/test/ResumeSignalForm.test.tsx | 2 +- 4 files changed, 82 insertions(+), 15 deletions(-) diff --git a/packages/console/src/components/Executions/ExecutionDetails/test/TaskNames.test.tsx b/packages/console/src/components/Executions/ExecutionDetails/test/TaskNames.test.tsx index d66bf3355..7a8807b39 100644 --- a/packages/console/src/components/Executions/ExecutionDetails/test/TaskNames.test.tsx +++ b/packages/console/src/components/Executions/ExecutionDetails/test/TaskNames.test.tsx @@ -1,11 +1,27 @@ import * as React from 'react'; import { render } from '@testing-library/react'; import { dTypes } from 'models/Graph/types'; +import { NodeExecutionDetailsContextProvider } from 'components/Executions/contextProvider/NodeExecutionDetails'; +import { QueryClient, QueryClientProvider } from 'react-query'; +import { NodeExecutionsByIdContext } from 'components/Executions/contexts'; +import { mockWorkflowId } from 'mocks/data/fixtures/types'; +import { createTestQueryClient } from 'test/utils'; +import { dateToTimestamp } from 'common/utils'; +import { createMockWorkflow } from 'models/__mocks__/workflowData'; import { TaskNames } from '../Timeline/TaskNames'; const onToggle = jest.fn(); const onAction = jest.fn(); +jest.mock('models/Workflow/api', () => { + const originalModule = jest.requireActual('models/Workflow/api'); + return { + __esModule: true, + ...originalModule, + getWorkflow: jest.fn().mockResolvedValue({}), + }; +}); + const node1 = { id: 'n1', scopedId: 'n1', @@ -25,7 +41,51 @@ const node2 = { }; describe('ExecutionDetails > Timeline > TaskNames', () => { - const renderComponent = props => render(); + let queryClient: QueryClient; + beforeEach(() => { + queryClient = createTestQueryClient(); + }); + + const renderComponent = props => { + const nodeExecutionsById = props.nodes.reduce( + (accumulator, currentValue) => { + accumulator[currentValue.id] = { + closure: { + createdAt: dateToTimestamp(new Date()), + outputUri: '', + phase: 1, + }, + metadata: currentValue.metadata, + id: { + executionId: { + domain: 'development', + name: 'MyWorkflow', + project: 'flytetest', + }, + nodeId: currentValue.id, + }, + inputUri: '', + scopedId: currentValue.scopedId, + }; + return accumulator; + }, + {}, + ); + return render( + + + {}, + }} + > + + + + , + ); + }; it('should render task names list', () => { const nodes = [node1, node2]; @@ -56,8 +116,8 @@ describe('ExecutionDetails > Timeline > TaskNames', () => { }, ]; const nodes = [ - { ...node1, nodes: nestedNodes }, - { ...node2, nodes: nestedNodes }, + { ...node1, metadata: { isParentNode: true }, nodes: nestedNodes }, + { ...node2, metadata: { isParentNode: true }, nodes: nestedNodes }, ]; const { getAllByTestId, getAllByTitle } = renderComponent({ nodes, diff --git a/packages/console/src/components/Executions/Tables/test/NodeExecutionRow.test.tsx b/packages/console/src/components/Executions/Tables/test/NodeExecutionRow.test.tsx index 24c4bdb05..fe1419661 100644 --- a/packages/console/src/components/Executions/Tables/test/NodeExecutionRow.test.tsx +++ b/packages/console/src/components/Executions/Tables/test/NodeExecutionRow.test.tsx @@ -14,10 +14,6 @@ import { NodeExecutionRow } from '../NodeExecutionRow'; jest.mock('components/Workflow/workflowQueries'); const { fetchWorkflow } = require('components/Workflow/workflowQueries'); -jest.mock('components/Executions/Tables/RowExpander', () => ({ - RowExpander: jest.fn(() =>
), -})); - const columns = []; const node = { id: 'n1', @@ -44,15 +40,15 @@ describe('Executions > Tables > NodeExecutionRow', () => { ); }); - const renderComponent = props => - render( + const renderComponent = props => { + return render( , ); - + }; it('should not render expander if node is a leaf', async () => { const { queryByRole, queryByTestId } = renderComponent({ columns, @@ -67,8 +63,14 @@ describe('Executions > Tables > NodeExecutionRow', () => { }); it('should render expander if node contains list of nodes', async () => { - const mockNode = { ...node, nodes: [node, node] }; - const { queryByRole, queryByTestId } = renderComponent({ + const mockNode = { + ...node, + nodes: [node, node], + }; + + (execution.metadata as any).isParentNode = true; + + const { queryByRole, queryByTitle } = renderComponent({ columns, node: mockNode, nodeExecution: execution, @@ -77,6 +79,6 @@ describe('Executions > Tables > NodeExecutionRow', () => { await waitFor(() => queryByRole('listitem')); expect(queryByRole('listitem')).toBeInTheDocument(); - expect(queryByTestId('expander')).toBeInTheDocument(); + expect(queryByTitle('Expand row')).toBeInTheDocument(); }); }); diff --git a/packages/console/src/components/Executions/Tables/test/NodeExecutionsTable.test.tsx b/packages/console/src/components/Executions/Tables/test/NodeExecutionsTable.test.tsx index 8aecbcbea..8460dc5e1 100644 --- a/packages/console/src/components/Executions/Tables/test/NodeExecutionsTable.test.tsx +++ b/packages/console/src/components/Executions/Tables/test/NodeExecutionsTable.test.tsx @@ -91,7 +91,12 @@ describe('NodeExecutionsTableExecutions > Tables > NodeExecutionsTable', () => { render( - + {}, + }} + > { }} >