2020-04-29 18:44:27 +03:00
|
|
|
const sinon = require('sinon');
|
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
2020-05-28 21:30:23 +03:00
|
|
|
const logging = require('../../../core/shared/logging');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{#is}} helper', function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-03-21 11:24:11 +03:00
|
|
|
});
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
// All positive tests
|
|
|
|
it('should match single context "index"', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const fn = sinon.spy();
|
|
|
|
const inverse = sinon.spy();
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
helpers.is.call(
|
|
|
|
{},
|
|
|
|
'index',
|
|
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['home', 'index']}}}
|
|
|
|
);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.true();
|
|
|
|
inverse.called.should.be.false();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should match OR context "index, paged"', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const fn = sinon.spy();
|
|
|
|
const inverse = sinon.spy();
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
helpers.is.call(
|
|
|
|
{},
|
|
|
|
'index, paged',
|
|
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['tag', 'paged']}}}
|
|
|
|
);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.true();
|
|
|
|
inverse.called.should.be.false();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not match "paged"', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const fn = sinon.spy();
|
|
|
|
const inverse = sinon.spy();
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
helpers.is.call(
|
|
|
|
{},
|
|
|
|
'paged',
|
|
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['index', 'home']}}}
|
|
|
|
);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.called.should.be.true();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
2015-05-14 13:31:43 +03:00
|
|
|
|
|
|
|
it('should log warning with no args', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const fn = sinon.spy();
|
|
|
|
const inverse = sinon.spy();
|
2020-05-28 21:30:23 +03:00
|
|
|
const logWarn = sinon.stub(logging, 'warn');
|
2015-05-14 13:31:43 +03:00
|
|
|
|
|
|
|
helpers.is.call(
|
|
|
|
{},
|
|
|
|
undefined,
|
|
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['index', 'home']}}}
|
|
|
|
);
|
|
|
|
|
2016-02-08 00:27:01 +03:00
|
|
|
logWarn.called.should.be.true();
|
|
|
|
fn.called.should.be.false();
|
|
|
|
inverse.called.should.be.false();
|
2015-05-14 13:31:43 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|