Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carina Ursu <[email protected]>
  • Loading branch information
ursucarina committed Feb 14, 2023
1 parent a9b5ddd commit 504f874
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -25,7 +41,51 @@ const node2 = {
};

describe('ExecutionDetails > Timeline > TaskNames', () => {
const renderComponent = props => render(<TaskNames {...props} />);
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(
<QueryClientProvider client={queryClient}>
<NodeExecutionDetailsContextProvider workflowId={mockWorkflowId}>
<NodeExecutionsByIdContext.Provider
value={{
nodeExecutionsById,
setCurrentNodeExecutionsById: () => {},
}}
>
<TaskNames {...props} />
</NodeExecutionsByIdContext.Provider>
</NodeExecutionDetailsContextProvider>
</QueryClientProvider>,
);
};

it('should render task names list', () => {
const nodes = [node1, node2];
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => <div data-testid="expander"></div>),
}));

const columns = [];
const node = {
id: 'n1',
Expand All @@ -44,15 +40,15 @@ describe('Executions > Tables > NodeExecutionRow', () => {
);
});

const renderComponent = props =>
render(
const renderComponent = props => {
return render(
<QueryClientProvider client={queryClient}>
<NodeExecutionDetailsContextProvider workflowId={mockWorkflowId}>
<NodeExecutionRow {...props} />
</NodeExecutionDetailsContextProvider>
</QueryClientProvider>,
);

};
it('should not render expander if node is a leaf', async () => {
const { queryByRole, queryByTestId } = renderComponent({
columns,
Expand All @@ -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,
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ describe('NodeExecutionsTableExecutions > Tables > NodeExecutionsTable', () => {
render(
<QueryClientProvider client={queryClient}>
<NodeExecutionDetailsContextProvider workflowId={mockWorkflowId}>
<NodeExecutionsByIdContext.Provider value={nodeExecutionsById}>
<NodeExecutionsByIdContext.Provider
value={{
nodeExecutionsById,
setCurrentNodeExecutionsById: () => {},
}}
>
<NodeExecutionsTable
initialNodes={initialNodes}
filteredNodes={filteredNodes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('ResumeSignalForm', () => {
}}
>
<NodeExecutionsByIdContext.Provider
value={mockNodeExecutionsById}
value={{ nodeExecutionsById: mockNodeExecutionsById }}
>
<ResumeSignalForm
onClose={onClose}
Expand Down

0 comments on commit 504f874

Please sign in to comment.