pad.libre-service.eu-etherpad/tests/backend/specs/easysync/makeattribsstring.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-08-04 12:47:44 +02:00
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
var AttributePool = require("ep_etherpad-lite/static/js/AttributePool");
var helper = require("./helper.js")
var assertEqualStrings = helper.assertEqualStrings;
describe("make attribs string",function(){
it("make attribs string",function(done){
testMakeAttribsString(1, ['bold,'], '+', [
['bold', '']
], '');
testMakeAttribsString(2, ['abc,def', 'bold,'], '=', [
['bold', '']
], '*1');
testMakeAttribsString(3, ['abc,def', 'bold,true'], '+', [
['abc', 'def'],
['bold', 'true']
], '*0*1');
testMakeAttribsString(4, ['abc,def', 'bold,true'], '+', [
['bold', 'true'],
['abc', 'def']
], '*0*1');
done()
})
})
function testMakeAttribsString(testId, pool, opcode, attribs, correctString) {
var p = poolOrArray(pool);
var str = Changeset.makeAttribsString(opcode, attribs, p);
assertEqualStrings(correctString, str);
}
function poolOrArray(attribs) {
if (attribs.getAttrib) {
return attribs; // it's already an attrib pool
} else {
// assume it's an array of attrib strings to be split and added
var p = new AttributePool();
attribs.forEach(function (kv) {
p.putAttrib(kv.split(','));
});
return p;
}
}