Skip to content

Increases code coverage of UI #88

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

Draft
wants to merge 52 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
fec2821
Updates snap of ui view
cesaragv May 5, 2020
d327106
Moves jest's configuration to jest.config.js
cesaragv May 5, 2020
ca46439
Removes unnecesary file
cesaragv May 5, 2020
445ff7e
Deletes unused file
cesaragv May 5, 2020
b07d84c
Ignores GraphView.test.js due to failure to run
cesaragv May 5, 2020
4a15edb
Increases code coverage by testing CustomNodeWidget
cesaragv May 5, 2020
11b4cf3
Covers NodeMenu
cesaragv May 5, 2020
f2e2f8f
Adds test for workspace
cesaragv May 5, 2020
92051b3
Adds unit tests for App
cesaragv May 5, 2020
8726073
Ignores untestable scripts
cesaragv May 5, 2020
0a9fdff
Adds snapshot for About
cesaragv May 5, 2020
6eec25e
Adds tests for GlobalFlowMenu
cesaragv May 5, 2020
97be002
Adds more unit tests for NodeConfig
cesaragv May 6, 2020
32b0129
Completes code coverage for CustomNodeModel
cesaragv May 6, 2020
112bf41
Increases code coverage for VPLinkModel
cesaragv May 6, 2020
3240836
Uses jest-mock-canvas to avoid warning messges
cesaragv May 6, 2020
733764e
Fixes CustomNodeFactory
cesaragv May 6, 2020
31a465c
Fixes API response object
cesaragv May 6, 2020
c93a854
Completes API setup
cesaragv May 6, 2020
d6d686c
Hides console log messages
cesaragv May 6, 2020
21d9ed9
Fixes VPLinkModel tests
cesaragv May 6, 2020
1fd22eb
Increases code coverage for VPLinkModel
cesaragv May 6, 2020
1329451
Adds more tests for NodeConfig
cesaragv May 6, 2020
5a45543
Adds more unit tests for NodeConfig.js
cesaragv May 6, 2020
6290f62
Increases code coverage for Workspace
cesaragv May 6, 2020
d3a3fc9
Increases code coverage for CustomNodeFactory
cesaragv May 6, 2020
6344c17
Increases code coverage
cesaragv May 7, 2020
b43a8ed
Uses Spinner instead of Roller
cesaragv May 8, 2020
635d39f
Converts About function to a react class
cesaragv May 8, 2020
a253da3
Converts CustomNodeUpload to React.Component clas
cesaragv May 8, 2020
b934950
Converts About.js and GlobalFlowMenu into React classes
cesaragv May 8, 2020
dd7feca
Merge branch 'master' into increasecoverage
cesaragv May 8, 2020
c337d29
Increases code coverage of GlogalFlowMenu
cesaragv May 8, 2020
9ef3e43
All unit tests pass cleanly
cesaragv May 8, 2020
a2e28ea
Completes code coverage for VPPortModel
cesaragv May 8, 2020
93a4ec4
Increases code coverage of GraphView
cesaragv May 9, 2020
b8d1588
Separates FileUpload from Workspace
cesaragv May 9, 2020
72033a0
Adds unit tests for FileUpload
cesaragv May 9, 2020
f6e9caf
Adds unit tests for Workspace
cesaragv May 9, 2020
6721da4
Increases code coverage for API.js
cesaragv May 9, 2020
ceb494e
Splits NodeConfig into multiple components
cesaragv May 9, 2020
36c1801
Completes separation of components
cesaragv May 9, 2020
46621c1
Cleans up imports
cesaragv May 9, 2020
5e9c76c
Increases code coverage requirement
cesaragv May 9, 2020
6db529c
Completes code coverage for BooleanInput
cesaragv May 9, 2020
f497960
Completes unit tests for BooleanInput and SimpleInput
cesaragv May 9, 2020
7e47951
Completes unit tests for SelectInput
cesaragv May 9, 2020
480f7c9
Completes code coverage for FlowVariableOverride
cesaragv May 9, 2020
1833f14
Completes code coverage for OptionInput
cesaragv May 9, 2020
9cb1c97
Increses code coverage for FileUploadInput
cesaragv May 9, 2020
95dd468
Completes unit tests for FileUploadInput
cesaragv May 9, 2020
1c6ea12
Completes minimum code coverage
cesaragv May 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions front-end/__tests__/components/API.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import React from 'react'
import { render } from '@testing-library/react'
import * as API from '../../src/API';
import VPLinkModel from '../../src/components/VPLink/VPLinkModel';
import CustomNodeModel from '../../src/components/CustomNode/CustomNodeModel';
import VPPortModel from '../../src/components/VPPort/VPPortModel'

global.console = {log: jest.fn()}
global.URL.createObjectURL = jest.fn(() => 'http://localhost:8080/');
global.URL.revokeObjectURL = jest.fn();

describe('Validates API calls', () => {

beforeEach(() => {
global.fetch = jest.fn(() => Promise.resolve({
ok: true,
data: [],
json: jest.fn(() => []),
text: jest.fn(() => Promise.resolve({})),
headers:{
get: (s)=>{
if (s === "content-type") {
return "text";
}

if (s === "Content-Disposition") {
return "filenameToDownload";
}
}
}
}));
});

it('Validates executionOrder', () => {
API.executionOrder();
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][1]).toStrictEqual({});
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/execute");
});

it('Validates execute', () => {
const node = {
options: {
id: 'nodeId'
}
};

API.execute(node);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][1]).toStrictEqual({});
expect(global.fetch.mock.calls[0][0]).toBe("/node/nodeId/execute");
});

it('Validates retrieveData', () => {
API.retrieveData("nodeId");
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][1]).toStrictEqual({});
expect(global.fetch.mock.calls[0][0]).toBe("/node/nodeId/retrieve_data");
});

it('Validates downloadDataFile', () => {
const node = {
options: {
id: 'nodeId'
},
config: {}
};

API.downloadDataFile(node);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/download");
});

it('Validates uploadDataFile', () => {
const formData = { data: {}};
const options = {method: "POST", body: formData};
API.uploadDataFile(formData);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][1]).toStrictEqual(options);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/upload");
});

it('Validates deleteEdge', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
const targetModel = new CustomNodeModel({id: "myId2", num_in: 2, num_out: 1});

const sourcePort = new VPPortModel({name: 'source-port-name'});
sourcePort.setParent(sourceModel);
const targetPort = new VPPortModel({name: 'target-port-name'});
targetPort.setParent(targetModel);
const linkModel = new VPLinkModel();
linkModel.setSourcePort(sourcePort);
linkModel.setTargetPort(targetPort);

const options = {method: "POST"};
API.deleteEdge(linkModel);

expect(global.fetch.mock.calls.length).toBe(2);
expect(global.fetch.mock.calls[0][1]).toStrictEqual(options);
expect(global.fetch.mock.calls[0][0]).toBe("/node/edge/myId1/myId2");

});

it('Validates addEdge', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
const targetModel = new CustomNodeModel({id: "myId2", num_in: 2, num_out: 1});

const sourcePort = new VPPortModel({name: 'source-port-name', in: true});
sourcePort.setParent(sourceModel);
const targetPort = new VPPortModel({name: 'target-port-name'});
targetPort.setParent(targetModel);
const linkModel = new VPLinkModel();
linkModel.setSourcePort(sourcePort);
linkModel.setTargetPort(targetPort);

const options = {method: "POST"};
API.addEdge(linkModel);

expect(global.fetch.mock.calls.length).toBe(2);
expect(global.fetch.mock.calls[0][1]).toStrictEqual(options);
expect(global.fetch.mock.calls[0][0]).toBe("/node/edge/myId2/myId1");

});

it('Validates uploadWorkflow', () => {
const formData = { data: {}};
const options = {method: "POST", body: formData};
API.uploadWorkflow(formData);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][1]).toStrictEqual(options);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/open");
});

it('Validates initWorkflow', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
API.initWorkflow(sourceModel);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/new");
});

it('Validates getGlobalVars', () => {
API.getGlobalVars();
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/globals");
});

it('Validates getNodes', () => {
API.getNodes();
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/workflow/nodes");
});

it('Validates updateNode', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
API.updateNode(sourceModel);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/node/myId1");
});

it('Validates deleteNode', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
API.deleteNode(sourceModel);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/node/myId1");
});

it('Validates addNode', () => {
const sourceModel = new CustomNodeModel({id: "myId1", num_in: 2, num_out: 1});
API.addNode(sourceModel);
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/node/");
});

it('Validates getNode', () => {
API.getNode("myId1");
expect(global.fetch.mock.calls.length).toBe(1);
expect(global.fetch.mock.calls[0][0]).toBe("/node/myId1");
});

});
42 changes: 42 additions & 0 deletions front-end/__tests__/components/About.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { render } from '@testing-library/react'
import ReactDOM from 'react-dom';
import About from '../../src/components/About';

global.console = {error: jest.fn()}

global.fetch = jest.fn(() => Promise.resolve({
data: [],
json: jest.fn(() => [])
}));

describe('Validates About', () => {
it('Does not display About info', () => {
const div = React.createElement('div');
const app = render(<About show={false} />, div);
expect(app).toMatchSnapshot();
});

it('Displays About info', () => {
const div = React.createElement('div');
const app = render(<About show={true} />, div);
expect(app).toMatchSnapshot();
});

it('Validates closing', () => {
const props = {
show: true
};

const event = {
preventDefault: jest.fn(() => [])
};

const about = new About(props);
about.componentDidMount();
about.handleShow(event);
about.handleClose();

expect(event.preventDefault.mock.calls.length).toBe(1);
});
});
17 changes: 17 additions & 0 deletions front-end/__tests__/components/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { render } from '@testing-library/react'
import App from '../../src/components/App';

global.console = {log: jest.fn()}

global.fetch = jest.fn(() => Promise.resolve({
data: [],
json: jest.fn(() => [])
}));

describe('Validates App initialization', () => {
it('Creates App', () => {
const app = render(<App />);
expect(app).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import { render } from '@testing-library/react'
import CustomNodeFactory from '../../../src/components/CustomNode/CustomNodeFactory';
import CustomNodeModel from '../../../src/components/CustomNode/CustomNodeModel';
import CustomNodeWidget from '../../../src/components/CustomNode/CustomNodeWidget';

describe('Validate CustomNodeFactory', () => {
it('CustomNodeFactory generates CustomNodeWidget', () => {
const customNodeFactory = new CustomNodeFactory();
const node = new CustomNodeModel({id: "myId"});
const model = {
node: node,
};
const event = {
model: model,
initialConfig: {
options: { id: "modelId"},
config: {}
}
};
const widget = customNodeFactory.generateReactWidget(event);
expect(React.isValidElement(widget)).toBe(true);

const nodeModel = customNodeFactory.generateModel(event);
expect(nodeModel instanceof CustomNodeModel).toBe(true);
expect(nodeModel.getNodeId()).toBe("modelId");
});
})
27 changes: 27 additions & 0 deletions front-end/__tests__/components/CustomNode/CustomNodeModel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import CustomNodeModel from '../../../src/components/CustomNode/CustomNodeModel';
import CustomNodeFactory from '../../../src/components/CustomNode/CustomNodeFactory';
import VPPortFactory from '../../../src/components/VPPort/VPPortFactory';
import createEngine from '@projectstorm/react-diagrams';


describe('Validates CustomNodeModel', () => {
it('Validates serialization/deserialization', () => {
const node = new CustomNodeModel({id: "myId", num_in: 2, num_out: 1});
node.setStatus("Complete");
const engine = createEngine();
engine.getNodeFactories().registerFactory(new CustomNodeFactory());
engine.getPortFactories().registerFactory(new VPPortFactory());

const serializedModel = node.serialize();
const event = {
data: serializedModel,
engine: engine,
registerModel: jest.fn(() => [])
};
const otherNode = new CustomNodeModel();
otherNode.deserialize(event, engine);

expect(event.registerModel.mock.calls.length).toBe(4);
});
});
Loading