[STABLE] Sync button tests

This commit is contained in:
Rick Carlino 2017-12-13 07:47:24 -06:00
parent 703a569f11
commit 5d5129c20c
2 changed files with 64 additions and 20 deletions

View file

@ -0,0 +1,64 @@
import * as React from "react";
import { SyncButton } from "../sync_button";
import { bot } from "../../__test_support__/fake_state/bot";
import { fakeUser } from "../../__test_support__/fake_state/resources";
import { defensiveClone } from "../../util";
import { shallow } from "enzyme";
const FAKE_BOT_STATE = defensiveClone(bot);
describe("<SyncButton/>", function () {
it("renders nothing when not given a bot", function () {
const dispatcher = jest.fn();
const result = shallow(<SyncButton user={undefined}
dispatch={dispatcher}
bot={FAKE_BOT_STATE}
consistent={true}
autoSyncEnabled={true} />);
expect(result.hasClass("nav-sync")).toBeFalsy();
expect(result.html()).toEqual("<span></span>");
});
it("is gray when inconsistent", () => {
const result = shallow(<SyncButton user={fakeUser()}
dispatch={jest.fn()}
bot={FAKE_BOT_STATE}
consistent={false}
autoSyncEnabled={true} />);
expect(result.hasClass("gray")).toBeTruthy();
});
it("defaults to `disconnected` and `red` when uncertain", () => {
const badState = defensiveClone(FAKE_BOT_STATE);
badState.hardware.informational_settings.sync_status = "mistake" as any;
const result = shallow(<SyncButton user={fakeUser()}
dispatch={jest.fn()}
bot={badState}
consistent={true}
autoSyncEnabled={true} />);
expect(result.text()).toContain("DISCONNECTED");
expect(result.hasClass("red")).toBeTruthy();
});
it("disables syncing when inconsistent", () => {
const dispatch = jest.fn();
const result = shallow(<SyncButton user={fakeUser()}
dispatch={dispatch}
bot={FAKE_BOT_STATE}
consistent={false}
autoSyncEnabled={true} />);
result.find("button").simulate("click");
expect(dispatch).not.toHaveBeenCalled();
});
it("syncs when clicked", () => {
const dispatch = jest.fn();
const result = shallow(<SyncButton user={fakeUser()}
dispatch={dispatch}
bot={FAKE_BOT_STATE}
consistent={true}
autoSyncEnabled={true} />);
result.find("button").simulate("click");
expect(dispatch).toHaveBeenCalled();
});
});

View file

@ -1,20 +0,0 @@
import * as React from "react";
import { SyncButton } from "../sync_button";
import { bot } from "../../__test_support__/fake_state/bot";
import { defensiveClone } from "../../util";
import { shallow } from "enzyme";
const FAKE_BOT_STATE = defensiveClone(bot);
describe("<SyncButton/>", function () {
it("renders nothing when not given a bot", function () {
const dispatcher = jest.fn();
const result = shallow(<SyncButton user={undefined}
dispatch={dispatcher}
bot={FAKE_BOT_STATE}
consistent={true}
autoSyncEnabled={true} />);
expect(result.hasClass("nav-sync")).toBeFalsy();
expect(result.html()).toEqual("<span></span>");
});
});