Skip to content

Commit

Permalink
feat(tests): add invalid connection test
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 7, 2019
1 parent 492ab71 commit 2a20a8b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
48 changes: 48 additions & 0 deletions cypress/integration/flow/advanced.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe('Advanced Flow Rendering', () => {
it('renders a flow with sone nodes', () => {
cy.visit('/advanced.html');

cy.get('.react-flow__renderer');

cy.get('.react-flow__node').should('have.length', 9);
cy.get('.react-flow__edge').should('have.length', 9);
});

it('connects nodes', () => {
cy.get('.react-flow__node')
.contains('1 Tests')
.find('.react-flow__handle.source')
.trigger('mousedown', { which: 1 });

cy.get('.react-flow__node')
.contains('7 output')
.find('.react-flow__handle.target')
.trigger('mousemove')
.should('have.class', 'connecting')
.should('have.class', 'valid')
.trigger('mouseup', { force: true })
.should('not.have.class', 'valid')
.should('not.have.class', 'connecting');

cy.get('.react-flow__edge').should('have.length', 10);
});

it('tries to make invalid connection', () => {
cy.get('.react-flow__node')
.contains('write something')
.parents('.react-flow__node')
.find('.react-flow__handle.source')
.trigger('mousedown', { which: 1 });

cy.get('.react-flow__node')
.contains('5 Another node')
.find('.react-flow__handle.target')
.trigger('mousemove')
.should('have.class', 'connecting')
.should('not.have.class', 'valid')
.trigger('mouseup', { force: true })
.should('not.have.class', 'connecting');

cy.get('.react-flow__edge').should('have.length', 10);
});
});
File renamed without changes.
24 changes: 12 additions & 12 deletions dist/ReactGraph.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom', 'prop-types'], factory) :
(global = global || self, factory(global.ReactGraph = {}, global.React, global.ReactDOM, global.PropTypes));
(global = global || self, factory(global.ReactFlow = {}, global.React, global.ReactDOM, global.PropTypes));
}(this, function (exports, React, reactDom, PropTypes) { 'use strict';

var React__default = 'default' in React ? React['default'] : React;
Expand Down Expand Up @@ -9207,7 +9207,15 @@
x: evt.clientX - containerBounds.x,
y: evt.clientY - containerBounds.y
});
setSourceId(nodeId); // checks if element below mouse is a handle and returns connection in form of an object { source: 123, target: 312 }
setSourceId(nodeId);

function resetRecentHandle() {
if (recentHoveredHandle) {
recentHoveredHandle.classList.remove('valid');
recentHoveredHandle.classList.remove('connecting');
}
} // checks if element below mouse is a handle and returns connection in form of an object { source: 123, target: 312 }


function checkElementBelowIsValid(evt) {
var elementBelow = document.elementFromPoint(evt.clientX, evt.clientY);
Expand Down Expand Up @@ -9257,12 +9265,7 @@
isHoveringHandle = _checkElementBelowIsV.isHoveringHandle;

if (!isHoveringHandle) {
if (recentHoveredHandle) {
recentHoveredHandle.classList.remove('valid');
recentHoveredHandle.classList.remove('connecting');
}

return false;
return resetRecentHandle();
}

var isOwnHandle = connection.source === connection.target;
Expand All @@ -9283,10 +9286,7 @@
onConnect(connection);
}

if (recentHoveredHandle) {
recentHoveredHandle.classList.remove('valid');
}

resetRecentHandle();
setSourceId(null);
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default [{
}
},
output: {
name: 'ReactGraph',
name: 'ReactFlow',
file: pkg.browser,
format: 'umd',
sourcemaps: true,
Expand Down

0 comments on commit 2a20a8b

Please sign in to comment.