-
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #641 from retejs/tests
add tests
- Loading branch information
Showing
1 changed file
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
// import jest globals | ||
import { describe, expect, test } from '@jest/globals' | ||
import { describe, expect, it } from '@jest/globals' | ||
|
||
import { NodeEditor } from '../src/editor' | ||
|
||
describe('NodeEditor', () => { | ||
test('NodeEditor is instantiable', () => { | ||
it('NodeEditor is instantiable', () => { | ||
expect(new NodeEditor()).toBeInstanceOf(NodeEditor) | ||
}) | ||
|
||
it('addNode should add a node', async () => { | ||
const editor = new NodeEditor() | ||
const nodeData = { id: '1', label: 'Node 1' } | ||
const result = await editor.addNode(nodeData) | ||
const nodes = editor.getNodes() | ||
|
||
expect(result).toBe(true) | ||
expect(nodes).toHaveLength(1) | ||
expect(nodes[0]).toEqual(nodeData) | ||
}) | ||
|
||
it('addNode should not add a node with duplicate id', async () => { | ||
const editor = new NodeEditor() | ||
const nodeData = { id: '1', label: 'Node 1' } | ||
|
||
await editor.addNode(nodeData) | ||
|
||
await expect(() => editor.addNode(nodeData)).rejects.toThrowError() | ||
}) | ||
|
||
it('addConnection should add a connection', async () => { | ||
const editor = new NodeEditor() | ||
const connectionData = { id: '1', source: '1', target: '2' } | ||
|
||
await editor.addNode({ id: '1' }) | ||
await editor.addNode({ id: '2' }) | ||
const result = await editor.addConnection(connectionData) | ||
const connections = editor.getConnections() | ||
|
||
expect(result).toBe(true) | ||
expect(connections).toHaveLength(1) | ||
expect(connections[0]).toEqual(connectionData) | ||
}) | ||
|
||
it('addConnection should not add a connection with duplicate id', async () => { | ||
const editor = new NodeEditor() | ||
const connectionData = { id: '1', source: '1', target: '2' } | ||
|
||
await editor.addNode({ id: '1' }) | ||
await editor.addNode({ id: '2' }) | ||
await editor.addConnection(connectionData) | ||
|
||
await expect(() => editor.addConnection(connectionData)).rejects.toThrowError() | ||
}) | ||
}) | ||
|