mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
95d27e7f58
- this is a small part of a bit of cleanup of our test files - the goal is to make the existing tests clearer with a view to making it easier to write more tests - this makes the test structure follow the codebase structure more closely - eventually we will colocate the frontend tests with the frontend code
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 authorHelper = require('../../../../core/frontend/helpers/author');
|
|
|
|
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 = authorHelper.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 = authorHelper.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 = authorHelper.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 = authorHelper.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();
|
|
});
|
|
});
|