TODO: De-Curry newVariableCreator

pull/1463/head
Rick Carlino 2019-09-26 13:45:54 -05:00
parent 0785ee979a
commit d124c58251
3 changed files with 50 additions and 4 deletions

View File

@ -9,7 +9,8 @@ import {
fakeSequence,
fakePoint,
fakeTool,
fakeToolSlot
fakeToolSlot,
fakePointGroup
} from "../../__test_support__/fake_state/resources";
import {
buildResourceIndex
@ -25,6 +26,39 @@ import { fakeVariableNameSet } from "../../__test_support__/fake_variables";
import { NOTHING_SELECTED } from "../../sequences/locals_list/handle_select";
describe("determineDropdown", () => {
it("crashes oon unknown DDIs", () => {
// tslint:disable-next-line:no-any
const baddata: any = {
kind: "parameter_application",
args: {
label: "x",
data_value: {
kind: "other",
args: { resource_id: 12 }
}
}
};
const r = () => determineDropdown(baddata, buildResourceIndex([]).index);
expect(r).toThrowError("WARNING: Unknown, possibly new data_value.kind?");
});
it("returns a label for `PointGroup`", () => {
const pg = fakePointGroup();
pg.body.id = 12;
const r = determineDropdown({
kind: "parameter_application",
args: {
label: "x",
data_value: {
kind: "point_group", args: { resource_id: 12 }
}
}
}, buildResourceIndex([pg]).index);
expect(r.label).toEqual(pg.body.name);
expect(r.value).toEqual(pg.body.id);
});
it("Returns a label for `parameter_declarations`", () => {
const r = determineDropdown({
kind: "parameter_declaration",

View File

@ -1,9 +1,9 @@
import {
locationFormList, dropDownName, formatTool
locationFormList, dropDownName, formatTool, groups2Ddi
} from "../location_form_list";
import { fakeResourceIndex } from "../test_helpers";
import {
fakeToolSlot, fakeTool
fakeToolSlot, fakeTool, fakePointGroup
} from "../../../__test_support__/fake_state/resources";
describe("locationFormList()", () => {
@ -88,3 +88,15 @@ describe("dropDownName()", () => {
expect(label).toEqual("Plant 1 (---, ---, ---)");
});
});
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");
});
});

View File

@ -60,7 +60,7 @@ const maybeGroup = (display: boolean) =>
(groupDDI: DropDownItem): DropDownItem[] =>
display ? [groupDDI] : [];
const groups2Ddi = (groups: TaggedPointGroup[]): DropDownItem[] => {
export const groups2Ddi = (groups: TaggedPointGroup[]): DropDownItem[] => {
return groups
.filter(x => x.body.id)
.map(x => {