More tests for commitSelection()

pull/979/head
Rick Carlino 2018-09-11 15:35:02 -05:00
parent b35d73241a
commit 9d8e80a647
5 changed files with 81 additions and 3 deletions

View File

@ -8,7 +8,7 @@ import { unpackStep } from "./mark_as/unpack_step";
import { ResourceUpdate } from "../../../latest_corpus";
import { resourceList } from "./mark_as/resource_list";
import { actionList } from "./mark_as/action_list";
import { commitStepChanges } from "./mark_as/commit_selection";
import { commitStepChanges } from "./mark_as/commit_step_changes";
interface MarkAsState { nextResource: DropDownItem | undefined }
const NONE: DropDownItem = { value: 0, label: "" };

View File

@ -0,0 +1,24 @@
import { fakeMarkAsProps } from "../assertion_support";
import { commitStepChanges } from "../commit_step_changes";
import { ResourceUpdate, TaggedSequence } from "farmbot";
import { Actions } from "../../../../constants";
describe("commitSelection", () => {
it("commits changes in a <MarkAs/> component", () => {
const p = fakeMarkAsProps();
const results = commitStepChanges({
nextAction: { label: "X", value: "some_action" },
nextResource: undefined,
step: p.currentStep as ResourceUpdate,
index: p.index,
sequence: p.currentSequence
});
expect(results.type).toBe(Actions.OVERWRITE_RESOURCE);
const { payload } = results;
expect(payload.uuid.split(".")[0]).toBe("Sequence");
const s = payload.update as TaggedSequence["body"];
expect(s.kind).toBe("sequence");
const step = (s.body || [])[0] as ResourceUpdate;
expect(step.args.value).toBe("some_action");
});
});

View File

@ -0,0 +1,26 @@
import * as React from "react";
import { shallow, mount } from "enzyme";
import { MarkAs } from "../../mark_as";
import { FBSelect } from "../../../../ui";
import { fakeMarkAsProps } from "../assertion_support";
describe("<MarkAs/>", () => {
it("renders the basic parts", () => {
const el = mount(<MarkAs {...fakeMarkAsProps()} />);
const text = el.text();
expect(text).toContain("Tool Mount");
expect(text).toContain("Not Mounted");
});
it("selects a resource", () => {
const el = shallow(<MarkAs {...fakeMarkAsProps()} />);
const wow = el.find(FBSelect).first();
expect(wow).toBeTruthy();
const nextResource = {
label: "fake resource",
value: "fake_resource"
};
wow.simulate("change", nextResource);
expect(el.state()).toEqual({ nextResource });
});
});

View File

@ -1,13 +1,15 @@
import { ResourceUpdate } from "farmbot";
import { ResourceUpdate, TaggedSequence } from "farmbot";
import {
buildResourceIndex
} from "../../../__test_support__/resource_index_builder";
import {
fakeTool,
fakePlant,
fakePoint
fakePoint,
fakeSequence
} from "../../../__test_support__/fake_state/resources";
import { betterMerge } from "../../../util";
import { MarkAs } from "../mark_as";
type Args = Partial<ResourceUpdate["args"]>;
@ -31,3 +33,29 @@ export const markAsResourceFixture = () => buildResourceIndex([
betterMerge(fakePoint(), { body: { name: "my point", id: 7 } }),
betterMerge(fakeTool(), { body: { name: "T3", id: undefined } }),
]);
export function fakeMarkAsProps() {
const steps: TaggedSequence["body"]["body"] = [
{
kind: "resource_update",
args: {
resource_type: "Device",
resource_id: 0,
label: "mounted_tool_id",
value: 0
}
}
];
const currentSequence: TaggedSequence =
betterMerge(fakeSequence(), { body: { body: steps } });
const props: MarkAs["props"] = {
currentSequence,
dispatch: jest.fn(),
index: 0,
currentStep: steps[0],
resources: buildResourceIndex([currentSequence]).index,
confirmStepDeletion: false
};
return props;
}