Skip to content

Commit

Permalink
Merge pull request #4 from fisuda/update
Browse files Browse the repository at this point in the history
Update testcase
  • Loading branch information
fisuda committed Jan 3, 2020
2 parents b963142 + 0c39b76 commit aafb89c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/js/JsonInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var JsonInjector = (function () {
buttons.appendChild(action_buttons);

var sendbtn = new StyledElements.Button({
id: 'button',
iconClass: 'fa fa-play',
state: 'info',
title: 'Output data'
Expand Down Expand Up @@ -104,6 +105,7 @@ var JsonInjector = (function () {
data = JSON.stringify(data, null , "\t");
} catch (e) {
type = '';
throw new MashupPlatform.wiring.EndpointTypeError();
}
} else if (typeof data === "string") {
type = 'JSON - (Object)';
Expand Down
43 changes: 27 additions & 16 deletions tests/helpers/ace.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
(function () {
class Session {
constructor() {
}

"use strict";
setMode() {}
setTabSize() {}
on() {}
}

window.ace = {
edit: function () {
return {
setFontSize: function () {},
setValue: function () {},
session: {
setMode: function () {},
setTabSize: function () {},
on: function () {}
}
}
}
};
class Edit {
constructor() {
this.session = new Session();
this.value = '{}';
}
setFontSize() {}
setValue(v) {this.value = v}
getValue() {return this.value}
}

class Ace {
constructor() {
this._edit = new Edit();
}

setFontSize() {}
edit() {return this._edit}
}

window.Ace = Ace;

})();
60 changes: 57 additions & 3 deletions tests/js/JsonInjectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,85 @@
* Licensed under the MIT license.
*/

/* globals $, MashupPlatform, MockMP, JsonInjector */
/* globals MashupPlatform, MockMP, Ace, JsonInjector */

(function () {

"use strict";


describe("JsonInjector", function () {

var widget;
var editor;

beforeAll(function () {
window.MashupPlatform = new MockMP({
type: 'widget',
inputs: ['input'],
outputs: ['output']
});
window.ace = new Ace();
});

beforeEach(function () {
MashupPlatform.reset();
MashupPlatform.wiring.connectInput('input');
MashupPlatform.widget.outputs.output.connect({simulate: () => {}});
widget = new JsonInjector();
});

it("Dummy test", function () {
expect(widget).not.toBe(null);
it("click", function (done) {
MashupPlatform.wiring.simulate('input', {"name": "abc"});
setTimeout(() => {
let button = document.getElementById('button');
button.click();

expect(MashupPlatform.wiring.pushEvent).toHaveBeenCalledWith('output', { name: 'abc' });
done();
}, 300);
});

it("click", function (done) {
MashupPlatform.wiring.simulate('input', '{}');
setTimeout(() => {
let button = document.getElementById('button');
button.click();

expect(MashupPlatform.wiring.pushEvent).toHaveBeenCalledWith('output', {});
done();
}, 300);
});

it("click", function (done) {
MashupPlatform.wiring.simulate('input', {func: function (){}});

setTimeout(() => {
expect(MashupPlatform.wiring.simulate).toThrow();
done();
}, 300);
});

it("click", function (done) {
MashupPlatform.wiring.simulate('input', '{');
setTimeout(() => {
let button = document.getElementById('button');
button.click();

expect(MashupPlatform.wiring.pushEvent).not.toHaveBeenCalled();
done();
}, 300);
});

it("click", function (done) {
MashupPlatform.widget.outputs.output.disconnect();
setTimeout(() => {
let button = document.getElementById('button');
button.click();

expect(MashupPlatform.wiring.pushEvent).not.toHaveBeenCalled();
done();
}, 300);
});

});
Expand Down

0 comments on commit aafb89c

Please sign in to comment.