Farmbot-Web-App/frontend/devices/components/__tests__/farmbot_os_settings_test.tsx

86 lines
2.9 KiB
TypeScript
Raw Normal View History

let mockReleaseNoteData = {};
2018-01-11 23:18:26 -07:00
jest.mock("axios", () => ({
2019-06-07 18:26:12 -06:00
get: jest.fn(() => Promise.resolve(mockReleaseNoteData))
}));
jest.mock("../../../api/crud", () => ({
edit: jest.fn(),
save: jest.fn(),
2018-01-11 23:18:26 -07:00
}));
2019-09-23 12:56:35 -06:00
jest.mock("../fbos_settings/boot_sequence_selector", () => ({
BootSequenceSelector: () => <div />
}));
import * as React from "react";
import { FarmbotOsSettings } from "../farmbot_os_settings";
2018-01-27 02:29:13 -07:00
import { mount, shallow } from "enzyme";
import { bot } from "../../../__test_support__/fake_state/bot";
import { fakeResource } from "../../../__test_support__/fake_resource";
2018-01-11 23:18:26 -07:00
import { FarmbotOsProps } from "../../interfaces";
import axios from "axios";
2019-04-09 23:17:03 -06:00
import { fakeTimeSettings } from "../../../__test_support__/fake_time_settings";
2019-08-24 05:53:52 -06:00
import { edit } from "../../../api/crud";
2019-09-20 09:52:51 -06:00
describe("<FarmbotOsSettings />", () => {
2018-05-15 20:38:52 -06:00
beforeEach(() => {
window.alert = jest.fn();
});
2019-06-07 18:26:12 -06:00
const fakeProps = (): FarmbotOsProps => ({
deviceAccount: fakeResource("Device", { id: 0, name: "", tz_offset_hrs: 0 }),
diagnostics: [],
dispatch: jest.fn(),
bot,
2019-07-12 14:39:40 -06:00
alerts: [],
botToMqttLastSeen: 0,
2019-06-07 18:26:12 -06:00
botToMqttStatus: "up",
sourceFbosConfig: x =>
({ value: bot.hardware.configuration[x], consistent: true }),
shouldDisplay: jest.fn(),
isValidFbosConfig: false,
env: {},
saveFarmwareEnv: jest.fn(),
timeSettings: fakeTimeSettings(),
});
2018-01-11 23:18:26 -07:00
it("renders settings", () => {
2018-07-03 12:21:05 -06:00
const osSettings = mount(<FarmbotOsSettings {...fakeProps()} />);
expect(osSettings.find("input").length).toBe(1);
2019-08-24 05:53:52 -06:00
expect(osSettings.find("button").length).toBe(6);
2019-06-07 18:26:12 -06:00
["NAME", "TIME ZONE", "FARMBOT OS", "CAMERA", "FIRMWARE"]
.map(string => expect(osSettings.text()).toContain(string));
});
2018-01-11 23:18:26 -07:00
it("fetches OS release notes", async () => {
mockReleaseNoteData = { data: "intro\n\n# v6\n\n* note" };
const osSettings = await mount<FarmbotOsSettings>(<FarmbotOsSettings
{...fakeProps()} />);
2018-01-11 23:18:26 -07:00
await expect(axios.get).toHaveBeenCalledWith(
expect.stringContaining("RELEASE_NOTES.md"));
2018-09-14 12:54:14 -06:00
expect(osSettings.instance().state.osReleaseNotesHeading)
.toEqual("FarmBot OS v6");
expect(osSettings.instance().state.osReleaseNotes)
2018-09-14 12:54:14 -06:00
.toEqual("* note");
2018-01-11 23:18:26 -07:00
});
it("doesn't fetch OS release notes", async () => {
mockReleaseNoteData = { data: "empty notes" };
const osSettings = await mount<FarmbotOsSettings>(<FarmbotOsSettings
{...fakeProps()} />);
2018-01-11 23:18:26 -07:00
await expect(axios.get).toHaveBeenCalledWith(
expect.stringContaining("RELEASE_NOTES.md"));
expect(osSettings.instance().state.osReleaseNotes)
2018-01-11 23:18:26 -07:00
.toEqual("Could not get release notes.");
});
2018-01-27 02:29:13 -07:00
it("changes bot name", () => {
const p = fakeProps();
2019-06-07 18:26:12 -06:00
const newName = "new bot name";
2018-01-27 02:29:13 -07:00
const osSettings = shallow(<FarmbotOsSettings {...p} />);
osSettings.find("input")
2019-06-07 18:26:12 -06:00
.simulate("change", { currentTarget: { value: newName } });
expect(edit).toHaveBeenCalledWith(p.deviceAccount, { name: newName });
2018-01-27 02:29:13 -07:00
});
});