opds-web-client
Version:
54 lines (53 loc) • 3.17 kB
JavaScript
var chai_1 = require("chai");
var React = require("react");
var enzyme_1 = require("enzyme");
var Book_1 = require("../Book");
var CatalogLink_1 = require("../CatalogLink");
var BookCover_1 = require("../BookCover");
var book = {
id: "urn:librarysimplified.org/terms/id/3M%20ID/crrmnr9",
title: "The Mayan Secrets",
authors: ["Clive Cussler", "Thomas Perry"],
summary: "<b>Sam and Remi Fargo race for treasure—and survival—in this lightning-paced new adventure from #1<i> New York Times</i> bestselling author Clive Cussler.</b><br /><br />Husband-and-wife team Sam and Remi Fargo are in Mexico when they come upon a remarkable discovery—the mummified remainsof a man clutching an ancient sealed pot. Within the pot is a Mayan book larger than any known before.<br /><br />The book contains astonishing information about the Mayans, their cities, and about mankind itself. The secrets are so powerful that some people would do anything to possess them—as the Fargos are about to find out. Many men and women are going to die for that book.",
imageUrl: "https://dlotdqc6pnwqb.cloudfront.net/3M/crrmnr9/cover.jpg",
openAccessLinks: [{ url: "secrets.epub", type: "application/epub+zip" }],
publisher: "Penguin Publishing Group",
language: "en"
};
describe("Book", function () {
it("shows the book cover", function () {
var wrapper = enzyme_1.shallow(React.createElement(Book_1.default, { book: book }));
var links = wrapper.find(CatalogLink_1.default);
chai_1.expect(links.length).to.equal(1);
var cover = links.at(0).children().at(0);
chai_1.expect(cover.type()).to.equal(BookCover_1.default);
chai_1.expect(cover.props().book).to.equal(book);
});
it("shows book info", function () {
var wrapper = enzyme_1.shallow(React.createElement(Book_1.default, { book: book }));
var links = wrapper.find(CatalogLink_1.default);
chai_1.expect(links.length).to.equal(1);
var bookInfo = links.at(0).children().at(1);
var title = bookInfo.find(".title");
var authors = bookInfo.find(".authors");
chai_1.expect(title.text()).to.equal(book.title);
chai_1.expect(authors.text()).to.equal(book.authors.join(", "));
});
it("shows contributors when there's no author", function () {
var bookCopy = Object.assign({}, book, {
authors: [],
contributors: ["contributor"]
});
var wrapper = enzyme_1.shallow(React.createElement(Book_1.default, { book: bookCopy }));
var links = wrapper.find(CatalogLink_1.default);
var bookInfo = links.at(0).children().at(1);
var authors = bookInfo.find(".authors");
chai_1.expect(authors.text()).to.equal(bookCopy.contributors[0]);
});
it("has language attribute matching the book's language", function () {
var wrapper = enzyme_1.shallow(React.createElement(Book_1.default, { book: book }));
var bookElement = wrapper.find(".book");
chai_1.expect(bookElement.props().lang).to.equal("en");
});
});
;