Farmbot-Web-App/frontend/sequences/locals_list/__tests__/location_form_list_test.ts

131 lines
3.5 KiB
TypeScript
Raw Normal View History

2019-06-07 18:26:55 -06:00
import {
2020-02-28 09:35:32 -07:00
locationFormList, dropDownName, formatTool, groups2Ddi,
2019-06-07 18:26:55 -06:00
} from "../location_form_list";
2017-10-12 21:50:02 -06:00
import { fakeResourceIndex } from "../test_helpers";
2019-06-07 18:26:55 -06:00
import {
2020-02-28 09:35:32 -07:00
fakeToolSlot, fakeTool, fakePointGroup,
2019-06-07 18:26:55 -06:00
} from "../../../__test_support__/fake_state/resources";
2017-10-12 21:50:02 -06:00
2019-01-13 16:43:12 -07:00
describe("locationFormList()", () => {
2017-10-12 21:50:02 -06:00
it("returns dropdown list", () => {
2019-10-22 10:03:00 -06:00
const pg = fakePointGroup();
pg.body.id = 1;
const items = locationFormList(fakeResourceIndex([pg]), [], true);
2019-04-09 22:00:03 -06:00
const coordinate = items[0];
expect(coordinate).toEqual({
headingId: "Coordinate",
label: "Custom Coordinates",
value: "",
});
const toolHeading = items[1];
expect(toolHeading).toEqual({
headingId: "Tool",
2019-04-15 20:11:35 -06:00
label: "Tools and Seed Containers",
value: 0,
heading: true,
});
2019-04-09 22:00:03 -06:00
const tool = items[2];
expect(tool).toEqual({
headingId: "Tool",
2018-12-20 20:18:10 -07:00
label: "Generic tool (100, 200, 300)",
value: "1",
});
const groupHeading = items[3];
expect(groupHeading).toEqual({
headingId: "PointGroup",
label: "Groups",
value: 0,
heading: true,
});
const group = items[4];
expect(group).toEqual({
headingId: "PointGroup",
label: "Fake",
value: "1"
});
const plantHeading = items[5];
expect(plantHeading).toEqual({
headingId: "Plant",
label: "Plants",
value: 0,
heading: true,
});
const plant = items[6];
2017-10-12 21:50:02 -06:00
expect(plant).toEqual({
headingId: "Plant",
label: "Plant 1 (1, 2, 3)",
2017-10-12 21:50:02 -06:00
value: "1"
});
const pointHeading = items[8];
expect(pointHeading).toEqual({
headingId: "GenericPointer",
label: "Map Points",
value: 0,
heading: true,
});
const point = items[9];
2017-10-12 21:50:02 -06:00
expect(point).toEqual({
headingId: "GenericPointer",
label: "Point 1 (10, 20, 30)",
2017-10-12 21:50:02 -06:00
value: "2"
});
const weedHeading = items[10];
expect(weedHeading).toEqual({
headingId: "Weed",
label: "Weeds",
2019-10-22 10:03:00 -06:00
value: 0,
heading: true,
});
const weed = items[11];
expect(weed).toEqual({
headingId: "Weed",
label: "Weed 1 (15, 25, 35)",
value: "5"
2019-10-22 10:03:00 -06:00
});
2017-10-12 21:50:02 -06:00
});
});
2019-06-07 18:26:55 -06:00
describe("formatTool()", () => {
it("returns ddi for tool", () => {
const ddi = formatTool(fakeTool(), fakeToolSlot());
expect(ddi.label).toEqual("Foo (0, 0, 0)");
});
it("returns ddi for tool when gantry mounted", () => {
const toolSlot = fakeToolSlot();
toolSlot.body.gantry_mounted = true;
const ddi = formatTool(fakeTool(), toolSlot);
2020-02-20 19:38:50 -07:00
expect(ddi.label).toEqual("Foo (gantry, 0, 0)");
2019-06-07 18:26:55 -06:00
});
});
2017-10-12 21:50:02 -06:00
describe("dropDownName()", () => {
it("returns label", () => {
const label = dropDownName("Plant 1", { x: 10, y: 20, z: 30 });
expect(label).toEqual("Plant 1 (10, 20, 30)");
2017-10-12 21:50:02 -06:00
});
2019-06-07 18:26:12 -06:00
it("returns untitled label", () => {
const label = dropDownName("", { x: 10, y: 20, z: 30 });
expect(label).toEqual("Untitled (10, 20, 30)");
});
2019-06-07 18:26:55 -06:00
it("returns label with undefined coordinates", () => {
const label = dropDownName("Plant 1",
{ x: undefined, y: undefined, z: undefined });
expect(label).toEqual("Plant 1 (---, ---, ---)");
});
2017-10-12 21:50:02 -06:00
});
2019-09-26 12:45:54 -06:00
describe("groups2Ddi", () => {
it("excludes unsaved groups", () => {
const fakes = [fakePointGroup(), fakePointGroup()];
fakes[0].body.id = 1;
fakes[1].body.id = undefined;
const result = groups2Ddi(fakes);
expect(result.length).toEqual(1);
expect(result[0].label).toEqual(fakes[0].body.name);
expect(result[0].value).toEqual("1");
});
});