243b387063
refs #8126, #8221, #8223 ✨ New 'Proxy' for all helper requires - this is not currently enforced, but could be, much like apps - the proxy object is HUGE - changed date to use SafeString, this should have been there anyway - use the proxy for all helpers, including those in apps 😁 ✨ 🎨 Single instance of hbs for theme + for errors - we now have theme/engine instead of requiring express-hbs everywhere - only error-handler still also requires express-hbs, this is so that we can render errors without extra crud - TODO: remove the asset helper after #8126 IF it is not needed, or else remove the TODO 🎨 Cleanup visibility utils 🎨 Clean up the proxy a little bit 🚨 Unskip test as it now works! 🎨 Minor amends as per comments
102 lines
3.6 KiB
JavaScript
102 lines
3.6 KiB
JavaScript
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'),
|
|
engine = require('../../../server/themes/engine'),
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('Themes', function () {
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
describe('Active', function () {
|
|
describe('Mount', function () {
|
|
var engineStub, configStub,
|
|
fakeBlogApp, fakeLoadedTheme, fakeCheckedTheme;
|
|
|
|
beforeEach(function () {
|
|
engineStub = sandbox.stub(engine, 'configure');
|
|
configStub = sandbox.stub(config, 'set');
|
|
|
|
fakeBlogApp = {
|
|
cache: ['stuff'],
|
|
set: sandbox.stub(),
|
|
engine: sandbox.stub()
|
|
};
|
|
|
|
fakeLoadedTheme = {
|
|
name: 'casper',
|
|
path: 'my/fake/theme/path'
|
|
};
|
|
fakeCheckedTheme = {};
|
|
});
|
|
|
|
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();
|
|
|
|
// Check handlebars was configured correctly
|
|
engineStub.calledOnce.should.be.true();
|
|
engineStub.calledWith('my/fake/theme/path/partials').should.be.true();
|
|
|
|
// 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();
|
|
|
|
// Check handlebars was configured correctly
|
|
engineStub.calledOnce.should.be.true();
|
|
engineStub.calledWith().should.be.true();
|
|
|
|
// Check the theme is now mounted
|
|
activeTheme.get().mounted.should.be.true();
|
|
});
|
|
});
|
|
});
|
|
});
|