2017-03-22 06:52:58 +00:00
|
|
|
var should = require('should'), // jshint ignore:line
|
|
|
|
sinon = require('sinon'),
|
|
|
|
|
|
|
|
config = require('../../../server/config'),
|
|
|
|
// is only exposed via themes.getActive()
|
|
|
|
activeTheme = require('../../../server/themes/active'),
|
2017-04-04 17:07:35 +01:00
|
|
|
engine = require('../../../server/themes/engine'),
|
2017-03-22 06:52:58 +00:00
|
|
|
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
describe('Themes', function () {
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Active', function () {
|
|
|
|
describe('Mount', function () {
|
2017-04-04 17:07:35 +01:00
|
|
|
var engineStub, configStub,
|
2017-03-22 06:52:58 +00:00
|
|
|
fakeBlogApp, fakeLoadedTheme, fakeCheckedTheme;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2017-04-04 17:07:35 +01:00
|
|
|
engineStub = sandbox.stub(engine, 'configure');
|
2017-03-22 06:52:58 +00:00
|
|
|
configStub = sandbox.stub(config, 'set');
|
|
|
|
|
|
|
|
fakeBlogApp = {
|
|
|
|
cache: ['stuff'],
|
|
|
|
set: sandbox.stub(),
|
|
|
|
engine: sandbox.stub()
|
|
|
|
};
|
|
|
|
|
|
|
|
fakeLoadedTheme = {
|
|
|
|
name: 'casper',
|
|
|
|
path: 'my/fake/theme/path'
|
|
|
|
};
|
2017-10-10 14:36:35 +02:00
|
|
|
fakeCheckedTheme = {
|
|
|
|
templates: {
|
|
|
|
all: ['post', 'about', 'post-hey', 'custom-test'],
|
|
|
|
custom: ['custom-test', 'post-hey']
|
|
|
|
}
|
|
|
|
};
|
2017-03-22 06:52:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should mount active theme with partials', function () {
|
|
|
|
// setup partials
|
|
|
|
fakeCheckedTheme.partials = ['loop', 'navigation'];
|
|
|
|
|
|
|
|
var theme = activeTheme.set(fakeLoadedTheme, fakeCheckedTheme);
|
|
|
|
|
|
|
|
// Check the theme is not yet mounted
|
|
|
|
activeTheme.get().mounted.should.be.false();
|
|
|
|
|
|
|
|
// Call mount!
|
|
|
|
theme.mount(fakeBlogApp);
|
|
|
|
|
|
|
|
// Check the asset hash gets reset
|
|
|
|
configStub.calledOnce.should.be.true();
|
|
|
|
configStub.calledWith('assetHash', null).should.be.true();
|
|
|
|
|
|
|
|
// Check te view cache was cleared
|
|
|
|
fakeBlogApp.cache.should.eql({});
|
|
|
|
|
|
|
|
// Check the views were set correctly
|
|
|
|
fakeBlogApp.set.calledOnce.should.be.true();
|
|
|
|
fakeBlogApp.set.calledWith('views', 'my/fake/theme/path').should.be.true();
|
|
|
|
|
2017-04-04 17:07:35 +01:00
|
|
|
// Check handlebars was configured correctly
|
|
|
|
engineStub.calledOnce.should.be.true();
|
|
|
|
engineStub.calledWith('my/fake/theme/path/partials').should.be.true();
|
2017-03-22 06:52:58 +00:00
|
|
|
|
|
|
|
// Check the theme is now mounted
|
|
|
|
activeTheme.get().mounted.should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mount active theme without partials', function () {
|
|
|
|
// setup partials
|
|
|
|
fakeCheckedTheme.partials = [];
|
|
|
|
|
|
|
|
var theme = activeTheme.set(fakeLoadedTheme, fakeCheckedTheme);
|
|
|
|
|
|
|
|
// Check the theme is not yet mounted
|
|
|
|
activeTheme.get().mounted.should.be.false();
|
|
|
|
|
|
|
|
// Call mount!
|
|
|
|
theme.mount(fakeBlogApp);
|
|
|
|
|
|
|
|
// Check the asset hash gets reset
|
|
|
|
configStub.calledOnce.should.be.true();
|
|
|
|
configStub.calledWith('assetHash', null).should.be.true();
|
|
|
|
|
|
|
|
// Check te view cache was cleared
|
|
|
|
fakeBlogApp.cache.should.eql({});
|
|
|
|
|
|
|
|
// Check the views were set correctly
|
|
|
|
fakeBlogApp.set.calledOnce.should.be.true();
|
|
|
|
fakeBlogApp.set.calledWith('views', 'my/fake/theme/path').should.be.true();
|
|
|
|
|
2017-04-04 17:07:35 +01:00
|
|
|
// Check handlebars was configured correctly
|
|
|
|
engineStub.calledOnce.should.be.true();
|
|
|
|
engineStub.calledWith().should.be.true();
|
2017-03-22 06:52:58 +00:00
|
|
|
|
|
|
|
// Check the theme is now mounted
|
|
|
|
activeTheme.get().mounted.should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|