mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
1c7c246616
- Theme preview was not showing the same behaviour as a real theme because nulls were being encoded and decoded incorrectly causing nulls/empty strings to be treasted as truthy values - Swap from using split to using proper query param parsing so that the code is more robust - this still creates empty strings and the string 'null' so added a small function to decode these back to real nulls - moved to its own file ready to be split out - there needs to be a bigger picture plan for this - added unit tests to cover the known issues + some potential breakages from converting the header string to a query param object
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
|
|
const preview = require('../../../../core/frontend/services/themes/preview');
|
|
|
|
describe('Theme Preview', function () {
|
|
let req, previewString = '';
|
|
|
|
before(function () {
|
|
req = {
|
|
header: () => {
|
|
return previewString;
|
|
}
|
|
};
|
|
});
|
|
|
|
it('can handle empty strings', function () {
|
|
previewString = 'logo=';
|
|
|
|
let siteData = preview.handle(req, {});
|
|
|
|
siteData.should.be.an.Object().with.properties('logo');
|
|
should(siteData.logo).be.null();
|
|
});
|
|
|
|
it('can handle nulls', function () {
|
|
previewString = 'cover=null';
|
|
|
|
let siteData = preview.handle(req, {});
|
|
|
|
siteData.should.be.an.Object().with.properties('cover_image');
|
|
should(siteData.cover_image).be.null();
|
|
});
|
|
|
|
it('can handle URIEncoded accent colors', function () {
|
|
previewString = 'c=%23f02d2d';
|
|
|
|
let siteData = preview.handle(req, {});
|
|
|
|
siteData.should.be.an.Object().with.properties('accent_color');
|
|
should(siteData.accent_color).eql('#f02d2d');
|
|
});
|
|
|
|
it('can handle multiple values', function () {
|
|
previewString = 'c=%23f02d2d&icon=&logo=&cover=null';
|
|
|
|
let siteData = preview.handle(req, {});
|
|
siteData.should.be.an.Object().with.properties('accent_color', 'icon', 'logo', 'cover_image');
|
|
|
|
should(siteData.accent_color).eql('#f02d2d');
|
|
should(siteData.icon).be.null();
|
|
should(siteData.logo).be.null();
|
|
should(siteData.cover_image).be.null();
|
|
});
|
|
});
|