2017-03-23 22:00:58 +03:00
|
|
|
var should = require('should'), // jshint ignore:line
|
2017-03-21 11:24:11 +03:00
|
|
|
sinon = require('sinon'),
|
|
|
|
helpers = require('../../../server/helpers'),
|
2017-12-12 00:47:46 +03:00
|
|
|
common = require('../../../server/lib/common'),
|
2017-03-21 11:24:11 +03:00
|
|
|
|
|
|
|
sandbox = sinon.sandbox.create();
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{#is}} helper', function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
// All positive tests
|
|
|
|
it('should match single context "index"', function () {
|
2017-03-21 11:24:11 +03:00
|
|
|
var fn = sandbox.spy(),
|
|
|
|
inverse = sandbox.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 () {
|
2017-03-21 11:24:11 +03:00
|
|
|
var fn = sandbox.spy(),
|
|
|
|
inverse = sandbox.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 () {
|
2017-03-21 11:24:11 +03:00
|
|
|
var fn = sandbox.spy(),
|
|
|
|
inverse = sandbox.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 () {
|
2017-03-21 11:24:11 +03:00
|
|
|
var fn = sandbox.spy(),
|
|
|
|
inverse = sandbox.spy(),
|
2017-12-12 00:47:46 +03:00
|
|
|
logWarn = sandbox.stub(common.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
|
|
|
});
|