mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added tests for body_class
helper to verify custom fonts rendering
This commit is contained in:
parent
18683ef9d0
commit
eae16830ce
1 changed files with 83 additions and 0 deletions
|
@ -1,9 +1,14 @@
|
||||||
const should = require('should');
|
const should = require('should');
|
||||||
const themeList = require('../../../../core/server/services/themes/list');
|
const themeList = require('../../../../core/server/services/themes/list');
|
||||||
|
const sinon = require('sinon');
|
||||||
|
|
||||||
// Stuff we are testing
|
// Stuff we are testing
|
||||||
const body_class = require('../../../../core/frontend/helpers/body_class');
|
const body_class = require('../../../../core/frontend/helpers/body_class');
|
||||||
|
|
||||||
|
// Stubs
|
||||||
|
const proxy = require('../../../../core/frontend/services/proxy');
|
||||||
|
const {settingsCache, labs} = proxy;
|
||||||
|
|
||||||
describe('{{body_class}} helper', function () {
|
describe('{{body_class}} helper', function () {
|
||||||
let options = {};
|
let options = {};
|
||||||
before(function () {
|
before(function () {
|
||||||
|
@ -155,4 +160,82 @@ describe('{{body_class}} helper', function () {
|
||||||
rendered.string.should.equal('page-template page-about');
|
rendered.string.should.equal('page-template page-about');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('custom fonts', function () {
|
||||||
|
let settingsCacheStub;
|
||||||
|
let labsStub;
|
||||||
|
|
||||||
|
function callBodyClassWithContext(context, self) {
|
||||||
|
options.data.root.context = context;
|
||||||
|
return body_class.call(
|
||||||
|
self,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
labsStub = sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||||
|
settingsCacheStub = sinon.stub(settingsCache, 'get');
|
||||||
|
options = {
|
||||||
|
data: {
|
||||||
|
root: {
|
||||||
|
context: [],
|
||||||
|
settings: {active_theme: 'casper'}
|
||||||
|
},
|
||||||
|
site: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes custom font for post when set in options data object', function () {
|
||||||
|
options.data.site.heading_font = 'Space Grotesk';
|
||||||
|
options.data.site.body_font = 'Noto Sans';
|
||||||
|
|
||||||
|
const rendered = callBodyClassWithContext(
|
||||||
|
['post'],
|
||||||
|
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
||||||
|
);
|
||||||
|
|
||||||
|
rendered.string.should.equal('post-template tag-foo tag-bar gh-font-heading-space-grotesk gh-font-body-noto-sans');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes custom font for post when set in settings cache', function () {
|
||||||
|
settingsCacheStub.withArgs('heading_font').returns('Space Grotesk');
|
||||||
|
settingsCacheStub.withArgs('body_font').returns('Noto Sans');
|
||||||
|
|
||||||
|
const rendered = callBodyClassWithContext(
|
||||||
|
['post'],
|
||||||
|
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
||||||
|
);
|
||||||
|
|
||||||
|
rendered.string.should.equal('post-template tag-foo tag-bar gh-font-heading-space-grotesk gh-font-body-noto-sans');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not include custom font classes when custom fonts are not enabled', function () {
|
||||||
|
labsStub.withArgs('customFonts').returns(false);
|
||||||
|
|
||||||
|
const rendered = callBodyClassWithContext(
|
||||||
|
['post'],
|
||||||
|
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
||||||
|
);
|
||||||
|
|
||||||
|
rendered.string.should.equal('post-template tag-foo tag-bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes custom font classes for home page when set in options data object', function () {
|
||||||
|
options.data.site.heading_font = 'Space Grotesk';
|
||||||
|
options.data.site.body_font = '';
|
||||||
|
|
||||||
|
const rendered = callBodyClassWithContext(
|
||||||
|
['home'],
|
||||||
|
{relativeUrl: '/'}
|
||||||
|
);
|
||||||
|
|
||||||
|
rendered.string.should.equal('home-template gh-font-heading-space-grotesk');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue