mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
22e13acd65
- All var declarations are now const or let as per ES6 - All comma-separated lists / chained declarations are now one declaration per line - This is for clarity/readability but also made running the var-to-const/let switch smoother - ESLint rules updated to match How this was done: - npm install -g jscodeshift - git clone https://github.com/cpojer/js-codemod.git - git clone git@github.com:TryGhost/Ghost.git shallow-ghost - cd shallow-ghost - jscodeshift -t ../js-codemod/transforms/unchain-variables.js . -v=2 - jscodeshift -t ../js-codemod/transforms/no-vars.js . -v=2 - yarn - yarn test - yarn lint / fix various lint errors (almost all indent) by opening files and saving in vscode - grunt test-regression - sorted!
109 lines
3.8 KiB
JavaScript
109 lines
3.8 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const config = require('../../../../core/server/config');
|
|
|
|
// is only exposed via themes.getActive()
|
|
const activeTheme = require('../../../../core/frontend/services/themes/active');
|
|
|
|
const engine = require('../../../../core/frontend/services/themes/engine');
|
|
|
|
describe('Themes', function () {
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
describe('Active', function () {
|
|
describe('Mount', function () {
|
|
let engineStub;
|
|
let configStub;
|
|
let fakeBlogApp;
|
|
let fakeLoadedTheme;
|
|
let fakeCheckedTheme;
|
|
|
|
beforeEach(function () {
|
|
engineStub = sinon.stub(engine, 'configure');
|
|
configStub = sinon.stub(config, 'set');
|
|
|
|
fakeBlogApp = {
|
|
cache: ['stuff'],
|
|
set: sinon.stub(),
|
|
engine: sinon.stub()
|
|
};
|
|
|
|
fakeLoadedTheme = {
|
|
name: 'casper',
|
|
path: 'my/fake/theme/path'
|
|
};
|
|
fakeCheckedTheme = {
|
|
templates: {
|
|
all: ['post', 'about', 'post-hey', 'custom-test'],
|
|
custom: ['custom-test', 'post-hey']
|
|
}
|
|
};
|
|
});
|
|
|
|
it('should mount active theme with partials', function () {
|
|
// setup partials
|
|
fakeCheckedTheme.partials = ['loop', 'navigation'];
|
|
|
|
const 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 = [];
|
|
|
|
const 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();
|
|
});
|
|
});
|
|
});
|
|
});
|