opds-web-client
Version:
55 lines (54 loc) • 3.06 kB
JavaScript
autoMockOff();
var React = require("react");
var enzyme_1 = require("enzyme");
var Lanes_1 = require("../Lanes");
var Lane_1 = require("../Lane");
var collectionData_1 = require("./collectionData");
var spinner_1 = require("../../images/spinner");
describe("Lanes", function () {
var wrapper;
var hiddenBookIds = ["book id"];
beforeEach(function () {
wrapper = enzyme_1.shallow(React.createElement(Lanes_1.Lanes, {url: collectionData_1.groupedCollectionData.url, lanes: collectionData_1.groupedCollectionData.lanes, isFetching: true, hideMoreLinks: true, hiddenBookIds: hiddenBookIds}));
});
it("shows lanes in order", function () {
var lanes = wrapper.find(Lane_1.default);
lanes.forEach(function (lane, i) {
expect(lane.props().lane).toBe(collectionData_1.groupedCollectionData.lanes[i]);
expect(lane.props().collectionUrl).toEqual(collectionData_1.groupedCollectionData.url);
expect(lane.props().hideMoreLink).toBe(true);
expect(lane.props().hiddenBookIds).toBe(hiddenBookIds);
});
});
it("shows spinner", function () {
var spinnerImage = wrapper.find("img.lanesSpinner");
expect(spinnerImage.props().src).toBe(spinner_1.default);
});
it("fetches collection on mount", function () {
var fetchCollection = jest.genMockFunction();
wrapper = enzyme_1.shallow(React.createElement(Lanes_1.Lanes, {url: collectionData_1.groupedCollectionData.url, lanes: [], fetchCollection: fetchCollection}));
expect(fetchCollection.mock.calls.length).toBe(1);
expect(fetchCollection.mock.calls[0][0]).toBe(collectionData_1.groupedCollectionData.url);
});
it("fetches new collection on componentWillReceiveProps if there's a new url", function () {
var clearCollection = jest.genMockFunction();
var fetchCollection = jest.genMockFunction();
wrapper = enzyme_1.shallow(React.createElement(Lanes_1.Lanes, {url: "test1", lanes: [], clearCollection: clearCollection, fetchCollection: fetchCollection}));
expect(clearCollection.mock.calls.length).toBe(0);
expect(fetchCollection.mock.calls.length).toBe(1);
wrapper.instance().componentWillReceiveProps({ url: "test1" });
expect(clearCollection.mock.calls.length).toBe(0);
expect(fetchCollection.mock.calls.length).toBe(1);
wrapper.instance().componentWillReceiveProps({ url: "test2" });
expect(clearCollection.mock.calls.length).toBe(1);
expect(fetchCollection.mock.calls.length).toBe(2);
expect(fetchCollection.mock.calls[1][0]).toBe("test2");
});
it("clears collection on unmount", function () {
var clearCollection = jest.genMockFunction();
wrapper = enzyme_1.shallow(React.createElement(Lanes_1.Lanes, {url: collectionData_1.groupedCollectionData.url, lanes: [], clearCollection: clearCollection}));
wrapper.instance().componentWillUnmount();
expect(clearCollection.mock.calls.length).toBe(1);
});
});
;
jest.