2019-07-25 12:08:29 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2020-03-30 18:26:47 +03:00
|
|
|
const helpers = require('../../../core/frontend/helpers');
|
|
|
|
const settingsCache = require('../../../core/server/services/settings/cache');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{meta_description}} helper', function () {
|
2019-07-25 12:08:29 +03:00
|
|
|
const localSettingsCache = {};
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
before(function () {
|
2019-07-25 12:08:29 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key) {
|
|
|
|
return localSettingsCache[key];
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
2019-07-25 12:08:29 +03:00
|
|
|
describe('no meta_description', function () {
|
|
|
|
before(function () {
|
|
|
|
localSettingsCache.description = 'The professional publishing platform';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns correct site description', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{},
|
|
|
|
{data: {root: {context: ['home', 'index']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('The professional publishing platform');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description on paginated page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{},
|
|
|
|
{data: {root: {context: ['index', 'paged']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description for a tag page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{tag: {name: 'Rasper Red'}},
|
|
|
|
{data: {root: {context: ['tag']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description for a paginated tag page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{tag: {name: 'Rasper Red'}},
|
|
|
|
{data: {root: {context: ['tag', 'paged']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns tag meta_description if present for a tag page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}},
|
|
|
|
{data: {root: {context: ['tag']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('Rasper is the Cool Red Casper');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description on paginated tag page that has meta data', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}},
|
|
|
|
{data: {root: {context: ['tag', 'paged']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
2019-11-21 16:08:00 +03:00
|
|
|
it('returns author bio for an author page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{author: {bio: 'I am a Duck.'}},
|
|
|
|
{data: {root: {context: ['author']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
2019-11-21 16:08:00 +03:00
|
|
|
String(rendered).should.equal('I am a Duck.');
|
2019-07-25 12:08:29 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description for a paginated author page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{author: {name: 'Donald Duck'}},
|
|
|
|
{data: {root: {context: ['author', 'paged']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns empty description when meta_description is not set', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{post: {title: 'Post Title', html: 'Very nice post indeed.'}},
|
|
|
|
{data: {root: {context: ['post']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns meta_description on post with meta_description set', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{post: {title: 'Post Title', meta_description: 'Nice post about stuff.'}},
|
|
|
|
{data: {root: {context: ['post']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('Nice post about stuff.');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns meta_description on post when used within {{#foreach posts}}', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{meta_description: 'Nice post about stuff.'},
|
|
|
|
{data: {root: {context: ['home']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('Nice post about stuff.');
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
2019-07-25 12:08:29 +03:00
|
|
|
describe('with meta_description', function () {
|
|
|
|
before(function () {
|
|
|
|
localSettingsCache.meta_description = 'Meta description of the professional publishing platform';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns correct site description', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{},
|
|
|
|
{data: {root: {context: ['home', 'index']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('Meta description of the professional publishing platform');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns tag meta_description if present for a tag page', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
const rendered = helpers.meta_description.call(
|
2019-07-25 12:08:29 +03:00
|
|
|
{tag: {name: 'Rasper Red', meta_description: 'Rasper is the Cool Red Casper'}},
|
|
|
|
{data: {root: {context: ['tag']}}}
|
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('Rasper is the Cool Red Casper');
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|