refactor(editor): Migrate workflows store to setup function with composition API (no-changelog) (#9270)

This commit is contained in:
Alex Grozav
2024-05-08 14:35:29 +03:00
committed by GitHub
parent 6b6e8dfc33
commit f64a41d617
9 changed files with 2002 additions and 1543 deletions

View File

@@ -6,7 +6,20 @@ import RunData from '@/components/RunData.vue';
import { STORES, VIEWS } from '@/constants';
import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
import { createComponentRenderer } from '@/__tests__/render';
import type { IRunDataDisplayMode } from '@/Interface';
import type { INodeUi, IRunDataDisplayMode } from '@/Interface';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { setActivePinia } from 'pinia';
const nodes = [
{
id: '1',
typeVersion: 1,
name: 'Test Node',
position: [0, 0],
type: 'test',
parameters: {},
},
] as INodeUi[];
describe('RunData', () => {
it('should render data correctly even when "item.json" has another "json" key', async () => {
@@ -81,8 +94,64 @@ describe('RunData', () => {
expect(getByTestId('ndv-binary-data_0')).toBeInTheDocument();
});
const render = (outputData: unknown[], displayMode: IRunDataDisplayMode) =>
createComponentRenderer(RunData, {
const render = (outputData: unknown[], displayMode: IRunDataDisplayMode) => {
const pinia = createTestingPinia({
initialState: {
[STORES.SETTINGS]: {
settings: merge({}, SETTINGS_STORE_DEFAULT_STATE.settings),
},
[STORES.NDV]: {
output: {
displayMode,
},
activeNodeName: 'Test Node',
},
[STORES.WORKFLOWS]: {
workflow: {
nodes,
},
workflowExecutionData: {
id: '1',
finished: true,
mode: 'trigger',
startedAt: new Date(),
workflowData: {
id: '1',
name: 'Test Workflow',
versionId: '1',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
active: false,
nodes: [],
connections: {},
},
data: {
resultData: {
runData: {
'Test Node': [
{
startTime: new Date().getTime(),
executionTime: new Date().getTime(),
data: {
main: [outputData],
},
source: [null],
},
],
},
},
},
},
},
},
});
setActivePinia(pinia);
const workflowsStore = useWorkflowsStore();
vi.mocked(workflowsStore).getNodeByName.mockReturnValue(nodes[0]);
return createComponentRenderer(RunData, {
props: {
node: {
name: 'Test Node',
@@ -114,64 +183,7 @@ describe('RunData', () => {
mappingEnabled: true,
distanceFromActive: 0,
},
pinia: createTestingPinia({
initialState: {
[STORES.SETTINGS]: {
settings: merge({}, SETTINGS_STORE_DEFAULT_STATE.settings),
},
[STORES.NDV]: {
output: {
displayMode,
},
activeNodeName: 'Test Node',
},
[STORES.WORKFLOWS]: {
workflow: {
nodes: [
{
id: '1',
typeVersion: 1,
name: 'Test Node',
position: [0, 0],
type: 'test',
parameters: {},
},
],
},
workflowExecutionData: {
id: '1',
finished: true,
mode: 'trigger',
startedAt: new Date(),
workflowData: {
id: '1',
name: 'Test Workflow',
versionId: '1',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
active: false,
nodes: [],
connections: {},
},
data: {
resultData: {
runData: {
'Test Node': [
{
startTime: new Date().getTime(),
executionTime: new Date().getTime(),
data: {
main: [outputData],
},
source: [null],
},
],
},
},
},
},
},
},
}),
pinia,
});
};
});