UNPKG

opds-web-client

Version:
114 lines (113 loc) 4.56 kB
"use strict"; jest.autoMockOff(); var React = require("react"); var enzyme_1 = require("enzyme"); var Breadcrumbs_1 = require("../Breadcrumbs"); var CatalogLink_1 = require("../CatalogLink"); describe("Breadcrumbs", function () { var data; beforeEach(function () { data = [{ id: "2nd id", text: "2nd title", url: "2nd url" }, { id: "last id", text: "last title", url: "last url" }]; }); it("shows links with bootstrap classes", function () { var wrapper = enzyme_1.shallow(React.createElement(Breadcrumbs_1.default, {links: data})); var list = wrapper.find("ol"); var links = wrapper.find(CatalogLink_1.default); expect(list.hasClass("breadcrumb")).toBe(true); expect(links.length).toBe(2); expect(links.at(0).props().children).toContain("2nd title"); expect(links.at(0).props().collectionUrl).toEqual("2nd url"); // last link is wrapped in <strong> expect(links.at(1).props().children.props.children).toContain("last title"); expect(links.at(1).props().collectionUrl).toEqual("last url"); }); }); describe("hierarchyComputeBreadcrumbs", function () { var collection = { id: "new id", url: "new url", title: "new title", lanes: [], books: [], links: [] }; var collectionLink = { url: "new url", text: "new title" }; var history = []; it("returns only collection link without root or parent", function () { expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(collection, history)).toEqual([collectionLink]); }); it("returns root and collection if parent not present", function () { var catalogRootLink = { url: "new root url", text: "new root url" }; var data = Object.assign({}, collection, { catalogRootLink: catalogRootLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([catalogRootLink, collectionLink]); }); it("provides default catalog root title", function () { var catalogRootLink = { url: "new root url", text: null }; var data = Object.assign({}, collection, { catalogRootLink: catalogRootLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([{ url: catalogRootLink.url, text: "Catalog" }, collectionLink]); }); it("returns only parent and collection if root not present", function () { var parentLink = { url: "new parent url", text: "new parent text" }; var data = Object.assign({}, collection, { parentLink: parentLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([parentLink, collectionLink]); }); it("returns only root and collection if parent is same as root", function () { var catalogRootLink = { url: "new root url", text: "new root text" }; var parentLink = { url: "new root url", text: "new root text" }; var data = Object.assign({}, collection, { catalogRootLink: catalogRootLink, parentLink: parentLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([catalogRootLink, collectionLink]); }); it("return only parent and collection if collection is same as root", function () { var catalogRootLink = { url: "new url", text: "new title" }; var parentLink = { url: "new parent url", text: "new parent text" }; var data = Object.assign({}, collection, { catalogRootLink: catalogRootLink, parentLink: parentLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([parentLink, collectionLink]); }); it("return only root and parent if collection is same as parent", function () { var catalogRootLink = { url: "new root url", text: "new root text" }; var parentLink = { url: "new url", text: "new title" }; var data = Object.assign({}, collection, { catalogRootLink: catalogRootLink, parentLink: parentLink }); expect(Breadcrumbs_1.hierarchyComputeBreadcrumbs(data, history)).toEqual([catalogRootLink, parentLink]); }); });