2020-01-27 14:41:12 +03:00
|
|
|
const should = require('should');
|
2020-03-30 18:26:47 +03:00
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
|
|
|
const handlebars = require('../../../core/frontend/services/themes/engine').handlebars;
|
2020-01-27 14:41:12 +03:00
|
|
|
|
|
|
|
function compile(templateString) {
|
|
|
|
const template = handlebars.compile(templateString);
|
|
|
|
template.with = (locals = {}, globals) => {
|
|
|
|
return template(locals, globals);
|
|
|
|
};
|
|
|
|
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('{{price}} helper', function () {
|
|
|
|
before(function () {
|
|
|
|
handlebars.registerHelper('price', helpers.price);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws an error for no provided parameters', function () {
|
|
|
|
(function compileWith() {
|
|
|
|
compile('{{price}}')
|
|
|
|
.with({});
|
|
|
|
}).should.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws an error for undefined parameter', function () {
|
|
|
|
(function compileWith() {
|
|
|
|
compile('{{price @dont.exist}}')
|
|
|
|
.with({});
|
|
|
|
}).should.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws if argument is not a number', function () {
|
|
|
|
(function compileWith() {
|
|
|
|
compile('{{price "not_a_number"}}')
|
|
|
|
.with({});
|
|
|
|
}).should.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will format decimal adjusted amount', function () {
|
|
|
|
compile('{{price 2000}}')
|
|
|
|
.with({})
|
|
|
|
.should.equal('20');
|
|
|
|
});
|
|
|
|
});
|