Skip to content
Permalink
Browse files

Adds tests for absoluteURLs template lambda

  • Loading branch information...
davidmerfield committed Aug 29, 2019
1 parent 8c564d9 commit dca4aebe57e27ccdefe5aee51d5137aae8006bd3
Showing with 54 additions and 0 deletions.
  1. +54 −0 app/blog/render/retrieve/tests/absoluteURLs.js
@@ -0,0 +1,54 @@
describe("absoluteURLs", function() {
var absoluteURLs = require("../absoluteURLs");
var mustache = require("mustache");

global.test.blog();

beforeEach(function() {
this.request = {
protocol: "http",
get: function() {
return "example.com";
}
};
});

it("replaces relative links with absolute URLs", function(done) {
var result;
var locals = {};
var html = '<a href="/foo"></a>';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual('<a href="http://example.com/foo"></a>');
done();
});
});

it("replaces relative image sources with absolute sources", function(done) {
var result;
var locals = {};
var html = '<img src="/bar.jpg">';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual('<img src="http://example.com/bar.jpg">');
done();
});
});

it("leaves fully qualified links and images as-is", function(done) {
var result;
var locals = {};
var html = '<a href="http://example.com/foo"><img src="http://example.com/bar.jpg"></a>';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
result = mustache.render(template, { absoluteURLs: lambda });
expect(result).toEqual(html);
done();
});
});
});

0 comments on commit dca4aeb

Please sign in to comment.
You can’t perform that action at this time.