fix(test): correct usage of store in testing

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-12 00:18:23 +01:00
parent a7bacb754a
commit 44f8eb1fe7
2 changed files with 18 additions and 16 deletions

View File

@@ -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', () => {

View File

@@ -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