0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/test/unit/helpers/author.test.js
Hannah Wolfe f08a55c21f
Renamed tests to .test.js & updated commands
refs: https://github.com/TryGhost/Team/issues/856
refs: https://github.com/TryGhost/Team/issues/756

- The .test.js extension is better than _spec.js as it's more obvious that it's an extension
- It also meaans we can use the --extension parameter in mocha, which should result in a better default behaviour for `yarn test`
- It also highlights that some of our tests were named incorrectly and were not (and still will not be) run (see https://github.com/TryGhost/Team/issues/856)
- Note: even with this change, `yarn test` is throwing errors, I believe because of this issue https://github.com/TryGhost/Team/issues/756
2021-07-06 20:45:01 +01:00

51 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();
});
});