Tests for assertIsHour()

pull/1570/head
Rick Carlino 2019-11-12 14:53:47 -06:00
parent b6c4f296cc
commit f04da2a91c
3 changed files with 14 additions and 4 deletions

View File

@ -1,9 +1,10 @@
import {
fakeFbosConfig, fakeImage, fakeFarmwareEnv
fakeFbosConfig, fakeImage, fakeFarmwareEnv, fakeWebAppConfig
} from "../../__test_support__/fake_state/resources";
let mockFbosConfig: TaggedFbosConfig | undefined = fakeFbosConfig();
const mockImages: TaggedImage | undefined = fakeImage();
const mockWebAppConf = fakeWebAppConfig();
jest.mock("../../resources/selectors_by_kind", () => ({
selectAllAlerts: () => [],
@ -17,7 +18,7 @@ jest.mock("../../resources/selectors_by_kind", () => ({
jest.mock("../../resources/getters", () => ({
getFbosConfig: () => mockFbosConfig,
getFirmwareConfig: () => undefined,
getWebAppConfig: jest.fn(),
getWebAppConfig: jest.fn(() => mockWebAppConf),
}));
import { mapStateToProps } from "../state_to_props";

View File

@ -1,10 +1,19 @@
import React from "react";
import { OtaTimeSelector, changeOtaHour } from "..";
import { OtaTimeSelector, changeOtaHour, assertIsHour } from "..";
import { shallow } from "enzyme";
import { FBSelect } from "../../../../../ui";
import { fakeDevice } from "../../../../../__test_support__/resource_index_builder";
describe("OTA time selector", () => {
it("asserts that a variable is an HOUR", () => {
expect(assertIsHour(undefined)).toBe(undefined);
// tslint:disable-next-line:no-null-keyword
expect(assertIsHour(null as unknown as undefined)).toBe(undefined);
const crashOn = (x: number) => () => assertIsHour(x);
expect(assertIsHour(undefined)).toBe(undefined);
expect(crashOn(-2)).toThrowError("Not an hour!");
expect(crashOn(24)).toThrowError("Not an hour!");
});
it("selects an OTA update time", () => {
const onUpdate = jest.fn();
const el = shallow(<OtaTimeSelector

View File

@ -112,7 +112,7 @@ export const changeOtaHour =
dispatch(save(device.uuid));
};
function assertIsHour(val: number | undefined): asserts val is (HOUR | undefined) {
export function assertIsHour(val: number | undefined): asserts val is (HOUR | undefined) {
if ((val === null) || (val === undefined)) {
return;
}