Farmbot-Web-App/frontend/__tests__/app_test.tsx

98 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-09-15 23:51:12 -06:00
jest.mock("react-redux", () => ({
connect: jest.fn()
}));
let mockPath = "";
jest.mock("../history", () => ({
getPathArray: jest.fn(() => { return mockPath.split("/"); })
}));
2017-09-08 12:38:46 -06:00
import * as React from "react";
import { App, AppProps } from "../app";
import { mount } from "enzyme";
import { bot } from "../__test_support__/fake_state/bot";
import { fakeUser } from "../__test_support__/fake_state/resources";
2018-04-12 17:55:38 -06:00
const fakeProps = (): AppProps => {
return {
timeOffset: 0, // Default to UTC
dispatch: jest.fn(),
loaded: [],
logs: [],
user: fakeUser(),
bot: bot,
consistent: true,
axisInversion: { x: false, y: false, z: false },
firmwareConfig: undefined,
xySwap: false,
animate: false,
2018-08-30 19:25:58 -06:00
getConfigValue: jest.fn(),
2018-10-15 17:23:58 -06:00
tour: undefined,
2018-04-12 17:55:38 -06:00
};
};
2017-09-08 12:38:46 -06:00
2018-04-12 17:55:38 -06:00
describe("<App />: Controls Pop-Up", () => {
2017-09-08 12:38:46 -06:00
function controlsPopUp(page: string, exists: boolean) {
it(`doesn't render controls pop-up on ${page} page`, () => {
mockPath = "/app/" + page;
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...fakeProps()} />);
2017-09-08 12:38:46 -06:00
if (exists) {
expect(wrapper.html()).toContain("controls-popup");
} else {
expect(wrapper.html()).not.toContain("controls-popup");
}
});
}
controlsPopUp("designer", true);
controlsPopUp("designer/plants", true);
controlsPopUp("controls", false);
controlsPopUp("device", true);
controlsPopUp("sequences", true);
2017-09-08 12:38:46 -06:00
controlsPopUp("sequences/for_regimens", true);
controlsPopUp("regimens", false);
controlsPopUp("tools", true);
2017-09-08 12:38:46 -06:00
controlsPopUp("farmware", true);
controlsPopUp("account", false);
});
2018-03-19 22:14:49 -06:00
describe("<App />: Loading", () => {
2017-09-08 12:38:46 -06:00
it("MUST_LOADs not loaded", () => {
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...fakeProps()} />);
2018-03-19 22:14:49 -06:00
expect(wrapper.text()).toContain("Loading...");
2018-10-12 12:14:49 -06:00
wrapper.unmount();
2017-09-08 12:38:46 -06:00
});
it("MUST_LOADs partially loaded", () => {
const p = fakeProps();
2017-10-27 07:31:25 -06:00
p.loaded = ["Sequence"];
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...p} />);
2018-03-19 22:14:49 -06:00
expect(wrapper.text()).toContain("Loading...");
2018-10-12 12:14:49 -06:00
wrapper.unmount();
2017-09-08 12:38:46 -06:00
});
it("MUST_LOADs loaded", () => {
const p = fakeProps();
p.loaded = ["Sequence", "Regimen", "FarmEvent", "Point", "Tool"];
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...p} />);
2018-03-19 22:14:49 -06:00
expect(wrapper.text()).not.toContain("Loading...");
2018-10-12 12:14:49 -06:00
wrapper.unmount();
2017-09-08 12:38:46 -06:00
});
});
describe("<App />: NavBar", () => {
it("displays links", () => {
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...fakeProps()} />);
2017-09-08 12:38:46 -06:00
expect(wrapper.text())
.toContain("Farm DesignerControlsDeviceSequencesRegimensToolsFarmware");
2018-10-12 12:14:49 -06:00
wrapper.unmount();
2017-09-08 12:38:46 -06:00
});
it("displays ticker", () => {
2018-03-09 02:34:24 -07:00
const wrapper = mount(<App {...fakeProps()} />);
2017-09-08 12:38:46 -06:00
expect(wrapper.text()).toContain("No logs yet.");
2018-10-12 12:14:49 -06:00
wrapper.unmount();
2017-09-08 12:38:46 -06:00
});
});