mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +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!
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
const should = require('should');
|
|
const sinon = require('sinon');
|
|
const testUtils = require('../../utils');
|
|
const urlService = require('../../../core/frontend/services/url');
|
|
const helpers = require('../../../core/frontend/helpers');
|
|
|
|
describe('{{author}} helper', function () {
|
|
beforeEach(function () {
|
|
sinon.stub(urlService, 'getUrlByResourceId');
|
|
});
|
|
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
it('Returns the link to the author from the context', function () {
|
|
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
|
|
|
|
urlService.getUrlByResourceId.withArgs(author.id).returns('author url');
|
|
|
|
const result = helpers.author.call({author: author}, {hash: {}});
|
|
String(result).should.equal('<a href="author url">abc 123</a>');
|
|
});
|
|
|
|
it('Returns the full name of the author from the context if no autolink', function () {
|
|
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
|
|
const result = helpers.author.call({author: author}, {hash: {autolink: 'false'}});
|
|
String(result).should.equal('abc 123');
|
|
urlService.getUrlByResourceId.called.should.be.false();
|
|
});
|
|
|
|
it('Returns a blank string where author data is missing', function () {
|
|
const result = helpers.author.call({author: null}, {hash: {}});
|
|
String(result).should.equal('');
|
|
});
|
|
|
|
it('Functions as block helper if called with #', function () {
|
|
const author = testUtils.DataGenerator.forKnex.createUser({slug: 'abc123', name: 'abc 123'});
|
|
|
|
// including fn emulates the #
|
|
const result = helpers.author.call({author: author}, {
|
|
hash: {}, fn: function () {
|
|
return 'FN';
|
|
}
|
|
});
|
|
|
|
// It outputs the result of fn
|
|
String(result).should.equal('FN');
|
|
urlService.getUrlByResourceId.called.should.be.false();
|
|
});
|
|
});
|