|
| 1 | +import { useVueFlow } from '@braks/vue-flow' |
| 2 | + |
| 3 | +describe('Check if edges are updatable', () => { |
| 4 | + const store = useVueFlow({ id: 'test' }) |
| 5 | + store.onEdgeUpdate((params) => store.updateEdge(params.edge, params.connection)) |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + cy.vueFlow({ |
| 9 | + fitViewOnInit: false, |
| 10 | + edgesUpdatable: true, |
| 11 | + modelValue: [ |
| 12 | + { |
| 13 | + id: '1', |
| 14 | + label: 'Node 1', |
| 15 | + position: { x: 0, y: 0 }, |
| 16 | + }, |
| 17 | + { |
| 18 | + id: '2', |
| 19 | + label: 'Node 2', |
| 20 | + position: { x: 300, y: 300 }, |
| 21 | + }, |
| 22 | + { |
| 23 | + id: '3', |
| 24 | + label: 'Node 3', |
| 25 | + position: { x: 300, y: 0 }, |
| 26 | + }, |
| 27 | + { |
| 28 | + id: 'e1-2', |
| 29 | + source: '1', |
| 30 | + target: '2', |
| 31 | + }, |
| 32 | + ], |
| 33 | + autoConnect: true, |
| 34 | + }) |
| 35 | + }) |
| 36 | + |
| 37 | + it('updates edge', () => { |
| 38 | + cy.window().then((win) => { |
| 39 | + const edgeAnchor = cy.get('.vue-flow__edgeupdater[data-type="target"]') |
| 40 | + const targetTargetHandle = cy.get(`[data-nodeid="3"].target`) |
| 41 | + |
| 42 | + targetTargetHandle.then((handle) => { |
| 43 | + const target = handle[0] |
| 44 | + const { x, y } = target.getBoundingClientRect() |
| 45 | + |
| 46 | + edgeAnchor |
| 47 | + .trigger('mousedown', { |
| 48 | + which: 1, |
| 49 | + force: true, |
| 50 | + view: win, |
| 51 | + }) |
| 52 | + .trigger('mousemove', { |
| 53 | + clientX: x + 5, |
| 54 | + clientY: y + 5, |
| 55 | + force: true, |
| 56 | + }) |
| 57 | + .trigger('mouseup', { |
| 58 | + clientX: x + 5, |
| 59 | + clientY: y + 5, |
| 60 | + force: true, |
| 61 | + view: win, |
| 62 | + }) |
| 63 | + |
| 64 | + cy.wait(100).then(() => { |
| 65 | + const storedEdges = store.edges.value |
| 66 | + expect(storedEdges).to.have.length(1) |
| 67 | + expect(storedEdges[0].target).to.equal('3') |
| 68 | + expect(storedEdges[0].source).to.equal('1') |
| 69 | + }) |
| 70 | + }) |
| 71 | + }) |
| 72 | + }) |
| 73 | +}) |
0 commit comments