import { createWorkflowStoreSnapshot } from '../mocks/store.mock' import { create, createRelId } from '.' describe('connect two actions', () => { it('should remove connected actions', () => { const api = create() const snapshot = createWorkflowStoreSnapshot() const relAId = createRelId() const relBId = createRelId() api.attach(relAId, snapshot.actions[0]) api.attach(relBId, snapshot.actions[1]) api.connect(relAId, relBId) api.remove(relBId) const state = api.getState() expect(state.actions.length).toEqual(1) expect(state.relations.length).toEqual(1) }) it('should remove disconnected actions and creanup views and consume', () => { const api = create() const snapshot = createWorkflowStoreSnapshot() const relAId = createRelId() const relBId = createRelId() const relCId = createRelId() api.attach(relAId, snapshot.actions[0]) api.attach(relBId, snapshot.actions[1]) api.attach(relCId, snapshot.actions[2]) api.connect(relAId, relBId) api.autoAssignLeftAttributes(relBId) api.connect(relBId, relCId) api.autoAssignLeftAttributes(relCId) const zeroState = api.getState() const rel2ProduceGlobalAttrs = Object.keys(zeroState.pipeline[1].produce) const rel3ProduceGlobalAttrs = Object.keys(zeroState.pipeline[2].produce) const elements2 = Object.fromEntries( rel2ProduceGlobalAttrs.map(key => [key, 'CardDescription']) ) const elements3 = Object.fromEntries( rel3ProduceGlobalAttrs.map(key => [key, 'CardDescription']) ) api.addView({ id: createRelId(), label: 'TestView', elements: { ...elements2, ...elements3 }, layout: '', position: 0, }) api.disconnect(relBId) api.remove(relBId) const state = api.getState() expect(state.actions.length).toEqual(2) expect(state.relations.length).toEqual(2) expect(state.pipeline[state.pipeline.length - 1].consume).toEqual({ '__var-a-text:text': '$empty__empty:null', '__var-b-url:url': '$empty__empty:null', }) expect(Object.keys(state.views[0].elements)).toEqual(rel3ProduceGlobalAttrs) }) })