2018-07-19 23:48:32 -06:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import { mount, shallow } from "enzyme";
|
2019-04-09 23:17:03 -06:00
|
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
|
TimePeriodSelection, getEndDate, DateDisplay,
|
2019-04-09 23:17:03 -06:00
|
|
|
|
} from "../time_period_selection";
|
2018-07-19 23:48:32 -06:00
|
|
|
|
import { fakeSensorReading } from "../../../__test_support__/fake_state/resources";
|
2018-07-24 21:45:38 -06:00
|
|
|
|
import { TimePeriodSelectionProps, DateDisplayProps } from "../interfaces";
|
2019-04-09 23:17:03 -06:00
|
|
|
|
import { fakeTimeSettings } from "../../../__test_support__/fake_time_settings";
|
2018-07-19 23:48:32 -06:00
|
|
|
|
|
|
|
|
|
describe("<TimePeriodSelection />", () => {
|
2018-07-24 21:45:38 -06:00
|
|
|
|
function fakeProps(): TimePeriodSelectionProps {
|
2018-07-19 23:48:32 -06:00
|
|
|
|
return {
|
|
|
|
|
timePeriod: 3600 * 24,
|
|
|
|
|
endDate: 1515715140,
|
|
|
|
|
showPreviousPeriod: false,
|
|
|
|
|
setEndDate: jest.fn(),
|
|
|
|
|
setPeriod: jest.fn(),
|
|
|
|
|
togglePrevious: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("renders", () => {
|
|
|
|
|
const wrapper = mount(<TimePeriodSelection {...fakeProps()} />);
|
|
|
|
|
const txt = wrapper.text().toLowerCase();
|
|
|
|
|
["time period", "day", "period end date", "show previous"]
|
|
|
|
|
.map(string => expect(txt).toContain(string));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes time period", () => {
|
|
|
|
|
const p = fakeProps();
|
|
|
|
|
const wrapper = shallow(<TimePeriodSelection {...p} />);
|
|
|
|
|
wrapper.find("FBSelect").simulate("change", { label: "", value: 100 });
|
|
|
|
|
expect(p.setPeriod).toHaveBeenCalledWith(100);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("changes end date", () => {
|
|
|
|
|
const p = fakeProps();
|
|
|
|
|
const wrapper = shallow(<TimePeriodSelection {...p} />);
|
|
|
|
|
wrapper.find("BlurableInput").simulate("commit",
|
|
|
|
|
{ currentTarget: { value: "2002-01-10" } });
|
2018-07-20 02:10:28 -06:00
|
|
|
|
expect(p.setEndDate).toHaveBeenCalledWith(expect.any(Number));
|
2018-07-19 23:48:32 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("updates end date", () => {
|
|
|
|
|
const p = fakeProps();
|
|
|
|
|
const wrapper = shallow(<TimePeriodSelection {...p} />);
|
|
|
|
|
wrapper.find("i").simulate("click");
|
|
|
|
|
expect(p.setEndDate).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("getEndDate()", () => {
|
|
|
|
|
it("returns recent reading date", () => {
|
2018-07-24 22:40:26 -06:00
|
|
|
|
expect(getEndDate([fakeSensorReading()])).toEqual(expect.any(Number));
|
2018-07-19 23:48:32 -06:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns current date", () => {
|
|
|
|
|
expect(getEndDate([])).toEqual(expect.any(Number));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("<DateDisplay />", () => {
|
2018-07-24 21:45:38 -06:00
|
|
|
|
function fakeProps(): DateDisplayProps {
|
2018-07-19 23:48:32 -06:00
|
|
|
|
return {
|
|
|
|
|
timePeriod: 3600 * 24 * 7,
|
|
|
|
|
endDate: 1515715140,
|
|
|
|
|
showPreviousPeriod: true,
|
2019-04-09 23:17:03 -06:00
|
|
|
|
timeSettings: fakeTimeSettings(),
|
2018-07-19 23:48:32 -06:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
it("renders", () => {
|
|
|
|
|
const wrapper = mount(<DateDisplay {...fakeProps()} />);
|
|
|
|
|
const txt = wrapper.text().toLowerCase();
|
|
|
|
|
["date", "january 4–january 11 (december 28–january 4)"]
|
|
|
|
|
.map(string => expect(txt).toContain(string));
|
|
|
|
|
});
|
|
|
|
|
});
|