2020-04-29 18:44:27 +03:00
|
|
|
const sinon = require('sinon');
|
2021-10-06 12:52:46 +03:00
|
|
|
const is = require('../../../../core/frontend/helpers/is');
|
2021-06-15 17:36:27 +03:00
|
|
|
const logging = require('@tryghost/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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
is.call(
|
2014-10-10 18:54:07 +04:00
|
|
|
{},
|
|
|
|
'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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
is.call(
|
2014-10-10 18:54:07 +04:00
|
|
|
{},
|
|
|
|
'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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
is.call(
|
2014-10-10 18:54:07 +04:00
|
|
|
{},
|
|
|
|
'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
|
|
|
|
2021-10-04 18:30:54 +03:00
|
|
|
is.call(
|
2015-05-14 13:31:43 +03:00
|
|
|
{},
|
|
|
|
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
|
|
|
});
|