2021-06-07 20:22:06 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
2021-07-07 21:41:34 +01:00
|
|
|
const labs = require('../../../core/shared/labs');
|
2021-06-07 20:22:06 +01:00
|
|
|
const handlebars = require('../../../core/frontend/services/theme-engine/engine').handlebars;
|
|
|
|
|
|
|
|
describe('Match helper', function () {
|
|
|
|
before(function () {
|
|
|
|
handlebars.registerHelper('match', helpers.match);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sinon.stub(labs, 'isSet').returns(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
function shouldCompileToExpected(templateString, hash, expected) {
|
|
|
|
const template = handlebars.compile(templateString);
|
|
|
|
const result = template(hash);
|
|
|
|
|
|
|
|
result.should.eql(expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('{{#match}} (block)', function () {
|
|
|
|
before(function () {
|
|
|
|
handlebars.registerHelper('foreach', helpers.foreach);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{#match title "=" "Hello World"}} works when true', function () {
|
|
|
|
const templateString = '{{#match title "=" "Hello World"}}true{{else}}false{{/match}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Hello World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'true';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{#match title "=" "Hello World"}} works when false', function () {
|
|
|
|
const templateString = '{{#match title "=" "Hello World"}}true{{else}}false{{/match}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Goodbye World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'false';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{#match title "!=" "Hello World"}} works when true', function () {
|
|
|
|
const templateString = '{{#match title "!=" "Hello World"}}true{{else}}false{{/match}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Goodbye World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'true';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{#match title "!=" "Hello World"}} works when false', function () {
|
|
|
|
const templateString = '{{#match title "!=" "Hello World"}}true{{else}}false{{/match}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Hello World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'false';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('{{match}} (inline)', function () {
|
|
|
|
before(function () {
|
|
|
|
handlebars.registerHelper('foreach', helpers.foreach);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{match title "=" "Hello World"}} works when true', function () {
|
|
|
|
const templateString = '{{match title "=" "Hello World"}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Hello World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'true';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{match title "=" "Hello World"}} works when false', function () {
|
|
|
|
const templateString = '{{match title "=" "Hello World"}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Goodbye World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'false';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{match title "!=" "Hello World"}} works when true', function () {
|
|
|
|
const templateString = '{{match title "!=" "Hello World"}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Goodbye World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'true';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('{{match title "!=" "Hello World"}} works when false', function () {
|
|
|
|
const templateString = '{{match title "!=" "Hello World"}}';
|
|
|
|
const hash = {
|
|
|
|
title: 'Hello World'
|
|
|
|
};
|
|
|
|
|
|
|
|
const expected = 'false';
|
|
|
|
|
|
|
|
shouldCompileToExpected(templateString, hash, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|