Skip to content

Commit

Permalink
tests + demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoltsova committed Dec 7, 2017
1 parent 8eb0128 commit 3800c38
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 57 deletions.
9 changes: 7 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ async function initialize() {
processButton('btn-build', () => {
const elem = document.getElementById('txt-script');
const baseURI = document.getElementById('base-url').value || null;
const recursionDepth = document.getElementById('recursion-depth').value || null;
const subWfDetailing = (document.getElementById('sub-wf-detailing').value || '').split(',').map(wf => wf.trim());

if (elem) {
pipeline.parse(elem.value, { baseURI }).then((res) => {
pipeline.parse(elem.value, { baseURI, recursionDepth, subWfDetailing }).then((res) => {
flow1 = res.model[0];
diagram.attachTo(flow1);
}).catch((message) => {
Expand Down Expand Up @@ -129,11 +132,13 @@ document.getElementById('file').addEventListener('change', (evt) => {
const file = evt.target.files[0];
const elem = document.getElementById('txt-script');
const baseUrl = document.getElementById('base-url').value || null;
const recursionDepth = parseInt(document.getElementById('recursion-depth').value, 10) || null;
const subWfDetailing = (document.getElementById('sub-wf-detailing').value || '').split(',').map(wf => wf.trim());

document.getElementById('file').value = '';

if (elem && elem.value && file && file.name.indexOf('.zip') === file.name.length - 4) {
pipeline.parse(elem.value, { zipFile: file, baseUrl }).then((res) => {
pipeline.parse(elem.value, { zipFile: file, baseUrl, recursionDepth, subWfDetailing }).then((res) => {
flow1 = res.model[0];
diagram.attachTo(flow1);
}).catch((message) => {
Expand Down
5 changes: 5 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<input type="button" value = "Load zip" id="btn-load-zip"/>
Base Url: <input type="text" id="base-url"/>
</p>
<p>
<label for="sub-wf-detailing">SubWorkflow to be detailed("*" - show all SubWorkflow detailed, "wf1, wf2" - show wf1 and wf2 detailed):</b></label><br>
<textarea rows="5" cols="20" id="sub-wf-detailing"></textarea><br>
Depth of recursion: <input type="text" value="0" id="recursion-depth"/>
</p>
<p>
<label for="txt-script"><b>Paste your .wdl script here:</b></label><br>
<textarea id="txt-script" cols="150" rows="20"></textarea>
Expand Down
23 changes: 7 additions & 16 deletions src/model/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,6 @@ export default class Step {
*/
this.o = _.mapValues(action.o, (portDesc, portName) => new Port(portName, this, portDesc));
bindPorts(config.o || {}, this.o);

const updateParentName = (parent, newName) => {
parent.name = newName;
if (parent.parent) {
updateParentName(parent.parent, parent.name);
}
};

_.forEach(config.children, (child, childName) => {
const copyChildParent = _.clone(child.parent);
updateParentName(copyChildParent, this.name);
const copyChild = _.clone(child);
copyChild.parent = copyChildParent;
this.children[childName] = copyChild;
});
}

/**
Expand Down Expand Up @@ -282,7 +267,13 @@ export default class Step {
}
const beforeResult = callback.before && callback.before(this);
if (beforeResult !== false) {
_.forEach(this.children, child => child.walk(callback));
_.forEach(this.children, (child) => {
if (child === this || child.type !== 'workflow') {
child.walk(callback);
} else {
callback.before(child);
}
});
}
return callback.after && callback.after(this);
}
Expand Down
8 changes: 1 addition & 7 deletions src/model/Workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ class Workflow extends Group {
*/
addAction(action) {
const existing = this.actions[action.name];
function ignoreFunctions(value, other) {
if (_.isFunction(value) && _.isFunction(other)) {
return true;
}
return undefined;
}
if (existing && !_.isEqualWith(existing, action, ignoreFunctions)) {
if (existing && existing !== action) {
throw new Error('Cannot add another action with the same name');
}
this.actions[action.name] = action;
Expand Down
8 changes: 4 additions & 4 deletions src/parser/parse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import * as JSZip from 'jszip';
import parseWDL from './WDL/parse';

Expand All @@ -21,11 +22,10 @@ import parseWDL from './WDL/parse';
*/
function parse(text, opts = {}) {
const format = opts.format || 'wdl';
// const subWfDetailing = (opts.subWfDetailing && _.isArray(opts.subWfDetailing)) ? opts.subWfDetailing : null;// todo uncomment
const subWfDetailing = ['*'];// CopyRatio_CNVSomaticCopyRatioBAMWorkflow
// const recursionDepth = opts.recursionDepth || 0 ;// todo uncomment
const recursionDepth = 10;
const subWfDetailing = (opts.subWfDetailing && _.isArray(opts.subWfDetailing)) ? opts.subWfDetailing : null;
const recursionDepth = opts.recursionDepth || 0;
const baseURI = opts.baseURI || null;

if (format === 'wdl') {
if (opts.zipFile) {
return JSZip.loadAsync(opts.zipFile).then((files) => {
Expand Down
78 changes: 52 additions & 26 deletions test/dataServices/data-servicesTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sinon from 'sinon';
import { expect } from 'chai';

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import DataService from '../../src/dataServices/data-services';

chai.use(chaiAsPromised);
const { expect } = chai;

let requests = [];

describe('data-services $http', () => {
Expand All @@ -24,38 +27,42 @@ describe('data-services $http', () => {
it('resolves as promised', () => {
const promise = DataService.get('test_url');
requests[0].respond(200, { 'Content-Type': 'text' }, 'OK');
return promise.then((result) => {
expect(requests[0].method).to.be.equal('get');
expect(requests[0].url).to.be.equal('test_url');
expect(result).to.be.equal('OK');
});
return Promise.all([
expect(promise).to.be.fulfilled,
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
expect(promise).to.eventually.deep.equal('OK'),
]);
});

it('reject when response status 404 promised', () => {
const promise = DataService.get('test_url');
requests[0].respond(404, { 'Content-Type': 'text' }, 'Not found');
return promise.catch((result) => {
expect(requests[0].method).to.be.equal('get');
expect(requests[0].url).to.be.equal('test_url');
expect(requests[0].status).to.be.equal(404);
expect(result).to.be.equal('Not found');
});
return Promise.all([
expect(promise).to.be.rejected,
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
]);
});

it('xhr error as promised', () => {
const promise = DataService.get('test_url');
requests[0].respond(0, { 'Content-Type': 'text' }, 'OK');
return promise.catch((result) => {
expect(result.type).to.be.equal('error');
});
return Promise.all([
expect(promise).to.be.rejected.and.eventually.have.property('type', 'error'),
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
]);
});

it('xhr abort as promised', () => {
const promise = DataService.get('test_url');
requests[0].abort();
return promise.catch((result) => {
expect(result.type).to.be.equal('abort');
});
return Promise.all([
expect(promise).to.be.rejected.and.eventually.have.property('type', 'abort'),
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
]);
});

it('resolves as promised with JSON data', () => {
Expand All @@ -66,18 +73,37 @@ describe('data-services $http', () => {

requests[0].respond(200, { 'Content-Type': 'text' }, dataJson);

return promise.then((result) => {
expect(result).to.be.equal(dataJson);
});
return Promise.all([
expect(promise).to.be.fulfilled,
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
expect(promise).to.eventually.deep.equal(dataJson),
]);
});

it('resolves as promised with string data', () => {
it('resolves as promised with string data (get)', () => {
const promise = DataService.get('test_url', 'data');

requests[0].respond(200, { 'Content-Type': 'text' }, 'data');

return promise.then((data) => {
expect(data).to.be.equal('data');
});
return Promise.all([
expect(promise).to.be.fulfilled,
expect(requests[0].method).to.be.equal('get'),
expect(requests[0].url).to.be.equal('test_url'),
expect(promise).to.eventually.deep.equal('data'),
]);
});

it('resolves as promised with string data (post)', () => {
const promise = DataService.post('test_url', 'data');

requests[0].respond(200, { 'Content-Type': 'text' }, 'data');

return Promise.all([
expect(promise).to.be.fulfilled,
expect(requests[0].method).to.be.equal('post'),
expect(requests[0].url).to.be.equal('test_url'),
expect(promise).to.eventually.deep.equal('data'),
]);
});
});
30 changes: 29 additions & 1 deletion test/parser/WDL/entities/ContextTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,35 @@ describe('parser/WDL/entities/Context', () => {
line: 3,
col: 8,
},
expression: null,
expression: {
attributes: {
lhs: {
attributes: {
name: {
col: 22,
id: 39,
line: 28,
resource: undefined,
source_string: 'select_first',
str: 'identifier',
},
params: {
list: [],
},
},
name: 'FunctionCall',
},
rhs: {
col: 60,
id: 27,
line: 28,
resource: undefined,
source_string: '',
str: 'string',
},
},
name: 'Equals',
},
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/parser/parseTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ workflow RootWorkflow {
resolve(data);
}
});
}).then(data => parse(wdl, { zipFile: data }))).to.be.fulfilled);
}).then(data => parse(wdl, { zipFile: data, subWfDetailing: '*', recursionDepth: 10 }))).to.be.fulfilled);

it('returns with error if source zip is incorrect', () =>
expect(parse(wdl, { zipFile: 'test' })).to.be.rejectedWith('Error'));
Expand Down

0 comments on commit 3800c38

Please sign in to comment.