2014-10-10 16:54:07 +02:00
|
|
|
/*globals describe, before, beforeEach, afterEach, after, it*/
|
|
|
|
/*jshint expr:true*/
|
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
|
|
|
Promise = require('bluebird'),
|
|
|
|
hbs = require('express-hbs'),
|
|
|
|
utils = require('./utils'),
|
|
|
|
|
|
|
|
// Stuff we are testing
|
|
|
|
handlebars = hbs.handlebars,
|
|
|
|
helpers = require('../../../server/helpers'),
|
|
|
|
api = require('../../../server/api');
|
|
|
|
|
|
|
|
describe('{{url}} helper', function () {
|
|
|
|
var sandbox;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
utils.overrideConfig({url: 'http://testurl.com/'});
|
|
|
|
utils.loadHelpers();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox.stub(api.settings, 'read', function () {
|
|
|
|
return Promise.resolve({settings: [{value: '/:slug/'}]});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
utils.restoreConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has loaded url helper', function () {
|
|
|
|
should.exist(handlebars.helpers.url);
|
|
|
|
});
|
|
|
|
|
2014-12-28 20:38:29 +01:00
|
|
|
it('should return the slug with a prefix slash if the context is a post', function () {
|
|
|
|
var rendered = helpers.url.call({
|
2014-10-10 16:54:07 +02:00
|
|
|
html: 'content',
|
|
|
|
markdown: 'ff',
|
|
|
|
title: 'title',
|
|
|
|
slug: 'slug',
|
2014-12-10 15:03:39 +01:00
|
|
|
created_at: new Date(0),
|
|
|
|
url: '/slug/'
|
2014-12-28 20:38:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/slug/');
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
2014-12-28 20:38:29 +01:00
|
|
|
it('should output an absolute URL if the option is present', function () {
|
|
|
|
var rendered = helpers.url.call(
|
2014-12-10 15:03:39 +01:00
|
|
|
{html: 'content', markdown: 'ff', title: 'title', slug: 'slug', url: '/slug/', created_at: new Date(0)},
|
2014-10-10 16:54:07 +02:00
|
|
|
{hash: {absolute: 'true'}}
|
2014-12-28 20:38:29 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('http://testurl.com/slug/');
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
2014-12-28 20:38:29 +01:00
|
|
|
it('should return the slug with a prefixed /tag/ if the context is a tag', function () {
|
|
|
|
var rendered = helpers.url.call({
|
2014-10-10 16:54:07 +02:00
|
|
|
name: 'the tag',
|
|
|
|
slug: 'the-tag',
|
|
|
|
description: null,
|
|
|
|
parent: null
|
2014-12-28 20:38:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/tag/the-tag/');
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
|
2014-12-28 20:38:29 +01:00
|
|
|
it('should return / if not a post or tag', function () {
|
|
|
|
var rendered;
|
|
|
|
|
|
|
|
rendered = helpers.url.call({markdown: 'ff', title: 'title', slug: 'slug'});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/');
|
|
|
|
|
|
|
|
rendered = helpers.url.call({html: 'content', title: 'title', slug: 'slug'});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/');
|
|
|
|
|
|
|
|
rendered = helpers.url.call({html: 'content', markdown: 'ff', slug: 'slug'});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/');
|
|
|
|
|
|
|
|
rendered = helpers.url.call({html: 'content', markdown: 'ff', title: 'title'});
|
|
|
|
should.exist(rendered);
|
|
|
|
rendered.should.equal('/');
|
2014-10-10 16:54:07 +02:00
|
|
|
});
|
|
|
|
});
|