52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
import React from "react";
|
|
import { shallow, configure } from "enzyme";
|
|
import Adapter from "enzyme-adapter-react-16";
|
|
configure({ adapter: new Adapter() });
|
|
|
|
import { EventLog, mapStateToProps } from "../../app/src/components/EventLog";
|
|
|
|
describe("EventLog", () => {
|
|
|
|
const writeTag = jest.fn();
|
|
|
|
it("renders loading div if events not defined", () => {
|
|
const wrapper = shallow(<EventLog />);
|
|
expect(wrapper.find(".loading")).toHaveLength(1);
|
|
expect(wrapper.find(".loading").text()).toMatch("Loading");
|
|
});
|
|
|
|
it("should call writeTag with cmd_ResetAlarms and true on Reset button click", () => {
|
|
const wrapper = shallow(<EventLog events={[]} writeTag={writeTag} />);
|
|
wrapper.find(".reset-button").simulate("click", null);
|
|
expect(writeTag).toBeCalledWith("cmd_ResetAlarms", true);
|
|
});
|
|
|
|
describe("event timeline", () => {
|
|
let events, wrapper;
|
|
|
|
beforeEach(() => {
|
|
events = [
|
|
{ tag: "test", timestamp: new Date(), eventType: "alarm"},
|
|
{ tag: "tttt", timestamp: new Date(), eventType: "cmd" }
|
|
];
|
|
wrapper = shallow(<EventLog events={events} />);
|
|
});
|
|
|
|
it("should return a Timeline Event for each event", () => {
|
|
expect(wrapper.find("TimelineEvent")).toHaveLength(2);
|
|
});
|
|
|
|
it("shows a calendar icon for non-alarm events", () => {
|
|
expect(wrapper.find("TimelineEvent").last().html()).toMatch("calendar");
|
|
});
|
|
|
|
it("shows an exclamation triangle for alarm events", () => {
|
|
expect(wrapper.find("TimelineEvent").first().html()).toMatch("exclamation-triangle");
|
|
});
|
|
});
|
|
|
|
|
|
it("should map state to props", () => {
|
|
expect(mapStateToProps({ events: "events", extra: "extra" })).toEqual({ events: "events" });
|
|
});
|
|
}); |