TEST: unpackStep(), plant_stage resource_update
parent
ce326c0078
commit
b5654229af
|
@ -1,21 +1,46 @@
|
|||
import { unpackStep, InputData } from "../unpack_step";
|
||||
import { fakeResourceIndex } from "../../tile_move_absolute/test_helpers";
|
||||
import { ResourceUpdate } from "farmbot";
|
||||
import { selectAllPlantPointers } from "../../../../resources/selectors";
|
||||
|
||||
describe("unpackStep()", () => {
|
||||
it("unpacks unknown resource_update steps", () => {
|
||||
const params: InputData = {
|
||||
step: {
|
||||
kind: "resource_update",
|
||||
args: {
|
||||
resource_type: "Other",
|
||||
resource_id: 1,
|
||||
label: "some_attr",
|
||||
value: "some_value",
|
||||
}
|
||||
},
|
||||
resourceIndex: fakeResourceIndex()
|
||||
function step(i: Partial<ResourceUpdate["args"]>): ResourceUpdate {
|
||||
return {
|
||||
kind: "resource_update",
|
||||
args: {
|
||||
resource_type: "Other",
|
||||
resource_id: 1,
|
||||
label: "some_attr",
|
||||
value: "some_value",
|
||||
...i
|
||||
}
|
||||
};
|
||||
const result = unpackStep(params);
|
||||
}
|
||||
|
||||
it("unpacks plant-based operations", () => {
|
||||
const resourceIndex = fakeResourceIndex();
|
||||
const plant = selectAllPlantPointers(resourceIndex)[1];
|
||||
expect(plant).toBeTruthy();
|
||||
|
||||
const result = unpackStep({
|
||||
step: step({
|
||||
resource_type: "Plant",
|
||||
resource_id: plant.body.id || -1,
|
||||
label: "plant_stage",
|
||||
value: "wilting"
|
||||
}), resourceIndex
|
||||
});
|
||||
expect(result.action.label).toBe("Wilting");
|
||||
expect(result.action.value).toBe("wilting");
|
||||
expect(result.resource.label).toBe(plant.body.name);
|
||||
expect(result.resource.value).toBe(plant.uuid); // Why uuid for plants? -RC
|
||||
});
|
||||
|
||||
it("unpacks unknown resource_update steps", () => {
|
||||
const result = unpackStep({
|
||||
step: step({}),
|
||||
resourceIndex: fakeResourceIndex()
|
||||
});
|
||||
expect(result.action.label).toBe("some_attr = some_value");
|
||||
expect(result.action.value).toBe("some_value");
|
||||
expect(result.resource.label).toBe("Other");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ResourceUpdate } from "farmbot";
|
||||
import { ResourceUpdate, TaggedPoint } from "farmbot";
|
||||
import { DropDownItem } from "../../../ui";
|
||||
import { ResourceIndex } from "../../../resources/interfaces";
|
||||
import { findToolById, findByKindAndId } from "../../../resources/selectors";
|
||||
|
@ -56,12 +56,11 @@ function discardPoint(i: InputData): OutputData {
|
|||
|
||||
function plantStage(i: InputData): OutputData {
|
||||
const { resource_id, value } = i.step.args;
|
||||
const r = findByKindAndId(i.resourceIndex, "Point", resource_id);
|
||||
if (r.kind !== "Point") { throw new Error("Always expecting Point"); }
|
||||
const a = value as string;
|
||||
const r: TaggedPoint = findByKindAndId(i.resourceIndex, "Point", resource_id);
|
||||
|
||||
return {
|
||||
resource: { label: r.body.name, value: r.uuid },
|
||||
action: { label: capitalize(a), value: a }
|
||||
action: { label: capitalize("" + value), value: ("" + value) }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,21 @@ export function fakeResourceIndex(): ResourceIndex {
|
|||
},
|
||||
"uuid": "toolslot"
|
||||
},
|
||||
{
|
||||
"specialStatus": SpecialStatus.SAVED,
|
||||
"kind": "Point",
|
||||
"body": {
|
||||
"id": 4,
|
||||
"meta": {},
|
||||
"name": "dandelion",
|
||||
"pointer_type": "Plant",
|
||||
"radius": 100,
|
||||
"x": 100,
|
||||
"y": 200,
|
||||
"z": 300,
|
||||
},
|
||||
"uuid": "toolslot"
|
||||
},
|
||||
{
|
||||
"specialStatus": SpecialStatus.SAVED,
|
||||
"kind": "Tool",
|
||||
|
|
Loading…
Reference in New Issue