mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
fb465e4704
refs https://ghost.slack.com/archives/C06TQR9SHSM/p1716816764653789?thread_ts=1716795330.737919&cid=C06TQR9SHSM MOM-158 - adds a new `hasFeature` helper for adding content behind a flag within Email Templates. - Usage: `{{#hasFeature 'flagname'}} <p>html behind flag</p> {{/hasFeature}}` - Added additional testing for testing the helpers
142 lines
3.4 KiB
JavaScript
142 lines
3.4 KiB
JavaScript
const assert = require('assert/strict');
|
|
const {registerHelpers} = require('../lib/helpers/register-helpers');
|
|
|
|
describe('registerHelpers', function () {
|
|
it('registers helpers', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return true;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
assert.ok(handlebars.if);
|
|
assert.ok(handlebars.and);
|
|
assert.ok(handlebars.not);
|
|
assert.ok(handlebars.or);
|
|
assert.ok(handlebars.hasFeature);
|
|
});
|
|
|
|
it('if helper returns true', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return true;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
const result = handlebars.if(true, {
|
|
fn: function () {
|
|
return true;
|
|
},
|
|
inverse: function () {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
assert.equal(result, true);
|
|
});
|
|
|
|
it('if helper returns false', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return true;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
const result = handlebars.if(false, {
|
|
fn: function () {
|
|
return true;
|
|
},
|
|
inverse: function () {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
assert.equal(result, false);
|
|
});
|
|
|
|
it('and helper returns true', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return true;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
const result = handlebars.and(true, true);
|
|
|
|
assert.equal(result, true);
|
|
});
|
|
|
|
it('usefeature helper returns true', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return true;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
const result = handlebars.hasFeature('test', {
|
|
fn: function () {
|
|
return true;
|
|
},
|
|
inverse: function () {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
assert.equal(result, true);
|
|
});
|
|
|
|
it('usefeature helper returns false', function () {
|
|
const handlebars = {
|
|
registerHelper: function (name, fn) {
|
|
this[name] = fn;
|
|
}
|
|
};
|
|
const labs = {
|
|
isSet: function () {
|
|
return false;
|
|
}
|
|
};
|
|
registerHelpers(handlebars, labs);
|
|
|
|
const result = handlebars.hasFeature('test', {
|
|
fn: function () {
|
|
return true;
|
|
},
|
|
inverse: function () {
|
|
return false;
|
|
}
|
|
});
|
|
|
|
assert.equal(result, false);
|
|
});
|
|
}); |