-
Notifications
You must be signed in to change notification settings - Fork 324
/
app_test.tsx
155 lines (141 loc) · 4.59 KB
/
app_test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
let mockShowPopUp = false;
jest.mock("../controls_popup", () => ({
ControlsPopup: () => <div className="controls-popup" />,
showControlsPopup: () => mockShowPopUp,
}));
import * as React from "react";
import { RawApp as App, AppProps, mapStateToProps } from "../app";
import { mount } from "enzyme";
import { bot } from "../__test_support__/fake_state/bot";
import {
fakeUser, fakeWebAppConfig, fakeFbosConfig, fakeFarmwareEnv,
} from "../__test_support__/fake_state/resources";
import { fakeState } from "../__test_support__/fake_state";
import {
buildResourceIndex,
} from "../__test_support__/resource_index_builder";
import { ResourceName } from "farmbot";
import { fakeTimeSettings } from "../__test_support__/fake_time_settings";
import { error } from "../toast/toast";
import { fakePings } from "../__test_support__/fake_state/pings";
const FULLY_LOADED: ResourceName[] = [
"Sequence", "Regimen", "FarmEvent", "Point", "Tool", "Device"];
const fakeProps = (): AppProps => ({
timeSettings: fakeTimeSettings(),
dispatch: jest.fn(),
loaded: [],
logs: [],
user: fakeUser(),
bot: bot,
consistent: true,
axisInversion: { x: false, y: false, z: false },
firmwareConfig: undefined,
xySwap: false,
animate: false,
getConfigValue: jest.fn(),
tour: undefined,
resources: buildResourceIndex().index,
autoSync: false,
alertCount: 0,
pings: fakePings(),
env: {},
alerts: [],
apiFirmwareValue: undefined,
});
describe("<App />: Controls Pop-Up", () => {
it("renders controls pop-up", () => {
mockShowPopUp = true;
const wrapper = mount(<App {...fakeProps()} />);
expect(wrapper.html()).toContain("controls-popup");
});
it("doesn't render controls pop-up", () => {
mockShowPopUp = false;
const wrapper = mount(<App {...fakeProps()} />);
expect(wrapper.html()).not.toContain("controls-popup");
});
});
describe("<App />: Loading", () => {
it("MUST_LOADs not loaded", () => {
const wrapper = mount(<App {...fakeProps()} />);
expect(wrapper.text()).toContain("Loading...");
wrapper.unmount();
});
it("MUST_LOADs partially loaded", () => {
const p = fakeProps();
p.loaded = ["Sequence"];
const wrapper = mount(<App {...p} />);
expect(wrapper.text()).toContain("Loading...");
wrapper.unmount();
});
it("MUST_LOADs loaded", () => {
const p = fakeProps();
p.loaded = FULLY_LOADED;
const wrapper = mount(<App {...p} />);
expect(wrapper.text()).not.toContain("Loading...");
wrapper.unmount();
});
it("times out while loading", () => {
jest.useFakeTimers();
const wrapper = mount(<App {...fakeProps()} />);
jest.runAllTimers();
expect(error).toHaveBeenCalledWith(
expect.stringContaining("App could not be fully loaded"), "Warning");
wrapper.unmount();
});
it("loads before timeout", () => {
const p = fakeProps();
p.loaded = FULLY_LOADED;
jest.useFakeTimers();
const wrapper = mount(<App {...p} />);
jest.runAllTimers();
expect(error).not.toHaveBeenCalled();
wrapper.unmount();
});
});
describe("<App />: NavBar", () => {
it("displays links", () => {
const p = fakeProps();
p.loaded = FULLY_LOADED;
const wrapper = mount(<App {...p} />);
const t = wrapper.text();
const strings = [
"Farm Designer",
"Sequences",
"Regimens",
];
strings.map(string => expect(t).toContain(string));
wrapper.unmount();
});
it("displays ticker", () => {
const p = fakeProps();
p.loaded = FULLY_LOADED;
const wrapper = mount(<App {...p} />);
expect(wrapper.text()).toContain("No logs yet.");
wrapper.unmount();
});
});
describe("mapStateToProps()", () => {
it("returns props", () => {
const state = fakeState();
const config = fakeWebAppConfig();
config.body.x_axis_inverted = true;
state.resources = buildResourceIndex([config]);
state.bot.hardware.user_env = { fake: "value" };
const result = mapStateToProps(state);
expect(result.axisInversion.x).toEqual(true);
expect(result.autoSync).toEqual(false);
expect(result.env).toEqual({ fake: "value" });
});
it("returns api props", () => {
const state = fakeState();
const config = fakeFbosConfig();
config.body.auto_sync = true;
const fakeEnv = fakeFarmwareEnv();
state.resources = buildResourceIndex([config, fakeEnv]);
state.bot.minOsFeatureData = { api_farmware_env: "8.0.0" };
state.bot.hardware.informational_settings.controller_version = "8.0.0";
const result = mapStateToProps(state);
expect(result.autoSync).toEqual(true);
expect(result.env).toEqual({ [fakeEnv.body.key]: fakeEnv.body.value });
});
});