✔️ Tests done

pull/1463/head
Rick Carlino 2019-09-26 15:48:10 -05:00
parent e0e88119db
commit 2e15b74ce9
4 changed files with 54 additions and 21 deletions

View File

@ -9,11 +9,43 @@ const expectedVariable = (data_value: Point | Tool | Coordinate) =>
({ kind: "parameter_application", args: { label, data_value } });
describe("convertDDItoDeclaration()", () => {
it("handles malformed items", () => {
const result = convertDDItoVariable({
identifierLabel: "Y",
allowedVariableNodes,
dropdown: {
headingId: "something_else",
label: "X",
value: 23
}
});
expect(result).toEqual(undefined);
});
it("handles point groups", () => {
const result = convertDDItoVariable({
identifierLabel: "Y",
allowedVariableNodes,
dropdown: {
headingId: "PointGroup",
label: "X",
value: 23
}
});
expect(result).toEqual({
kind: "parameter_application",
args: {
label: "Y",
data_value: { kind: "point_group", args: { resource_id: 23 } }
}
});
});
it("returns location data: point", () => {
const dropdown =
({ headingId: "GenericPointer", label: "Point 1 (10, 20, 30)", value: 2 });
const variable = convertDDItoVariable({
label,
identifierLabel: label,
allowedVariableNodes,
dropdown
});
@ -29,7 +61,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: tool", () => {
const dropdown = { headingId: "Tool", label: "Generic Tool", value: 1 };
const variable =
convertDDItoVariable({ label, allowedVariableNodes, dropdown });
convertDDItoVariable({ identifierLabel: label, allowedVariableNodes, dropdown });
expect(variable).toEqual(expectedVariable({
kind: "tool", args: { tool_id: 1 }
}));
@ -38,7 +70,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: Plant", () => {
const dropdown = { headingId: "Plant", label: "Mint", value: 1 };
const variable =
convertDDItoVariable({ label, allowedVariableNodes, dropdown });
convertDDItoVariable({ identifierLabel: label, allowedVariableNodes, dropdown });
expect(variable).toEqual(expectedVariable({
kind: "point", args: { pointer_id: 1, pointer_type: "Plant" }
}));
@ -46,7 +78,8 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: default", () => {
const variable = convertDDItoVariable({
label, allowedVariableNodes,
identifierLabel: label,
allowedVariableNodes,
dropdown: NO_VALUE_SELECTED_DDI()
});
expect(variable).toEqual(expectedVariable(NOTHING_SELECTED));
@ -56,7 +89,7 @@ describe("convertDDItoDeclaration()", () => {
const expected = expectedVariable(NOTHING_SELECTED);
expected.kind = "variable_declaration";
const variable = convertDDItoVariable({
label, allowedVariableNodes: AllowedVariableNodes.parameter,
identifierLabel: label, allowedVariableNodes: AllowedVariableNodes.parameter,
dropdown: NO_VALUE_SELECTED_DDI()
});
expect(variable).toEqual(expected);
@ -64,7 +97,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: coordinate", () => {
const variable = convertDDItoVariable({
label, allowedVariableNodes,
identifierLabel: label, allowedVariableNodes,
dropdown: COORDINATE_DDI({ x: 1, y: 2, z: 3 })
});
expect(variable).toEqual(expectedVariable({
@ -74,7 +107,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: new coordinate", () => {
const variable = convertDDItoVariable({
label, allowedVariableNodes,
identifierLabel: label, allowedVariableNodes,
dropdown: COORDINATE_DDI()
});
expect(variable).toEqual(expectedVariable({
@ -85,7 +118,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: parameter_declaration", () => {
const dropdown = ({ headingId: "parameter", label: "Parent0", value: "parent0" });
const variable = convertDDItoVariable({
label: "parent",
identifierLabel: "parent",
allowedVariableNodes,
dropdown
});
@ -101,7 +134,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: identifier", () => {
const dropdown = ({ headingId: "parameter", label: "Parent0", value: "parent0" });
const variable = convertDDItoVariable({
label: "parent",
identifierLabel: "parent",
allowedVariableNodes: AllowedVariableNodes.identifier,
dropdown
});
@ -123,7 +156,7 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: every_point", () => {
const dropdown = ({ headingId: "every_point", label: "All Plants", value: "Plant" });
const variable = convertDDItoVariable({
label: "label",
identifierLabel: "label",
allowedVariableNodes,
dropdown
});

View File

@ -53,7 +53,7 @@ describe("<LocationForm/>", () => {
select.onChange(dropdown);
expect(p.onChange)
.toHaveBeenCalledWith(convertDDItoVariable({
label: "label",
identifierLabel: "label",
allowedVariableNodes: p.allowedVariableNodes,
dropdown
}));

View File

@ -63,18 +63,18 @@ const createVariableDeclaration =
});
interface NewVarProps {
label: string;
identifierLabel: string;
allowedVariableNodes: AllowedVariableNodes;
dropdown: DropDownItem;
newVarLabel?: string;
}
const nothingVar =
({ label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
({ identifierLabel: label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
createVariableNode(allowedVariableNodes)(label, NOTHING_SELECTED);
const toolVar = (value: string | number) =>
({ label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
({ identifierLabel: label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
createVariableNode(allowedVariableNodes)(label, {
kind: "tool",
args: { tool_id: parseInt("" + value) }
@ -83,21 +83,21 @@ const toolVar = (value: string | number) =>
const pointVar = (
pointer_type: "Plant" | "GenericPointer",
value: string | number
) => ({ label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
) => ({ identifierLabel: label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
createVariableNode(allowedVariableNodes)(label, {
kind: "point",
args: { pointer_type, pointer_id: parseInt("" + value) }
});
const everyPointVar = (value: string | number) =>
({ label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
({ identifierLabel: label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
createVariableNode(allowedVariableNodes)(label, {
kind: "every_point",
args: { every_point_type: "" + value as PointType }
});
const manualEntry = (value: string | number) =>
({ label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
({ identifierLabel: label, allowedVariableNodes }: NewVarProps): VariableWithAValue =>
createVariableNode(allowedVariableNodes)(label, {
kind: "coordinate",
args: value ? JSON.parse("" + value) : { x: 0, y: 0, z: 0 }
@ -108,7 +108,7 @@ const manualEntry = (value: string | number) =>
* identifier.
*/
export const newParameter = (p: NewVarProps): VariableNode => {
const { label, newVarLabel, allowedVariableNodes } = p;
const { identifierLabel: label, newVarLabel, allowedVariableNodes } = p;
if (allowedVariableNodes === AllowedVariableNodes.identifier && newVarLabel) {
return createParameterApplication(label, {
kind: "identifier",
@ -143,12 +143,12 @@ const createNewVariable = (props: NewVarProps): VariableNode | undefined => {
return {
kind: "parameter_application",
args: {
label: props.label,
label: props.identifierLabel,
data_value: { kind: "point_group", args: { resource_id } }
}
};
}
console.warn("WARNING: Don't know how to handle " + (ddi.headingId || "NA"));
console.error("WARNING: Don't know how to handle " + (ddi.headingId || "NA"));
return undefined;
};
/** Convert a drop down selection to a variable. */

View File

@ -86,7 +86,7 @@ export const LocationForm =
customNullLabel={NO_VALUE_SELECTED_DDI().label}
onChange={ddi => {
props.onChange(convertDDItoVariable({
label,
identifierLabel: label,
allowedVariableNodes,
dropdown: ddi
}));