From ce1d97ad6539f7752072f27e05a683d5d2663d53 Mon Sep 17 00:00:00 2001 From: moklick Date: Wed, 31 Aug 2022 15:08:02 +0200 Subject: [PATCH] test(useNodesINitialized): add test --- .../hooks/useNodesInitialized.cy.tsx | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/nextjs/cypress/components/hooks/useNodesInitialized.cy.tsx diff --git a/examples/nextjs/cypress/components/hooks/useNodesInitialized.cy.tsx b/examples/nextjs/cypress/components/hooks/useNodesInitialized.cy.tsx new file mode 100644 index 00000000..0d7be072 --- /dev/null +++ b/examples/nextjs/cypress/components/hooks/useNodesInitialized.cy.tsx @@ -0,0 +1,68 @@ +import ReactFlow, { useNodesInitialized } from 'reactflow'; + +import { nodes } from '../../fixtures/simpleflow'; +import ControlledFlow from '../../support/ControlledFlow'; + +describe('useNodesInitialized.cy.tsx', () => { + it('returns false for no nodes', () => { + const initSpy = cy.spy().as('initSpy'); + + cy.mount( + + + + ); + + cy.get('@initSpy').should('to.be.calledOnce'); + cy.get('@initSpy').should('have.been.calledWith', false); + }); + + it('returns false without onNodesChange', () => { + const initSpy = cy.spy().as('initSpy'); + + cy.mount( + + + + ); + + cy.get('@initSpy').should('to.be.calledOnce'); + cy.get('@initSpy').should('have.be.calledWith', false); + }); + + it('returns true for defaultNodes', () => { + const initSpy = cy.spy().as('initSpy'); + + cy.mount( + + + + ); + + cy.get('@initSpy').should('have.been.calledWith', false); + cy.get('@initSpy').should('have.been.calledWith', true); + }); + + it('returns true for nodes + onNodesChange', () => { + const initSpy = cy.spy().as('initSpy'); + + cy.mount( + + + + ); + + cy.get('@initSpy').should('have.been.calledWith', false); + cy.get('@initSpy').should('have.been.calledWith', true); + }); +}); + +// test specific helpers + +function HookHelperComponent({ onChange }: { onChange: (init: boolean) => void }) { + const initialized = useNodesInitialized(); + + onChange(initialized); + + return null; +}