More tests

This commit is contained in:
Rick Carlino 2017-09-28 16:46:46 -05:00
parent dfac5173f3
commit 5be5586aa8
4 changed files with 66 additions and 2 deletions

View file

@ -0,0 +1,47 @@
jest.mock("react-redux", () => ({
connect: jest.fn()
}));
jest.mock("farmbot-toastr/dist", () => ({ success: jest.fn() }));
import * as React from "react";
import { fakeState } from "../../__test_support__/fake_state";
import { mapStateToProps } from "../state_to_props";
import { mount } from "enzyme";
import { Account } from "../index";
import { edit, save } from "../../api/crud";
describe("<Account />", () => {
it("handles the onChange event - bad input", () => {
const props = mapStateToProps(fakeState());
props.dispatch = jest.fn();
const el = mount(<Account {...props} />);
expect(() => {
(el.instance() as Account).onChange({
currentTarget: {
name: "foo",
value: "bar"
}
} as any);
}).toThrow();
(el.instance() as Account).onChange({
currentTarget: {
name: "email",
value: "foo@bar.com"
}
} as any);
expect(props.dispatch).toHaveBeenCalledTimes(1);
const expected = edit(props.user, { email: "foo@bar.com" });
expect(props.dispatch).toHaveBeenCalledWith(expected);
});
it("triggers the onSave() event", () => {
const props = mapStateToProps(fakeState());
props.dispatch = jest.fn(() => Promise.resolve({}));
const el = mount(<Account {...props} />);
(el.instance() as Account).onSave();
expect(props.dispatch).toHaveBeenCalledTimes(1);
});
});

View file

@ -0,0 +1,18 @@
import { connectivityReducer } from "../reducer";
import { networkUp, networkDown } from "../actions";
describe("connectivityReducer", () => {
it("goes up", () => {
const state = connectivityReducer(undefined, networkUp());
expect(state).toBeDefined();
expect(state && state.state).toBe("up");
expect(state && state.at).toBeTruthy();
});
it("goes down", () => {
const state = connectivityReducer(undefined, networkDown());
expect(state).toBeDefined();
expect(state && state.state).toBe("down");
expect(state && state.at).toBeTruthy();
});
});

View file

@ -45,6 +45,5 @@ export function diagnose(x: DiagnosisProps) {
x.userMQTT,
x.botFirmware);
const errMsg = TRUTH_TABLE[errorCode] || DiagnosticMessages.MISC;
console.log(`Err code ${errorCode} (${errorCode.toString(2)})`);
return `${t(errMsg)} (code ${errorCode})`;
}

View file

@ -8,7 +8,7 @@ import { stopIE, attachToRoot, shortRevision } from "./util";
stopIE();
let r = shortRevision();
const r = shortRevision();
console.log(r);
detectLanguage().then((config) => {