TEST: unpackStep(), unknown resource_update
parent
18a4809e4c
commit
ce326c0078
|
@ -115,7 +115,6 @@ GEM
|
|||
responders
|
||||
warden (~> 1.2.3)
|
||||
diff-lcs (1.3)
|
||||
digest-murmurhash (1.1.1)
|
||||
discard (1.0.0)
|
||||
activerecord (>= 4.2, < 6)
|
||||
docile (1.3.1)
|
||||
|
@ -398,7 +397,6 @@ DEPENDENCIES
|
|||
delayed_job
|
||||
delayed_job_active_record
|
||||
devise
|
||||
digest-murmurhash
|
||||
discard
|
||||
factory_bot_rails
|
||||
faker
|
||||
|
|
|
@ -50,8 +50,8 @@
|
|||
"browser-speech": "1.1.1",
|
||||
"coveralls": "3.0.2",
|
||||
"css-loader": "1.0.0",
|
||||
"enzyme-adapter-react-16": "1.5.0",
|
||||
"enzyme": "3.6.0",
|
||||
"enzyme-adapter-react-16": "1.5.0",
|
||||
"farmbot": "https://github.com/RickCarlino/farmbot-js.git#2458c790",
|
||||
"farmbot-toastr": "^1.0.3",
|
||||
"fastclick": "^1.0.6",
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import { unpackStep, InputData } from "../unpack_step";
|
||||
import { fakeResourceIndex } from "../../tile_move_absolute/test_helpers";
|
||||
|
||||
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()
|
||||
};
|
||||
const result = unpackStep(params);
|
||||
expect(result.action.label).toBe("some_attr = some_value");
|
||||
expect(result.action.value).toBe("some_value");
|
||||
expect(result.resource.label).toBe("Other");
|
||||
expect(result.resource.value).toBe(1);
|
||||
});
|
||||
});
|
|
@ -1,15 +0,0 @@
|
|||
export type MarkableAction =
|
||||
| "discarded_at"
|
||||
| "plant_stage"
|
||||
| "current_tool_id";
|
||||
|
||||
const markableActions: MarkableAction[] = [
|
||||
"discarded_at",
|
||||
"plant_stage",
|
||||
"current_tool_id",
|
||||
];
|
||||
|
||||
export const isMarkableAction = (x: unknown): x is MarkableAction => {
|
||||
const y: string[] = markableActions;
|
||||
return (typeof x === "string") && y.includes(x);
|
||||
};
|
|
@ -6,7 +6,7 @@ import { point2ddi } from "../tile_move_absolute/format_selected_dropdown";
|
|||
import { capitalize } from "lodash";
|
||||
import { MOUNTED_TO } from "./action_list";
|
||||
|
||||
interface InputData { step: ResourceUpdate; resourceIndex: ResourceIndex; }
|
||||
export interface InputData { step: ResourceUpdate; resourceIndex: ResourceIndex; }
|
||||
interface OutputData { resource: DropDownItem; action: DropDownItem; }
|
||||
|
||||
const TOOL_MOUNT: DropDownItem = { label: "Tool Mount", value: "tool_mount" };
|
||||
|
@ -34,10 +34,12 @@ function mountTool(i: InputData): OutputData {
|
|||
}
|
||||
|
||||
function unknownOption(i: InputData): OutputData {
|
||||
const r = `${i.step.args.resource_type}#${i.step.args.resource_id}`;
|
||||
const a = `${i.step.args.value}`;
|
||||
const { resource_type, resource_id, label, value } = i.step.args;
|
||||
|
||||
return { resource: { label: r, value: r }, action: { label: a, value: a } };
|
||||
return {
|
||||
resource: { label: resource_type, value: resource_id },
|
||||
action: { label: `${label} = ${value}`, value: "" + value }
|
||||
};
|
||||
}
|
||||
|
||||
function discardPoint(i: InputData): OutputData {
|
||||
|
@ -70,7 +72,6 @@ export function unpackStep(i: InputData): OutputData {
|
|||
case "mounted_tool_id": return mountTool(i);
|
||||
case "discarded_at": return discardPoint(i);
|
||||
case "plant_stage": return plantStage(i);
|
||||
default:
|
||||
return unknownOption(i);
|
||||
default: return unknownOption(i);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue