2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../../core/shared/config');
|
2017-03-22 09:52:58 +03:00
|
|
|
|
2021-04-23 15:22:45 +03:00
|
|
|
// is only exposed via themeEngine.getActive()
|
|
|
|
const activeTheme = require('../../../../core/frontend/services/theme-engine/active');
|
2021-04-19 17:09:35 +03:00
|
|
|
const engine = require('../../../../core/frontend/services/theme-engine/engine');
|
2017-03-22 09:52:58 +03:00
|
|
|
|
|
|
|
describe('Themes', function () {
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-03-22 09:52:58 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Active', function () {
|
|
|
|
describe('Mount', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
let engineStub;
|
|
|
|
let configStub;
|
2021-05-04 18:49:35 +03:00
|
|
|
let fakeSettings;
|
2020-04-29 18:44:27 +03:00
|
|
|
let fakeBlogApp;
|
|
|
|
let fakeLoadedTheme;
|
|
|
|
let fakeCheckedTheme;
|
2017-03-22 09:52:58 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
engineStub = sinon.stub(engine, 'configure');
|
|
|
|
configStub = sinon.stub(config, 'set');
|
2017-03-22 09:52:58 +03:00
|
|
|
|
2021-05-04 18:49:35 +03:00
|
|
|
fakeSettings = {
|
|
|
|
locale: 'en'
|
|
|
|
};
|
|
|
|
|
2017-03-22 09:52:58 +03:00
|
|
|
fakeBlogApp = {
|
|
|
|
cache: ['stuff'],
|
2019-01-21 19:53:44 +03:00
|
|
|
set: sinon.stub(),
|
|
|
|
engine: sinon.stub()
|
2017-03-22 09:52:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
fakeLoadedTheme = {
|
|
|
|
name: 'casper',
|
|
|
|
path: 'my/fake/theme/path'
|
|
|
|
};
|
2017-10-10 15:36:35 +03:00
|
|
|
fakeCheckedTheme = {
|
|
|
|
templates: {
|
|
|
|
all: ['post', 'about', 'post-hey', 'custom-test'],
|
|
|
|
custom: ['custom-test', 'post-hey']
|
|
|
|
}
|
|
|
|
};
|
2017-03-22 09:52:58 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should mount active theme with partials', function () {
|
|
|
|
// setup partials
|
|
|
|
fakeCheckedTheme.partials = ['loop', 'navigation'];
|
|
|
|
|
2021-05-04 18:49:35 +03:00
|
|
|
const theme = activeTheme.set(fakeSettings, fakeLoadedTheme, fakeCheckedTheme);
|
2017-03-22 09:52:58 +03:00
|
|
|
|
|
|
|
// 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 19:07:35 +03:00
|
|
|
// Check handlebars was configured correctly
|
|
|
|
engineStub.calledOnce.should.be.true();
|
|
|
|
engineStub.calledWith('my/fake/theme/path/partials').should.be.true();
|
2017-03-22 09:52:58 +03: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 = [];
|
|
|
|
|
2021-05-04 18:49:35 +03:00
|
|
|
const theme = activeTheme.set(fakeSettings, fakeLoadedTheme, fakeCheckedTheme);
|
2017-03-22 09:52:58 +03:00
|
|
|
|
|
|
|
// 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 19:07:35 +03:00
|
|
|
// Check handlebars was configured correctly
|
|
|
|
engineStub.calledOnce.should.be.true();
|
|
|
|
engineStub.calledWith().should.be.true();
|
2017-03-22 09:52:58 +03:00
|
|
|
|
|
|
|
// Check the theme is now mounted
|
|
|
|
activeTheme.get().mounted.should.be.true();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|