mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 04:10:04 +01:00
test import string with no configs (#279)
* test import string with no configs * now working without () Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * update test Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * refactor for readability * refactor for pipes | between multiple step settings * fixed bugs * test fixed
This commit is contained in:
22267
dist/image-sequencer.js
vendored
22267
dist/image-sequencer.js
vendored
File diff suppressed because one or more lines are too long
2
dist/image-sequencer.min.js
vendored
2
dist/image-sequencer.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -217,35 +217,42 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
inputs[input] = encodeURIComponent(inputs[input]);
|
||||
}
|
||||
|
||||
var configurations = Object.keys(inputs).map(key=>key + ':' + inputs[key]).join(',');
|
||||
var configurations = Object.keys(inputs).map(key => key + ':' + inputs[key]).join('|');
|
||||
return `${step.options.name}(${configurations})`;
|
||||
}
|
||||
|
||||
// Coverts stringified sequence into JSON
|
||||
function importStringtoJson(str){
|
||||
let steps = str.split('),');
|
||||
steps.push(steps.splice(-1)[0].slice(0,-1));
|
||||
let steps = str.split(',');
|
||||
return steps.map(importStringtoJsonStep);
|
||||
}
|
||||
|
||||
// Converts one stringified step into JSON
|
||||
function importStringtoJsonStep(str){
|
||||
str = [
|
||||
str.substr(0,str.indexOf('(')),
|
||||
str.slice(str.indexOf('(')+1)
|
||||
];
|
||||
if(str.indexOf('(') === -1) { // if there are no settings specified
|
||||
var moduleName = str.substr(0);
|
||||
stepSettings = "";
|
||||
} else {
|
||||
var moduleName = str.substr(0, str.indexOf('('));
|
||||
stepSettings = str.slice(str.indexOf('(') + 1, -1);
|
||||
}
|
||||
|
||||
str[1] = str[1].split(',').reduce(function(acc,cur,i){
|
||||
cur = [
|
||||
cur.substr(0,cur.indexOf(':')),
|
||||
decodeURIComponent(cur.substr(cur.indexOf(':') + 1))
|
||||
stepSettings = stepSettings.split('|').reduce(function formatSettings(accumulator, current, i){
|
||||
var settingName = current.substr(0, current.indexOf(':')),
|
||||
settingValue = current.substr(current.indexOf(':') + 1);
|
||||
settingValue = settingValue.replace(/^\(/, '').replace(/\)$/, ''); // strip () at start/end
|
||||
settingValue = decodeURIComponent(settingValue);
|
||||
current = [
|
||||
settingName,
|
||||
settingValue
|
||||
];
|
||||
if(!!cur[0]) acc[cur[0]] = cur[1];
|
||||
return acc;
|
||||
if (!!settingName) accumulator[settingName] = settingValue;
|
||||
return accumulator;
|
||||
}, {});
|
||||
|
||||
return {
|
||||
name : str[0],
|
||||
options:str[1]
|
||||
name : moduleName,
|
||||
options: stepSettings
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,24 @@ test('toString() and stepToString() return the step/steps in string format',func
|
||||
t.equal(sequencer.stepToString(sequencer.steps[1]),"channel(channel:green)","stepToString works");
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('importStringtoJson() and importStringtoJsonStep() return the step/steps from a string', function(t){
|
||||
t.deepEqual(sequencer.importStringtoJson('channel(channel:green),invert(),blend(blend:function(r1%2C%20g1%2C%20b1%2C%20a1%2C%20r2%2C%20g2%2C%20b2%2C%20a2)%20%7B%20return%20%5B%20r1%2C%20g2%2C%20b2%2C%20a2%20%5D%20%7D)'),[
|
||||
t.deepEqual(sequencer.importStringtoJson('channel(channel:green),invert(),crop(x:0|y:0|w:50%25|h:50%25),blend(blend:function(r1%2C%20g1%2C%20b1%2C%20a1%2C%20r2%2C%20g2%2C%20b2%2C%20a2)%20%7B%20return%20%5B%20r1%2C%20g2%2C%20b2%2C%20a2%20%5D%20%7D)'),[
|
||||
{ name: 'channel', options: { channel: 'green' } },
|
||||
{ name: 'invert', options: {} },
|
||||
{ name: 'crop', options: { x: '0', y: '0', w: '50%', h: '50%'} },
|
||||
{ name: 'blend', options: { blend: 'function(r1, g1, b1, a1, r2, g2, b2, a2) { return [ r1, g2, b2, a2 ] }' } }
|
||||
]);
|
||||
t.deepEqual(sequencer.importStringtoJsonStep("channel(channel:green)"),{ name: 'channel', options: { channel: 'green)' } });
|
||||
t.deepEqual(sequencer.importStringtoJsonStep("channel(channel:green)"),{ name: 'channel', options: { channel: 'green' } });
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('importStringtoJson() and importStringtoJsonStep() return the step/steps from a string without configs, using defaults', function(t){
|
||||
t.deepEqual(sequencer.importStringtoJson('channel,blur,invert,blend'),[
|
||||
{ name: 'channel', options: { } },
|
||||
{ name: 'blur', options: { } },
|
||||
{ name: 'invert', options: { } },
|
||||
{ name: 'blend', options: { } }
|
||||
]);
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user