diff --git a/cypress.config.js b/examples/nextjs/cypress.config.js
similarity index 67%
rename from cypress.config.js
rename to examples/nextjs/cypress.config.js
index 842b7fff..7e24d96b 100644
--- a/cypress.config.js
+++ b/examples/nextjs/cypress.config.js
@@ -7,4 +7,11 @@ module.exports = defineConfig({
viewportHeight: 720,
video: false,
},
+
+ component: {
+ devServer: {
+ framework: 'next',
+ bundler: 'webpack',
+ },
+ },
});
diff --git a/cypress/e2e/basic.cy.js b/examples/nextjs/cypress/e2e/basic.cy.ts
similarity index 91%
rename from cypress/e2e/basic.cy.js
rename to examples/nextjs/cypress/e2e/basic.cy.ts
index c43ab716..a08ca021 100644
--- a/cypress/e2e/basic.cy.js
+++ b/examples/nextjs/cypress/e2e/basic.cy.ts
@@ -29,9 +29,7 @@ describe('Basic Flow Rendering', () => {
});
it('selects a node by click', () => {
- cy.get('.react-flow__node:first')
- .click({ force: true })
- .should('have.class', 'selected');
+ cy.get('.react-flow__node:first').click({ force: true }).should('have.class', 'selected');
});
it('deselects node', () => {
@@ -40,9 +38,7 @@ describe('Basic Flow Rendering', () => {
});
it('selects an edge by click', () => {
- cy.get('.react-flow__edge:first')
- .click({ force: true })
- .should('have.class', 'selected');
+ cy.get('.react-flow__edge:first').click({ force: true }).should('have.class', 'selected');
});
it('deselects edge', () => {
@@ -93,17 +89,13 @@ describe('Basic Flow Rendering', () => {
});
it('selects an edge', () => {
- cy.get('.react-flow__edge:first')
- .click({ force: true })
- .should('have.class', 'selected');
+ cy.get('.react-flow__edge:first').click({ force: true }).should('have.class', 'selected');
});
it('drags a node', () => {
- const styleBeforeDrag = Cypress.$('.react-flow__node:first').css(
- 'transform'
- );
+ const styleBeforeDrag = Cypress.$('.react-flow__node:first').css('transform');
- cy.drag('.react-flow__node:first', { x: 500, y: 25 }).then(($el) => {
+ cy.drag('.react-flow__node:first', { x: 500, y: 25 }).then(($el: any) => {
const styleAfterDrag = $el.css('transform');
expect(styleBeforeDrag).to.not.equal(styleAfterDrag);
});
@@ -153,9 +145,7 @@ describe('Basic Flow Rendering', () => {
.wait(50)
.trigger('mouseup', { force: true, view: win })
.then(() => {
- const styleAfterDrag = Cypress.$('.react-flow__viewport').css(
- 'transform'
- );
+ const styleAfterDrag = Cypress.$('.react-flow__viewport').css('transform');
expect(styleBeforeDrag).to.not.equal(styleAfterDrag);
});
});
@@ -168,10 +158,10 @@ describe('Basic Flow Rendering', () => {
.trigger('wheel', 'topLeft', { deltaY: -200 })
.wait(50)
.then(() => {
- const styleAfterZoom = Cypress.$('.react-flow__viewport').css(
- 'transform'
- );
+ const styleAfterZoom = Cypress.$('.react-flow__viewport').css('transform');
expect(styleBeforeZoom).to.not.equal(styleAfterZoom);
});
});
});
+
+export {};
diff --git a/cypress/e2e/controls.cy.js b/examples/nextjs/cypress/e2e/controls.cy.ts
similarity index 99%
rename from cypress/e2e/controls.cy.js
rename to examples/nextjs/cypress/e2e/controls.cy.ts
index f38df829..74548f56 100644
--- a/cypress/e2e/controls.cy.js
+++ b/examples/nextjs/cypress/e2e/controls.cy.ts
@@ -79,3 +79,5 @@ describe('Controls Testing', () => {
});
});
});
+
+export {};
diff --git a/cypress/e2e/draghandle.cy.js b/examples/nextjs/cypress/e2e/draghandle.cy.ts
similarity index 98%
rename from cypress/e2e/draghandle.cy.js
rename to examples/nextjs/cypress/e2e/draghandle.cy.ts
index 498d84d2..259fbf8a 100644
--- a/cypress/e2e/draghandle.cy.js
+++ b/examples/nextjs/cypress/e2e/draghandle.cy.ts
@@ -28,3 +28,5 @@ describe('DragHandle Flow Rendering', () => {
});
});
});
+
+export {};
diff --git a/cypress/e2e/empty.cy.js b/examples/nextjs/cypress/e2e/empty.cy.ts
similarity index 69%
rename from cypress/e2e/empty.cy.js
rename to examples/nextjs/cypress/e2e/empty.cy.ts
index ce31424f..5f25dcaf 100644
--- a/cypress/e2e/empty.cy.js
+++ b/examples/nextjs/cypress/e2e/empty.cy.ts
@@ -10,12 +10,15 @@ describe('Empty Flow Rendering', () => {
});
it('renders empty selection', () => {
+ cy.get('.react-flow__renderer').click();
cy.get('body')
.type('{shift}', { release: false })
+ .wait(50)
.get('.react-flow__selectionpane')
- .trigger('mousedown', 'topLeft', { which: 1, force: true })
- .trigger('mousemove', 'bottomLeft', { which: 1 })
- .trigger('mouseup', 'bottomLeft', { force: true });
+ .trigger('mousedown', 400, 50, { which: 1, force: true })
+ .trigger('mousemove', 200, 200, { which: 1 })
+ .wait(50)
+ .trigger('mouseup', 200, 200, { force: true });
cy.get('body').type('{shift}', { release: true });
});
@@ -26,10 +29,7 @@ describe('Empty Flow Rendering', () => {
});
it('connects nodes', () => {
- cy.get('.react-flow__node')
- .first()
- .find('.react-flow__handle.source')
- .trigger('mousedown', { button: 0 });
+ cy.get('.react-flow__node').first().find('.react-flow__handle.source').trigger('mousedown', { button: 0 });
cy.get('.react-flow__node')
.last()
@@ -40,3 +40,5 @@ describe('Empty Flow Rendering', () => {
cy.get('.react-flow__edge').should('have.length', 1);
});
});
+
+export {};
diff --git a/cypress/e2e/graph-utils.cy.js b/examples/nextjs/cypress/e2e/graph-utils.cy.ts
similarity index 77%
rename from cypress/e2e/graph-utils.cy.js
rename to examples/nextjs/cypress/e2e/graph-utils.cy.ts
index 18d9cb2c..6ebded1b 100644
--- a/cypress/e2e/graph-utils.cy.js
+++ b/examples/nextjs/cypress/e2e/graph-utils.cy.ts
@@ -1,12 +1,6 @@
-import {
- isNode,
- isEdge,
- getOutgoers,
- getIncomers,
- addEdge,
-} from '../../packages/core/dist/react-flow-core.esm.js';
+import { Node, Edge, isNode, isEdge, getOutgoers, getIncomers, addEdge } from '@react-flow/bundle';
-const nodes = [
+const nodes: Node[] = [
{
id: '1',
type: 'input',
@@ -18,7 +12,7 @@ const nodes = [
{ id: '4', data: { label: 'Node 4' }, position: { x: 400, y: 200 } },
];
-const edges = [
+const edges: Edge[] = [
{ id: 'e1-2', source: '1', target: '2', animated: true },
{ id: 'e1-3', source: '1', target: '3' },
{ id: 'e2-3', source: '2', target: '3' },
@@ -54,31 +48,32 @@ describe('Graph Utils Testing', () => {
describe('tests addEdge function', () => {
it('adds edge', () => {
- const newEdge = { source: '1', target: '4' };
+ const newEdge: Edge = { source: '1', target: '4', id: 'new-edge-1-4' };
const nextEdges = addEdge(newEdge, edges);
expect(nextEdges.length).to.be.equal(edges.length + 1);
});
it('tries to add existing edge', () => {
- const newEdge = { source: '2', target: '3' };
+ const newEdge: Edge = { source: '2', target: '3', id: 'new-edge-2-3' };
const nextEdges = addEdge(newEdge, edges);
expect(nextEdges.length).to.be.equal(edges.length);
});
it('tries to add invalid edge', () => {
- const newEdge = { nosource: '1', notarget: '3' };
+ // @ts-ignore
+ const newEdge: Edge = { nosource: '1', notarget: '3' };
try {
addEdge(newEdge, edges);
- } catch (e) {
+ } catch (e: any) {
console.log(e.message);
- expect(e.message).to.be.equal(
- "Can't create edge. An edge needs a source and a target."
- );
+ expect(e.message).to.be.equal("Can't create edge. An edge needs a source and a target.");
}
});
});
});
+
+export {};
diff --git a/cypress/e2e/hidden.cy.js b/examples/nextjs/cypress/e2e/hidden.cy.ts
similarity index 98%
rename from cypress/e2e/hidden.cy.js
rename to examples/nextjs/cypress/e2e/hidden.cy.ts
index 730502f3..2039d742 100644
--- a/cypress/e2e/hidden.cy.js
+++ b/examples/nextjs/cypress/e2e/hidden.cy.ts
@@ -30,3 +30,5 @@ describe('Hidden Flow Rendering', () => {
cy.get('.react-flow__minimap-node').should('not.exist');
});
});
+
+export {};
diff --git a/cypress/e2e/interaction.cy.js b/examples/nextjs/cypress/e2e/interaction.cy.ts
similarity index 92%
rename from cypress/e2e/interaction.cy.js
rename to examples/nextjs/cypress/e2e/interaction.cy.ts
index 368dd0e1..625ecc57 100644
--- a/cypress/e2e/interaction.cy.js
+++ b/examples/nextjs/cypress/e2e/interaction.cy.ts
@@ -11,16 +11,12 @@ describe('Interaction Flow Rendering', () => {
});
it('tries to select a node by click', () => {
- const pointerEvents = Cypress.$('.react-flow__node:first').css(
- 'pointer-events'
- );
+ const pointerEvents = Cypress.$('.react-flow__node:first').css('pointer-events');
expect(pointerEvents).to.equal('none');
});
it('tries to select an edge by click', () => {
- const pointerEvents = Cypress.$('.react-flow__edge:first').css(
- 'pointer-events'
- );
+ const pointerEvents = Cypress.$('.react-flow__edge:first').css('pointer-events');
expect(pointerEvents).to.equal('none');
});
@@ -29,24 +25,17 @@ describe('Interaction Flow Rendering', () => {
});
it('allows node clicks when enabled', () => {
- const pointerEvents = Cypress.$('.react-flow__node:first').css(
- 'pointer-events'
- );
+ const pointerEvents = Cypress.$('.react-flow__node:first').css('pointer-events');
expect(pointerEvents).to.equal('all');
});
it('allows edge clicks when enabled', () => {
- const pointerEvents = Cypress.$('.react-flow__edge:first').css(
- 'pointer-events'
- );
+ const pointerEvents = Cypress.$('.react-flow__edge:first').css('pointer-events');
expect(pointerEvents.toLowerCase()).to.equal('visiblestroke');
});
it('tries to do a selection', () => {
- cy.get('body')
- .type('{shift}', { release: false })
- .get('.react-flow__selectionpane')
- .should('not.exist');
+ cy.get('body').type('{shift}', { release: false }).get('.react-flow__selectionpane').should('not.exist');
cy.get('body').type('{shift}', { release: true });
});
@@ -87,9 +76,7 @@ describe('Interaction Flow Rendering', () => {
});
it('drags a node', () => {
- const styleBeforeDrag = Cypress.$('.react-flow__node:first').css(
- 'transform'
- );
+ const styleBeforeDrag = Cypress.$('.react-flow__node:first').css('transform');
cy.drag('.react-flow__node:first', { x: 325, y: 100 }).then(($el) => {
const styleAfterDrag = $el.css('transform');
@@ -140,9 +127,7 @@ describe('Interaction Flow Rendering', () => {
.trigger('wheel', 'topLeft', { deltaY: 200 })
.wait(50)
.then(() => {
- const styleAfterZoom = Cypress.$('.react-flow__viewport').css(
- 'transform'
- );
+ const styleAfterZoom = Cypress.$('.react-flow__viewport').css('transform');
expect(styleBeforeZoom).not.to.equal(styleAfterZoom);
});
});
@@ -159,10 +144,10 @@ describe('Interaction Flow Rendering', () => {
.dblclick()
.wait(50)
.then(() => {
- const styleAfterZoom = Cypress.$('.react-flow__viewport').css(
- 'transform'
- );
+ const styleAfterZoom = Cypress.$('.react-flow__viewport').css('transform');
expect(styleBeforeZoom).not.to.equal(styleAfterZoom);
});
});
});
+
+export {};
diff --git a/cypress/e2e/minimap.cy.js b/examples/nextjs/cypress/e2e/minimap.cy.ts
similarity index 82%
rename from cypress/e2e/minimap.cy.js
rename to examples/nextjs/cypress/e2e/minimap.cy.ts
index a61c2565..668b8b0f 100644
--- a/cypress/e2e/minimap.cy.js
+++ b/examples/nextjs/cypress/e2e/minimap.cy.ts
@@ -21,19 +21,15 @@ describe('Minimap Testing', () => {
});
it('changes zoom level', () => {
- const viewBoxBeforeZoom = Cypress.$('.react-flow__minimap').attr('viewBox');
+ const viewBoxBeforeZoom = Cypress.$('.react-flow__minimap svg').attr('viewBox');
const maskPathBeforeZoom = Cypress.$('.react-flow__minimap-mask').attr('d');
cy.get('.react-flow__pane')
.trigger('wheel', 'topLeft', { deltaY: -200 })
.wait(50)
.then(() => {
- const viewBoxAfterZoom = Cypress.$('.react-flow__minimap').attr(
- 'viewBox'
- );
- const maskPathAfterZoom = Cypress.$('.react-flow__minimap-mask').attr(
- 'd'
- );
+ const viewBoxAfterZoom = Cypress.$('.react-flow__minimap svg').attr('viewBox');
+ const maskPathAfterZoom = Cypress.$('.react-flow__minimap-mask').attr('d');
expect(viewBoxBeforeZoom).to.not.equal(viewBoxAfterZoom);
expect(maskPathBeforeZoom).to.not.equal(maskPathAfterZoom);
@@ -41,22 +37,14 @@ describe('Minimap Testing', () => {
});
it('changes node position', () => {
- const xPosBeforeDrag = Cypress.$('.react-flow__minimap-node:first').attr(
- 'x'
- );
- const yPosBeforeDrag = Cypress.$('.react-flow__minimap-node:first').attr(
- 'y'
- );
+ const xPosBeforeDrag = Cypress.$('.react-flow__minimap-node:first').attr('x');
+ const yPosBeforeDrag = Cypress.$('.react-flow__minimap-node:first').attr('y');
cy.drag('.react-flow__node:first', { x: 500, y: 25 })
.wait(100)
.then(() => {
- const xPosAfterDrag = Cypress.$('.react-flow__minimap-node:first').attr(
- 'x'
- );
- const yPosAfterDrag = Cypress.$('.react-flow__minimap-node:first').attr(
- 'y'
- );
+ const xPosAfterDrag = Cypress.$('.react-flow__minimap-node:first').attr('x');
+ const yPosAfterDrag = Cypress.$('.react-flow__minimap-node:first').attr('y');
expect(xPosBeforeDrag).to.not.equal(xPosAfterDrag);
expect(yPosBeforeDrag).to.not.equal(yPosAfterDrag);
@@ -64,7 +52,7 @@ describe('Minimap Testing', () => {
});
it('changes node positions via pane drag', () => {
- const viewBoxBeforeDrag = Cypress.$('.react-flow__minimap').attr('viewBox');
+ const viewBoxBeforeDrag = Cypress.$('.react-flow__minimap svg').attr('viewBox');
const maskPathBeforeDrag = Cypress.$('.react-flow__minimap-mask').attr('d');
// for d3 we have to pass the window to the event
@@ -76,12 +64,8 @@ describe('Minimap Testing', () => {
.wait(50)
.trigger('mouseup', { force: true, view: win })
.then(() => {
- const viewBoxAfterDrag = Cypress.$('.react-flow__minimap').attr(
- 'viewBox'
- );
- const maskPathAfterDrag = Cypress.$('.react-flow__minimap-mask').attr(
- 'd'
- );
+ const viewBoxAfterDrag = Cypress.$('.react-flow__minimap svg').attr('viewBox');
+ const maskPathAfterDrag = Cypress.$('.react-flow__minimap-mask').attr('d');
expect(viewBoxBeforeDrag).to.not.equal(viewBoxAfterDrag);
expect(maskPathBeforeDrag).to.not.equal(maskPathAfterDrag);
@@ -89,3 +73,5 @@ describe('Minimap Testing', () => {
});
});
});
+
+export {};
diff --git a/examples/nextjs/cypress/fixtures/example.json b/examples/nextjs/cypress/fixtures/example.json
new file mode 100644
index 00000000..02e42543
--- /dev/null
+++ b/examples/nextjs/cypress/fixtures/example.json
@@ -0,0 +1,5 @@
+{
+ "name": "Using fixtures to represent data",
+ "email": "hello@cypress.io",
+ "body": "Fixtures are a great way to mock data for responses to routes"
+}
diff --git a/cypress/support/commands.js b/examples/nextjs/cypress/support/commands.ts
similarity index 73%
rename from cypress/support/commands.js
rename to examples/nextjs/cypress/support/commands.ts
index 76707060..b1fa542d 100644
--- a/cypress/support/commands.js
+++ b/examples/nextjs/cypress/support/commands.ts
@@ -1,3 +1,5 @@
+///