More tests

pull/593/head
Rick Carlino 2017-12-27 10:24:50 -06:00
parent 13f05691cb
commit 4e1a7fe81e
4 changed files with 56 additions and 3 deletions

View File

@ -0,0 +1,34 @@
import {
isNumericSetting,
isBooleanSetting,
safeBooleanSettting,
safeNumericSetting
} from "../session";
describe("isNumericSetting", () => {
it("determines numericality", () => {
expect(isNumericSetting("zoomLevel")).toBe(true);
expect(isNumericSetting("foo")).toBe(false);
});
});
describe("isBooleanSetting", () => {
it("determines boolean-ness of settings", () => {
expect(isBooleanSetting("xAxisInverted")).toBe(true);
expect(isBooleanSetting("no")).toBe(false);
});
});
describe("safeBooleanSetting", () => {
it("safely fetches bool", () => {
expect(() => safeBooleanSettting("NO")).toThrow();
expect(safeBooleanSettting("xAxisInverted")).toBe("xAxisInverted");
});
});
describe("safeNumericSetting", () => {
it("safely returns num", () => {
expect(() => safeNumericSetting("NO")).toThrow();
expect(safeNumericSetting("zoomLevel")).toBe("zoomLevel");
});
});

View File

@ -0,0 +1,17 @@
import { authReducer } from "../reducer";
import { setToken } from "../actions";
import { AuthState } from "../interfaces";
describe("Auth reducer", () => {
function fakeToken(): AuthState {
const output: Partial<AuthState> = {
token: ({} as any)
};
return output as AuthState;
}
it("replaces the token", () => {
const result = authReducer({ token: undefined }, setToken(fakeToken()));
expect(result.token).toBeTruthy();
});
});

View File

@ -30,6 +30,7 @@ import { fakeState } from "../../__test_support__/fake_state";
import { changeStepSize, resetNetwork, resetConnectionInfo } from "../actions";
import { Actions } from "../../constants";
import { fakeDevice } from "../../__test_support__/resource_index_builder";
import { API } from "../../api/index";
describe("checkControllerUpdates()", function () {
beforeEach(function () {
@ -226,9 +227,10 @@ describe("resetConnectionInfo()", () => {
it("dispatches the right actions", () => {
const mock1 = jest.fn();
const d = fakeDevice();
API.setBaseUrl("http://localhost:300");
resetConnectionInfo(d)(mock1, jest.fn());
expect(mock1).toHaveBeenCalledWith(resetNetwork());
expect(mock1).toHaveBeenCalledTimes(2);
expect(mock1).toHaveBeenCalledTimes(1);
expect(mockDevice.readStatus).toHaveBeenCalled();
});
});

View File

@ -73,7 +73,7 @@ export namespace Session {
}
}
const isBooleanSetting =
export const isBooleanSetting =
// tslint:disable-next-line:no-any
(x: any): x is BooleanSetting => !!BooleanSetting[x];
@ -85,7 +85,7 @@ export function safeBooleanSettting(name: string): BooleanSetting {
}
}
const isNumericSetting =
export const isNumericSetting =
// tslint:disable-next-line:no-any
(x: any): x is NumericSetting => !!NumericSetting[x];