2018-06-02 22:48:23 +03:00
|
|
|
var should = require('should'),
|
2017-03-21 11:24:11 +03:00
|
|
|
sinon = require('sinon'),
|
|
|
|
configUtils = require('../../utils/configUtils'),
|
|
|
|
helpers = require('../../../server/helpers'),
|
2019-01-21 19:53:44 +03:00
|
|
|
settingsCache = require('../../../server/services/settings/cache');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
describe('{{asset}} helper', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
var rendered, localSettingsCache = {};
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
before(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.set({assetHash: 'abc'});
|
2017-04-10 12:30:21 +03:00
|
|
|
configUtils.set({useMinFiles: true});
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key) {
|
2017-02-03 16:15:11 +03:00
|
|
|
return localSettingsCache[key];
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2015-12-14 23:05:11 +03:00
|
|
|
configUtils.restore();
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('no subdirectory', function () {
|
|
|
|
it('handles favicon correctly', function () {
|
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/favicon.ico');
|
|
|
|
});
|
|
|
|
|
2017-04-04 12:06:38 +03:00
|
|
|
it('handles ghost.css for default templates correctly', function () {
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/ghost.css');
|
2017-04-04 12:06:38 +03:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/public/ghost.css?v=abc');
|
2017-04-04 12:06:38 +03:00
|
|
|
});
|
|
|
|
|
2017-01-26 21:01:19 +03:00
|
|
|
it('handles custom favicon correctly', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.png';
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with png
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.png');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/favicon.png');
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.ico';
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with ico
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/favicon.ico');
|
2017-01-26 21:01:19 +03:00
|
|
|
});
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
it('handles public assets correctly', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '';
|
|
|
|
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/asset.js');
|
2014-10-10 18:54:07 +04:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/public/asset.js?v=abc');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles theme assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/assets/js/asset.js?v=abc');
|
|
|
|
});
|
2017-04-10 12:30:21 +03:00
|
|
|
|
|
|
|
it('handles hasMinFile assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js', {hash: {hasMinFile: true}});
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/assets/js/asset.min.js?v=abc');
|
|
|
|
});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('with /blog subdirectory', function () {
|
|
|
|
before(function () {
|
2017-04-03 18:29:36 +03:00
|
|
|
configUtils.set({url: 'http://localhost:82832/blog'});
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles favicon correctly', function () {
|
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/blog/favicon.ico');
|
|
|
|
});
|
|
|
|
|
2017-04-04 12:06:38 +03:00
|
|
|
it('handles ghost.css for default templates correctly', function () {
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/ghost.css');
|
2017-04-04 12:06:38 +03:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/blog/public/ghost.css?v=abc');
|
2017-04-04 12:06:38 +03:00
|
|
|
});
|
|
|
|
|
2017-01-26 21:01:19 +03:00
|
|
|
it('handles custom favicon correctly', function () {
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.png';
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with png
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.png');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/blog/favicon.png');
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-02-03 16:15:11 +03:00
|
|
|
localSettingsCache.icon = '/content/images/favicon.ico';
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
// with ico
|
2017-01-26 21:01:19 +03:00
|
|
|
rendered = helpers.asset('favicon.ico');
|
|
|
|
should.exist(rendered);
|
2017-04-10 14:04:46 +03:00
|
|
|
String(rendered).should.equal('/blog/favicon.ico');
|
2017-01-26 21:01:19 +03:00
|
|
|
});
|
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
it('handles public assets correctly', function () {
|
2017-04-07 15:21:41 +03:00
|
|
|
rendered = helpers.asset('public/asset.js');
|
2014-10-10 18:54:07 +04:00
|
|
|
should.exist(rendered);
|
2017-04-07 15:21:41 +03:00
|
|
|
String(rendered).should.equal('/blog/public/asset.js?v=abc');
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles theme assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js');
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/blog/assets/js/asset.js?v=abc');
|
|
|
|
});
|
2017-01-26 21:01:19 +03:00
|
|
|
|
2017-04-10 12:30:21 +03:00
|
|
|
it('handles hasMinFile assets correctly', function () {
|
|
|
|
rendered = helpers.asset('js/asset.js', {hash: {hasMinFile: true}});
|
|
|
|
should.exist(rendered);
|
|
|
|
String(rendered).should.equal('/blog/assets/js/asset.min.js?v=abc');
|
|
|
|
});
|
|
|
|
|
2017-01-26 21:01:19 +03:00
|
|
|
configUtils.restore();
|
2014-10-10 18:54:07 +04:00
|
|
|
});
|
|
|
|
});
|