Skip to content

Commit

Permalink
chore(tests): add test for selections and empty graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 23, 2019
1 parent 1879ba1 commit 75d8eba
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const BasicGraph = () => (
- `onConnect`: connect handler
- `onLoad`: editor load handler
- `onMove`: move handler
- `nodeTypes`: object with [node types](#node-types)
- `edgeTypes`: object with [edge types](#edge-types)
- `nodeTypes`: object with [node types](#node-types--custom-nodes)
- `edgeTypes`: object with [edge types](#edge-types--custom-edges)
- `style`: css style passed to the wrapper
- `connectionLineType`: connection line type = `straight` or `bezier`
- `connectionLineStyle`: connection style as svg attributes
Expand All @@ -55,21 +55,21 @@ const BasicGraph = () => (

## Nodes

There are three different [node types](#node-types) (`default`, `input`, `output`) you can use. You can also create [custom nodes](#custom-nodes).
There are three different [node types](#node-types--custom-nodes) (`default`, `input`, `output`) you can use. You can also create [custom nodes](#node-types--custom-nodes).

Node example: `{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } }`

**Node Props**

- `id`: string *(required)*
- `position`: { x: number, y: number } *(required)*
- `data`: {} (required if you are using a standard type, otherwise depends on your implementation)
- `data`: {} *(required if you are using a standard type, otherwise depends on your implementation)*
- `type`: 'input' | 'output' | 'default' or a custom one you implemented
- `style`: css properties

## Edges

There are three [edge types](#edge-types) (`straight`, `default`, `step`) you can use. The default type is `default`. You can also create [custom edges](#custom-edges).
There are three [edge types](#edge-types--custom-edges) (`straight`, `default`, `step`) you can use. The default type is `default`. You can also create [custom edges](#edge-types--custom-edges).

Edge example: `{ id: 'e1-2', type: 'straight', source: '1', target: '2', animated: true }`

Expand Down Expand Up @@ -107,7 +107,7 @@ You can now use type `special` for a node.
The `default`, `input` and `output` types will be still available except you overwrite one of them.
You can find an example of how to implement a custom node in [custom nodes example](example/src/CustomNodes).

# Edge Types / Custom Edges
## Edge Types / Custom Edges

The standard edge types are `straight`, `default` and `step`. The default edge types object looks like this:

Expand Down
20 changes: 18 additions & 2 deletions cypress/integration/flow/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Basic Graph Rendering', () => {
expect(gridStroke).to.equal('#eee');
});

it('selects a node', () => {
it('selects a node by click', () => {
cy.get('.react-flow__node:first').click().should('have.class', 'selected');
});

Expand All @@ -24,7 +24,7 @@ describe('Basic Graph Rendering', () => {
cy.get('.react-flow__node:first').should('not.have.class', 'selected');
});

it('selects an edge', () => {
it('selects an edge by click', () => {
cy.get('.react-flow__edge:first').click().should('have.class', 'selected');
});

Expand All @@ -33,6 +33,22 @@ describe('Basic Graph Rendering', () => {
cy.get('.react-flow__edge:first').should('not.have.class', 'selected');
});

it('selects one node with a selection', () => {
cy.get('body')
.type('{shift}', { release: false })
.get('.react-flow__selectionpane')
.trigger('mousedown', 'topLeft', { which: 1, force: true })
.trigger('mousemove', 800, 75, { which: 1 })
.trigger('mouseup', 'bottomRight', { force: true })
.get('.react-flow__node')
.first()
.should('have.class', 'selected')
.get('.react-flow__node')
.last()
.should('have.not.class', 'selected')
.get('.react-flow__nodesselection-rect');
});

it('selects all nodes', () => {
cy.get('body')
.type('{shift}', { release: false })
Expand Down
49 changes: 48 additions & 1 deletion cypress/integration/flow/empty.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,58 @@ describe('Empty Flow Rendering', () => {
cy.get('.react-flow__edge').should('not.exist');
});

it('renders empty selection', () => {
cy.get('body')
.type('{shift}', { release: false })
.get('.react-flow__selectionpane')
.trigger('mousedown', 'topLeft', { which: 1, force: true })
.trigger('mousemove', 'bottomRight', { which: 1 })
.trigger('mouseup', 'bottomRight', { force: true })
});

it('renders a control panel', () => {
cy.get('.react-flow__controls');
});

it('renders a mini map', () => {
it('uses zoom in control', () => {
cy.get('.react-flow__controls-zoomin').click();
});

it('uses zoom out control', () => {
cy.get('.react-flow__controls-zoomout').click();
});

it('uses fit view control', () => {
cy.get('.react-flow__controls-fitview').click();
});

it('renders an empty mini map', () => {
cy.get('.react-flow__minimap');
cy.get('.react-flow__minimap-node').should('not.exist');
});

it('adds two nodes', () => {
cy.contains('add node').click();
cy.contains('add node').click();
});

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

cy.get('.react-flow__node')
.last()
.find('.react-flow__handle.target')
.trigger('mousemove')
.trigger('mouseup', { force: true });

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

it('renders mini map with two nodes', () => {
cy.get('.react-flow__minimap');
cy.get('.react-flow__minimap-node').should('have.length', 2);
});
});

0 comments on commit 75d8eba

Please sign in to comment.