mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 11:50:02 +01:00
Add tests for notify() (#686)
* Added HTML-UI test * Added test for notify() * Updated Readme's
This commit is contained in:
committed by
Jeffrey Warren
parent
413a235594
commit
8fd4efc621
@@ -175,6 +175,7 @@ There are four events in all:
|
||||
* `UI.onComplete(options.step)` must be emitted whenever the output of a draw call
|
||||
is ready. An argument, that is the DataURL of the output image must be passed in.
|
||||
* `UI.onRemove(options.step)` is emitted automatically and the module should not emit it.
|
||||
* `UI.notify(msg,id)` must be emmited when a notification has to be produced.
|
||||
|
||||
### Name and description
|
||||
|
||||
|
||||
@@ -549,6 +549,10 @@ for a module. This can be used, for instance, to update the DIV with the new ima
|
||||
and remove the loading GIF generated above.
|
||||
* `onRemove` : This event is triggered when a module is removed. This can be used,
|
||||
for instance, to remove the DIV generated above.
|
||||
* `notify` : This event is triggered whenever we need to shoot a notification to the
|
||||
user-interface.For example when the step is not available, we can shoot a notification,
|
||||
by sending appropriate message.For HTML UI it adds a DOM node to the browser, for CLI
|
||||
and node , it logs the notification output to the respective console.
|
||||
|
||||
How to define these functions:
|
||||
|
||||
@@ -557,7 +561,8 @@ sequencer.setUI({
|
||||
onSetup: function(step) {},
|
||||
onDraw: function(step) {},
|
||||
onComplete: function(step) {},
|
||||
onRemove: function(step) {}
|
||||
onRemove: function(step) {},
|
||||
notify: function(msg,id) {}
|
||||
});
|
||||
```
|
||||
|
||||
@@ -607,3 +612,5 @@ not specified, the name of a loaded image defaults to a name like "image1",
|
||||
|
||||
Details of all modules can be sought using `sequencer.modulesInfo()`.
|
||||
This method returns an object which defines the name and inputs of the modules. If a module name (hyphenated) is passed in the method, then only the details of that module are returned.
|
||||
|
||||
The `notify` function takes two parameters `msg` and `id`, former being the message to be displayed on console (in case of CLI and node ) and a HTML component(in browser). The id is optional and is useful for HTML interface to give appropriate IDs.
|
||||
@@ -295,3 +295,9 @@ function DefaultHtmlStepUi(_sequencer, options) {
|
||||
notify: notify
|
||||
}
|
||||
}
|
||||
|
||||
if(typeof window === "undefined"){
|
||||
module.exports={
|
||||
DefaultHtmlStepUi: DefaultHtmlStepUi
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
"main": "src/ImageSequencer.js",
|
||||
"scripts": {
|
||||
"debug": "TEST=true node ./index.js -i ./examples/images/monarch.png -s invert",
|
||||
"test": "TEST=true tape test/**/*.js test/*.js | tap-spec; browserify test/modules/image-sequencer.js test/modules/chain.js test/modules/meta-modules.js test/modules/replace.js test/modules/import-export.js test/modules/run.js test/modules/dynamic-imports.js | tape-run --render=\"tap-spec\"",
|
||||
"test": "TEST=true tape test/ui/*.js test/**/*.js test/*.js test/ui/user-interface.js | tap-spec; browserify test/modules/image-sequencer.js test/modules/chain.js test/modules/meta-modules.js test/modules/replace.js test/modules/import-export.js test/modules/run.js test/modules/dynamic-imports.js test/util/parse-input.js | tape-run --render=\"tap-spec\"",
|
||||
"setup": "npm i && npm i -g grunt grunt-cli",
|
||||
"start": "grunt serve"
|
||||
},
|
||||
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/publiclab/image-sequencer.git"
|
||||
@@ -35,6 +36,7 @@
|
||||
"imagejs": "0.0.9",
|
||||
"imgareaselect": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2",
|
||||
"jquery": "^3.3.1",
|
||||
"jsdom": "^11.12.0",
|
||||
"jsqr": "^1.1.1",
|
||||
"lodash": "^4.17.5",
|
||||
"ndarray-gaussian-filter": "^1.0.0",
|
||||
|
||||
31
test/ui/user-interface.js
Normal file
31
test/ui/user-interface.js
Normal file
@@ -0,0 +1,31 @@
|
||||
var test = require('tape');
|
||||
var jsdom = require('jsdom');
|
||||
var JSDOM = jsdom.JSDOM;
|
||||
|
||||
var DOM = new JSDOM(`<body></body>`);
|
||||
|
||||
global.document = DOM.window.document;
|
||||
|
||||
var DefaultHtmlStepUi = require('../../examples/lib/defaultHtmlStepUi').DefaultHtmlStepUi;
|
||||
var sequencer = require('../../src/ImageSequencer.js')();
|
||||
var UserInterface = require('../../src/ui/UserInterface');
|
||||
|
||||
test('Notify function works for all three UIs', function (t) {
|
||||
//Mocking console.log for testing default notify()
|
||||
function doesLogMessage(f, message) {
|
||||
var oldLog = console.log,
|
||||
result = false;
|
||||
console.log = function (s) {
|
||||
if (s == message) {
|
||||
result = true;
|
||||
}
|
||||
};
|
||||
f('Test Message');
|
||||
console.log = oldLog;
|
||||
return result;
|
||||
}
|
||||
t.equal(doesLogMessage(UserInterface().notify, 'Test Message'),true,'Default notify() produces correct output');
|
||||
sequencer.setUI(DefaultHtmlStepUi(sequencer));
|
||||
t.equal(typeof sequencer.events.notify, "function", "Html UI contains notify function");
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user