-
Notifications
You must be signed in to change notification settings - Fork 324
/
map_state_to_props_test.ts
88 lines (80 loc) · 2.99 KB
/
map_state_to_props_test.ts
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
import {
mapStateToProps, plantAgeAndStage, formatPlantInfo,
} from "../map_state_to_props";
import { fakeState } from "../../__test_support__/fake_state";
import {
buildResourceIndex,
} from "../../__test_support__/resource_index_builder";
import {
fakePlant, fakePlantTemplate, fakeWebAppConfig, fakeWeed,
} from "../../__test_support__/fake_state/resources";
import moment from "moment";
describe("mapStateToProps()", () => {
it("returns findPlant()", () => {
const state = fakeState();
const plant = fakePlant();
plant.body.id = 10;
state.resources = buildResourceIndex([plant]);
const uuid = Object.keys(state.resources.index.all)[0];
const result = mapStateToProps(state);
expect(result.findPlant(undefined)).toEqual(undefined);
expect(result.findPlant("10")).toEqual(
expect.objectContaining({ uuid }));
});
it("finds plant template", () => {
const state = fakeState();
const template = fakePlantTemplate();
template.body.id = 10;
state.resources = buildResourceIndex([template]);
const uuid = Object.keys(state.resources.index.all)[0];
state.resources.consumers.farm_designer.openedSavedGarden = 1;
const result = mapStateToProps(state);
expect(result.findPlant("10")).toEqual(
expect.objectContaining({ uuid }));
});
it("returns getConfigValue()", () => {
const state = fakeState();
const webAppConfig = fakeWebAppConfig();
webAppConfig.body.show_plants = false;
state.resources = buildResourceIndex([webAppConfig]);
const result = mapStateToProps(state);
expect(result.getConfigValue("show_plants")).toEqual(false);
});
});
describe("plantAgeAndStage()", () => {
it("returns planted at date", () => {
const plant = fakePlant();
plant.body.planted_at = "2018-01-11T20:20:38.362Z";
plant.body.created_at = undefined;
expect(plantAgeAndStage(plant).age).toBeGreaterThan(100);
});
it("returns plant stage", () => {
const plant = fakePlant();
plant.body.planted_at = undefined;
plant.body.created_at = "2018-01-11T20:20:38.362Z";
expect(plantAgeAndStage(plant).stage).toEqual("planned");
});
it("returns created at date", () => {
const plant = fakeWeed();
plant.body.created_at = "2018-01-11T20:20:38.362Z";
expect(plantAgeAndStage(plant).age).toBeGreaterThan(100);
});
});
describe("formatPlantInfo()", () => {
it("returns info for plant", () => {
const plant = fakePlant();
plant.body.planted_at = "2018-01-11T20:20:38.362Z";
plant.body.plant_stage = "planted";
const result = formatPlantInfo(plant);
expect(result.meta).toEqual({});
expect(result.plantedAt).toEqual(moment("2018-01-11T20:20:38.362Z"));
expect(result.plantStatus).toEqual("planted");
});
it("returns info for plant template", () => {
const plant = fakePlantTemplate();
const result = formatPlantInfo(plant);
expect(result.meta).toBeUndefined();
expect(result.plantedAt).toEqual(undefined);
expect(result.plantStatus).toEqual("planned");
});
});