@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
59 lines • 2.15 kB
JavaScript
import React from "react";
import { shallow } from "enzyme";
import CivicStoryCard from "./CivicStoryCard";
describe("CivicStoryCard", function () {
var _title$slug = {
title: "Test Story Card Title",
slug: "card1"
},
title = _title$slug.title,
slug = _title$slug.slug;
describe("common properties", function () {
var wrapper = shallow(React.createElement(CivicStoryCard, {
slug: slug,
title: title
}));
it("should render the title as an h2", function () {
var h2 = wrapper.find("h2");
expect(h2.text()).to.contain(title);
});
it("should include a StoryFooter that references this CivicStoryCard", function () {
var footer = wrapper.find("StoryFooter");
expect(footer.props().slug).to.equal(slug);
});
});
describe("loading state", function () {
var wrapper = shallow(React.createElement(CivicStoryCard, {
loading: true
}, React.createElement("h1", null, "blah")));
it("should render loading image", function () {
expect(wrapper.find("Logo").length).to.eql(1);
});
it("should not render children", function () {
expect(wrapper.find("h1").length).to.eql(0);
});
});
describe("error state", function () {
var wrapper = shallow(React.createElement(CivicStoryCard, {
error: "Could not load data"
}, React.createElement("h1", null, "blah")));
it("should render loading message", function () {
expect(wrapper.text().indexOf("Could not load data")).to.eql(0);
});
it("should not render children", function () {
expect(wrapper.find("h1").length).to.eql(0);
});
});
describe("card children", function () {
var wrapper = shallow(React.createElement(CivicStoryCard, {
slug: slug,
title: title
}, React.createElement("div", {
className: "Description"
}, "Some content"), React.createElement("div", null, "Some other stuff")));
it("should render children into a container div under the title", function () {
expect(wrapper.children()).to.have.length(4);
expect(wrapper.find("h2 + div").children()).to.have.length(2);
});
});
});