Files
vue-flow/e2e/cypress/integration/1-store/setState.spec.ts
T
Braks ee38f4af9b fix(edges): Remove orphaned edges
# What's changed?

* Remove source/targetNode properties from GraphEdge type, the source/target will be fetched with getters if necessary
* Remove edges when they have no existing source or target nodes that can be found in the state
* Add nodes to custom edge test
2022-04-21 10:47:53 +02:00

71 lines
1.6 KiB
TypeScript

import { useVueFlow, State, Store } from '@braks/vue-flow'
describe('test store state', () => {
let store: Store
const { store: initial } = useVueFlow()
beforeEach(() => ({ store } = useVueFlow()))
it('has any initial state', () => expect(store).to.exist)
it('has default initial state', () => {
Object.keys(store).forEach((state) => {
const storedState = store[<keyof State>state]
const initialVal = initial[<keyof State>state]
if (state === 'initialized') return expect(storedState).to.be.true
expect(JSON.stringify(storedState)).to.eq(JSON.stringify(initialVal))
})
})
it('sets state', () => {
store.setState({
zoomOnScroll: false,
})
expect(store.zoomOnScroll).to.eq(false)
})
it('takes initial options', () => {
const { store } = useVueFlow({
zoomOnScroll: false,
})
expect(store.zoomOnScroll).to.eq(false)
})
it('gets custom node types', () => {
store.setState({
nodes: [
{
id: '1',
position: { x: 0, y: 0 },
type: 'custom',
},
],
})
expect(Object.keys(store.getNodeTypes)).to.contain('custom')
})
it('gets custom edge types', () => {
store.setState({
nodes: [
{
id: '1',
position: { x: 0, y: 0 },
},
{
id: '2',
position: { x: 50, y: 50 },
},
],
edges: [
{
id: '1',
source: '1',
target: '2',
type: 'custom',
},
],
})
expect(Object.keys(store.getEdgeTypes)).to.contain('custom')
})
})