@lonelyplanet/dotcom-core
Version:
This package is meant to house some of our more common UI and shared libs across dotcom applications.
91 lines (90 loc) • 5.11 kB
JavaScript
import imgix from "../../helpers/imgix";
describe("imgix", function () {
describe("booking.com", function () {
it("should replace aff.bstatic.com", function () {
var result = imgix("https://aff.bstatic.com/images/hotel/max500/177/1778356.jpg", {}, "bdc");
expect(result).toEqual("https://lpbookingcom.imgix.net/images/hotel/max500/177/1778356.jpg");
});
it("should replace q-xx.bstatic.com", function () {
var result = imgix("https://q-xx.bstatic.com/images/hotel/max500/177/1778356.jpg", {}, "bdc");
expect(result).toEqual("https://lpbookingcom.imgix.net/images/hotel/max500/177/1778356.jpg");
});
});
describe("gadventures", function () {
it("should replace media.gadventures.com", function () {
var result = imgix("https://media.gadventures.com/media-server/cache/e2/7a/e27ad55d69b8cea10baac7f50e526a16.jpg", {}, "gadventures");
expect(result).toEqual("https://lpgadventures.imgix.net/media-server/cache/e2/7a/e27ad55d69b8cea10baac7f50e526a16.jpg");
});
});
describe("hostelworld", function () {
it("should replace ucd.hwstatic.com", function () {
var result = imgix("https://ucd.hwstatic.com/propertyimages/7/76525/1.jpg", {}, "hostelworld");
expect(result).toEqual("https://lphostelworld.imgix.net/propertyimages/7/76525/1.jpg");
});
});
describe("media", function () {
it("should replace media.lonelyplanet.com", function () {
var result = imgix("https://media.lonelyplanet.com/foo.jpg", {}, "media");
expect(result).toEqual("https://lonelyplanetimages.imgix.net/foo.jpg");
});
});
describe("news", function () {
it("should replace lonelyplanet.com/news/wp-content/uploads", function () {
var result = imgix("https://www.lonelyplanet.com/news/wp-content/uploads/foo.jpg", {}, "news");
expect(result).toEqual("https://lonelyplanetwpnews.imgix.net/foo.jpg");
});
});
describe("staticAsset", function () {
it("should replace s3.amazonaws.com/static-asset", function () {
var result = imgix("https://s3.amazonaws.com/static-asset/op-video-sync/images/production/foo.jpg", {}, "staticAsset");
expect(result).toEqual("https://lonelyplanetstatic.imgix.net/op-video-sync/images/production/foo.jpg");
});
});
describe("staticSites", function () {
it("should replace s3.amazonaws.com/lp-static-sites", function () {
var result = imgix("https://s3.amazonaws.com/lp-static-sites/trinity-college-dublin/assets/images/foo.jpg", {}, "staticSites");
expect(result).toEqual("http://lonelyplanetstaticsites.imgix.net/trinity-college-dublin/assets/images/foo.jpg");
});
});
describe("viator", function () {
it("should replace cache-graphicslib.viator.com", function () {
var result = imgix("https://cache-graphicslib.viator.com/graphicslib/thumbs674x446/26200/SITours/nashville-food-and-sightseeing-tour-in-nashville-309998.jpg", {}, "viator");
expect(result).toEqual("https://lpviator.imgix.net/graphicslib/thumbs674x446/26200/SITours/nashville-food-and-sightseeing-tour-in-nashville-309998.jpg");
});
});
describe("wordpress", function () {
it("should replace lonelyplanet.com/travel-blog/tip-article/wordpress_uploads", function () {
var result = imgix("https://www.lonelyplanet.com/travel-blog/tip-article/wordpress_uploads/foo.jpg", {}, "wordpress");
expect(result).toEqual("https://lonelyplanetwp.imgix.net/foo.jpg");
});
});
describe("with parameters", function () {
it("should add params to the url", function () {
var result = imgix("http://media.lonelyplanet.com/foo.jpg", {
w: 1024,
h: 768,
}, "media");
expect(result).toEqual("https://lonelyplanetimages.imgix.net/foo.jpg?w=1024&h=768");
});
});
describe("non-matching url", function () {
it("should return the original url", function () {
var result = imgix("http://www.anotherurl.com/foo.jpg");
expect(result).toEqual("http://www.anotherurl.com/foo.jpg");
});
});
describe("without source", function () {
it("should handle an undefined source", function () {
var result = imgix("https://media.lonelyplanet.com/foo.jpg", {});
expect(result).toEqual("https://lonelyplanetimages.imgix.net/foo.jpg");
});
it("should handle a null string source", function () {
var result = imgix("https://media.lonelyplanet.com/foo.jpg", {}, null);
expect(result).toEqual("https://lonelyplanetimages.imgix.net/foo.jpg");
});
it("should handle a mismatched source key", function () {
var result = imgix("https://media.lonelyplanet.com/foo.jpg", {}, "notakey");
expect(result).toEqual("https://media.lonelyplanet.com/foo.jpg");
});
});
});