Skip to content

Commit

Permalink
test: add describe getNodeInputData for test context
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgrozav committed Dec 13, 2023
1 parent 5b6d932 commit 663cd7c
Showing 1 changed file with 115 additions and 113 deletions.
228 changes: 115 additions & 113 deletions packages/editor-ui/src/composables/__tests__/useNodeHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,138 +17,108 @@ describe('useNodeHelpers()', () => {
vi.clearAllMocks();
});

it('should return an empty array when node is null', () => {
const { getNodeInputData } = useNodeHelpers();

const result = getNodeInputData(null);
expect(result).toEqual([]);
});
describe('getNodeInputData()', () => {
it('should return an empty array when node is null', () => {
const { getNodeInputData } = useNodeHelpers();

it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
const result = getNodeInputData(null);
expect(result).toEqual([]);
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});
it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
const result = getNodeInputData(node);
expect(result).toEqual([]);
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});
it('should return an empty array when workflowsStore.getWorkflowExecution() is null', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: null,
} as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

it('should return an empty array when resultData is not available', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: null,
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
const result = getNodeInputData(node);
expect(result).toEqual([]);
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when taskData is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [],
},
it('should return an empty array when resultData is not available', () => {
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: null,
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: 'test',
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});
const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return an empty array when taskData.data is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [{ data: undefined }],
it('should return an empty array when taskData is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [],
},
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual([]);
});
const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it('should return input data from inputOverride', () => {
const nodeName = 'Code';
const data = { hello: 'world' };
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [
{
inputOverride: {
main: [data],
},
},
],
it('should return an empty array when taskData.data is unavailable', () => {
const nodeName = 'Code';
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [{ data: undefined }],
},
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node, 0, 0, 'input');
expect(result).toEqual(data);
});
const result = getNodeInputData(node);
expect(result).toEqual([]);
});

it.each(['example', 'example.withdot', 'example.with.dots', 'example.with.dots and spaces'])(
'should return input data for "%s" node name, with given connection type and output index',
(nodeName) => {
it('should return input data from inputOverride', () => {
const nodeName = 'Code';
const data = { hello: 'world' };
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
Expand All @@ -157,7 +127,7 @@ describe('useNodeHelpers()', () => {
runData: {
[nodeName]: [
{
data: {
inputOverride: {
main: [data],
},
},
Expand All @@ -173,8 +143,40 @@ describe('useNodeHelpers()', () => {
type: 'test',
});

const result = getNodeInputData(node);
const result = getNodeInputData(node, 0, 0, 'input');
expect(result).toEqual(data);
},
);
});

it.each(['example', 'example.withdot', 'example.with.dots', 'example.with.dots and spaces'])(
'should return input data for "%s" node name, with given connection type and output index',
(nodeName) => {
const data = { hello: 'world' };
vi.mocked(useWorkflowsStore).mockReturnValue({
getWorkflowExecution: {
data: {
resultData: {
runData: {
[nodeName]: [
{
data: {
main: [data],
},
},
],
},
},
},
},
} as unknown as ReturnType<typeof useWorkflowsStore>);
const { getNodeInputData } = useNodeHelpers();
const node = createTestNode({
name: nodeName,
type: 'test',
});

const result = getNodeInputData(node);
expect(result).toEqual(data);
},
);
});
});

0 comments on commit 663cd7c

Please sign in to comment.