From 44f8eb1fe766df1ceb1d511fb9f7e22da1e650ca Mon Sep 17 00:00:00 2001 From: Braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:18:23 +0100 Subject: [PATCH] fix(test): correct usage of store in testing Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com> --- .../integration/1-store/setElements.spec.ts | 32 ++++++++++--------- cypress/integration/1-store/setState.spec.ts | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cypress/integration/1-store/setElements.spec.ts b/cypress/integration/1-store/setElements.spec.ts index 046984a4..de6440d4 100644 --- a/cypress/integration/1-store/setElements.spec.ts +++ b/cypress/integration/1-store/setElements.spec.ts @@ -1,16 +1,19 @@ import { getElements } from '../../../examples/Stress/utils' import { useStore } from '~/composables' -import { Elements, FlowStore } from '~/types' -import { isGraphEdge, isGraphNode } from '~/utils' +import { Edge, FlowStore, Node } from '~/types' +import { isEdge, isNode } from '~/utils' describe('test store action setElements', () => { const setElements = async (store: FlowStore) => { - const elements: Elements = [ + const nodes: Node[] = [ { id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } }, { id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } }, - { id: 'e1-2', source: '1', target: '2', animated: true }, ] - await store.setElements(elements) + const edges: Edge[] = [{ id: 'e1-2', source: '1', target: '2', animated: true }] + store.setState({ + nodes, + edges, + }) } it('sets elements', async () => { @@ -26,20 +29,19 @@ describe('test store action setElements', () => { await setElements(store) }) - it('adds elements', () => { - store.addElements([{ id: '4', data: { label: 'Node 4' }, position: { x: 500, y: 500 } }]) - expect(store.elements).to.have.length(4) - }) - it('parses elements to flow-elements', () => { - store.getEdges.forEach((edge) => expect(!isGraphNode(edge)).to.be.true) - store.getNodes.forEach((node) => expect(!isGraphEdge(node)).to.be.true) + store.getEdges.forEach((edge) => expect(!isEdge(edge)).to.be.true) + store.getNodes.forEach((node) => expect(!isNode(node)).to.be.true) }) it('parses elements to flow-elements (199 elements - stress test)', async () => { - await store.setElements(getElements()) - store.getEdges.forEach((edge) => expect(!isGraphNode(edge)).to.be.true) - store.getNodes.forEach((node) => expect(!isGraphEdge(node)).to.be.true) + const { nodes, edges } = getElements() + store.setState({ + nodes, + edges, + }) + store.getEdges.forEach((edge) => expect(!isEdge(edge)).to.be.true) + store.getNodes.forEach((node) => expect(!isNode(node)).to.be.true) }) it('has correct element ids', () => { diff --git a/cypress/integration/1-store/setState.spec.ts b/cypress/integration/1-store/setState.spec.ts index e1371c44..47480c73 100644 --- a/cypress/integration/1-store/setState.spec.ts +++ b/cypress/integration/1-store/setState.spec.ts @@ -1,6 +1,6 @@ import { useStore } from '~/composables' -import { initialState } from '~/utils' import { FlowState, FlowStore } from '~/types' +import { initialState } from '~/store' describe('test store state', () => { let store: FlowStore