Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds jest unit tests #77

Merged
merged 12 commits into from
Apr 30, 2020
Merged
1 change: 1 addition & 0 deletions front-end/__mocks__/css/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
18 changes: 18 additions & 0 deletions front-end/__tests__/components/CustomNode/GraphView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { render } from '@testing-library/react'
import CustomNodeModel from '../../../src/components/CustomNode/CustomNodeModel';
import GraphView from '../../../src/components/CustomNode/GraphView';

describe('Validate Graph Modal', () => {
it('Display warning message', () => {
const node = new CustomNodeModel({id: "myId"});
const graphView = render(
<GraphView node={node}
show={true}
toggleShow={() => {}}
onDelete={() => {}}
onSubmit={() => {}} />
);
expect(graphView).toMatchSnapshot();
});
});
19 changes: 19 additions & 0 deletions front-end/__tests__/components/CustomNode/NodeConfig.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { render } from '@testing-library/react'
import CustomNodeModel from '../../../src/components/CustomNode/CustomNodeModel';
import NodeConfig from '../../../src/components/CustomNode/NodeConfig';


describe('Validate NodeConfig Modal', () => {
it('Display configuration', () => {
const node = new CustomNodeModel({id: "myId"});
const nodeConfig = render(
<NodeConfig node={node}
show={true}
toggleShow={() => {}}
onDelete={() => {}}
onSubmit={() => {}} />
);
expect(nodeConfig).toMatchSnapshot();
});
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Validate Graph Modal Display warning message 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body
class="modal-open"
style="padding-right: 0px;"
>
<div
aria-hidden="true"
/>
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
role="document"
>
<div
class="modal-content"
>
<div
class="modal-header"
>
<div
class="modal-title h4"
>
<b />
View
</div>
</div>
<div
class="modal-body"
>
Loading the data might take a while depending on how big the data is.
</div>
<div
class="modal-footer"
>
<button
class="btn btn-secondary"
type="button"
>
Cancel
</button>
<button
class="btn btn-secondary"
type="button"
>
Load
</button>
</div>
</div>
</div>
</div>
</body>,
"container": <div
aria-hidden="true"
/>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Validate NodeConfig Modal Display configuration 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body
class="modal-open"
style="padding-right: 0px;"
>
<div
aria-hidden="true"
/>
<div
class="fade modal-backdrop show"
/>
<div
aria-modal="true"
class="fade modal show"
role="dialog"
style="display: block;"
tabindex="-1"
>
<div
class="modal-dialog modal-dialog-centered"
role="document"
>
<div
class="modal-content"
>
<form
class=""
>
<div
class="modal-header"
>
<div
class="modal-title h4"
>
<b />
Configuration
</div>
</div>
<div
class="modal-body"
>
<div
class="form-group"
>
<label
class="form-label"
>
Node Description
</label>
<textarea
class="form-control"
name="description"
rows="2"
/>
</div>
</div>
<div
class="modal-footer"
>
<button
class="btn btn-success"
type="submit"
>
Save
</button>
<button
class="btn btn-secondary"
type="button"
>
Cancel
</button>
<button
class="btn btn-danger"
type="button"
>
Delete
</button>
</div>
</form>
</div>
</div>
</div>
</body>,
"container": <div
aria-hidden="true"
/>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
17 changes: 17 additions & 0 deletions front-end/__tests__/components/VPLink/VPLinkModel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import VPLinkModel from '../../../src/components/VPLink/VPLinkModel';
import * as API from '../../../src/API';
jest.mock('../../../src/API');

describe('VPLinkModel behaves as expected', () => {
it('Determine if default is last position', () => {
const linkModel = new VPLinkModel();
expect(linkModel.isLastPositionDefault()).toBe(true);
});
it('remove calls deleteEdge API', () => {
API.deleteEdge.mockResolvedValue(new Promise((resolve, reject) => {}));
const linkModel = new VPLinkModel();
linkModel.remove();
expect(API.deleteEdge.mock.calls.length).toBe(1);
});
});
12 changes: 12 additions & 0 deletions front-end/__tests__/components/VPPort/VPPortFactory.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import VPPortFactory from '../../../src/components/VPPort/VPPortFactory';
import VPPortModel from '../../../src/components/VPPort/VPPortModel';


describe('Generates correct port', () => {
it('VPPortModel is generated', () => {
const portFactory = new VPPortFactory();
const portModel = portFactory.generateModel();
expect(portModel instanceof VPPortModel).toBe(true);
})
});
30 changes: 30 additions & 0 deletions front-end/__tests__/components/VPPort/VPPortModel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { DefaultPortModel } from '@projectstorm/react-diagrams';
import VPPortModel from '../../../src/components/VPPort/VPPortModel'
import VPLinkModel from '../../../src/components/VPLink/VPLinkModel';


describe('VPPortModel only links to different VPPortModels', () => {
it('null is not VPPortModel', () => {
const portModel = new VPPortModel({name: 'vp-port-name'});
expect(portModel.canLinkToPort(null)).toBe(false);
});

it('DefaultPortModel is not VPPortModel', () => {
const portModel = new VPPortModel({name: 'vp-port-name'});
const otherPortModel = new DefaultPortModel({name: 'default-port-name'});
expect(portModel.canLinkToPort(otherPortModel)).toBe(false);
});
it('Cannot link to itself', () => {
const portModel = new VPPortModel({name: 'vp-port-name'});
expect(portModel.canLinkToPort(portModel)).toBe(false);
});
});

describe('Validate VPLinkModel generated', () => {
it('VPPortModel generates VPLinkModel', () => {
const portModel = new VPPortModel({name: 'vp-port-name'});
const linkModel = portModel.createLinkModel();
expect(linkModel instanceof VPLinkModel).toBe(true);
});
});
Loading