opds-web-client
Version:
59 lines (58 loc) • 2.53 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var React = require("react");
var enzyme_1 = require("enzyme");
var BookCover_1 = require("../BookCover");
describe("BookCover", function () {
describe("with no image url", function () {
var wrapper;
var bookData = {
id: "test id",
title: "test book",
authors: ["paperback writer", "brilliant recluse"]
};
beforeEach(function () {
wrapper = (0, enzyme_1.shallow)(React.createElement(BookCover_1.default, { book: bookData }));
});
it("shows title and authors", function () {
var title = wrapper.childAt(0);
(0, chai_1.expect)(title.text()).to.equal(bookData.title);
var authors = wrapper.childAt(1);
(0, chai_1.expect)(authors.text()).to.equal("By ".concat(bookData.authors.join(", ")));
});
});
describe("with image url", function () {
var wrapper;
var bookData = {
id: "test id",
title: "test book",
authors: ["paperback writer", "brilliant recluse"],
imageUrl: "https://dlotdqc6pnwqb.cloudfront.net/3M/crrmnr9/cover.jpg"
};
beforeEach(function () {
wrapper = (0, enzyme_1.shallow)(React.createElement(BookCover_1.default, { book: bookData }));
});
it("shows the book cover with empty alt", function () {
var image = wrapper.find("img");
(0, chai_1.expect)(image.props().src).to.equal(bookData.imageUrl);
(0, chai_1.expect)(image.props().alt).to.equal("");
});
it("shows the placeholder cover on image error", function () {
var image = wrapper.find("img");
image.simulate("error");
var title = wrapper.childAt(0);
(0, chai_1.expect)(title.text()).to.equal(bookData.title);
var authors = wrapper.childAt(1);
(0, chai_1.expect)(authors.text()).to.equal("By ".concat(bookData.authors.join(", ")));
// The placeholder is cleared when there are new props.
var newBookData = {
id: "new book",
imageUrl: "https://dlotdqc6pnwqb.cloudfront.net/3M/abcdefg/cover.jpg"
};
wrapper.setProps({ book: newBookData });
image = wrapper.find("img");
(0, chai_1.expect)(image.props().src).to.equal(newBookData.imageUrl);
});
});
});
;