2018-06-02 22:48:23 +03:00
|
|
|
var should = require('should'),
|
2020-03-30 18:26:47 +03:00
|
|
|
themeList = require('../../../core/frontend/services/themes/list'),
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
// Stuff we are testing
|
2020-03-30 18:26:47 +03:00
|
|
|
helpers = require('../../../core/frontend/helpers');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{body_class}} helper', function () {
|
2015-11-24 18:12:50 +03:00
|
|
|
var options = {};
|
2014-10-10 18:54:07 +04:00
|
|
|
before(function () {
|
2017-03-02 19:53:48 +03:00
|
|
|
themeList.init({
|
|
|
|
casper: {
|
|
|
|
assets: null,
|
|
|
|
'default.hbs': '/content/themes/casper/default.hbs',
|
|
|
|
'index.hbs': '/content/themes/casper/index.hbs',
|
|
|
|
'page.hbs': '/content/themes/casper/page.hbs',
|
|
|
|
'page-about.hbs': '/content/themes/casper/page-about.hbs',
|
|
|
|
'post.hbs': '/content/themes/casper/post.hbs'
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
2017-03-02 19:53:48 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
2015-11-24 18:12:50 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
options = {
|
|
|
|
data: {
|
|
|
|
root: {
|
|
|
|
context: [],
|
2017-04-24 20:41:00 +03:00
|
|
|
settings: {active_theme: 'casper'}
|
2015-11-24 18:12:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
after(function () {
|
2017-03-02 19:53:48 +03:00
|
|
|
themeList.init();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('can render class string', function () {
|
2015-11-24 18:12:50 +03:00
|
|
|
options.data.root.context = ['home'];
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
var rendered = helpers.body_class.call({}, options);
|
|
|
|
should.exist(rendered);
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
rendered.string.should.equal('home-template');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
2015-11-24 18:12:50 +03:00
|
|
|
describe('can render class string for context', function () {
|
|
|
|
function callBodyClassWithContext(context, self) {
|
|
|
|
options.data.root.context = context;
|
|
|
|
return helpers.body_class.call(
|
|
|
|
self,
|
|
|
|
options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('Standard home page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['home', 'index'],
|
|
|
|
{relativeUrl: '/'}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('home-template');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('a post', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['post'],
|
|
|
|
{relativeUrl: '/a-post-title', post: {}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('post-template');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('paginated index', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['index', 'paged'],
|
|
|
|
{relativeUrl: '/page/4'}
|
|
|
|
);
|
|
|
|
|
2016-10-10 12:38:12 +03:00
|
|
|
rendered.string.should.equal('paged');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('tag page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['tag'],
|
|
|
|
{relativeUrl: '/tag/foo', tag: {slug: 'foo'}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('tag-template tag-foo');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('paginated tag page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['tag', 'paged'],
|
|
|
|
{relativeUrl: '/tag/foo/page/2', tag: {slug: 'foo'}}
|
|
|
|
);
|
|
|
|
|
2016-10-10 12:38:12 +03:00
|
|
|
rendered.string.should.equal('tag-template tag-foo paged');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('author page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['author'],
|
|
|
|
{relativeUrl: '/author/bar', author: {slug: 'bar'}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('author-template author-bar');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('paginated author page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['author', 'paged'],
|
|
|
|
{relativeUrl: '/author/bar/page/2', author: {slug: 'bar'}}
|
|
|
|
);
|
|
|
|
|
2016-10-10 12:38:12 +03:00
|
|
|
rendered.string.should.equal('author-template author-bar paged');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('private route for password protection', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['private'],
|
|
|
|
{relativeUrl: '/private/'}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('private-template');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
|
|
|
|
2015-12-08 17:35:04 +03:00
|
|
|
it('post with tags', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['post'],
|
|
|
|
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('post-template tag-foo tag-bar');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
|
|
|
|
2019-03-12 03:18:07 +03:00
|
|
|
it('v2: a static page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['page'],
|
|
|
|
{relativeUrl: '/about', page: {page: true, slug: 'about'}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('page-template page-about');
|
|
|
|
});
|
|
|
|
|
2019-08-09 17:25:12 +03:00
|
|
|
it('canary: a static page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['page'],
|
|
|
|
{relativeUrl: '/about', page: {page: true, slug: 'about'}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('page-template page-about');
|
|
|
|
});
|
|
|
|
|
2019-09-03 10:03:31 +03:00
|
|
|
it('v3: a static page', function () {
|
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['page'],
|
|
|
|
{relativeUrl: '/about', page: {page: true, slug: 'about'}}
|
|
|
|
);
|
|
|
|
|
|
|
|
rendered.string.should.equal('page-template page-about');
|
|
|
|
});
|
|
|
|
|
2016-10-10 12:38:12 +03:00
|
|
|
it('a static page with custom template (is now the same as one without)', function () {
|
2015-12-08 17:35:04 +03:00
|
|
|
var rendered = callBodyClassWithContext(
|
|
|
|
['page'],
|
|
|
|
{relativeUrl: '/about', post: {page: true, slug: 'about'}}
|
|
|
|
);
|
|
|
|
|
2016-10-10 12:38:12 +03:00
|
|
|
rendered.string.should.equal('page-template page-about');
|
2015-11-24 18:12:50 +03:00
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|