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