Skip to content

Commit

Permalink
Merge branch 'staging' into rpc_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCarlino committed Jan 13, 2019
2 parents 62a5bc6 + 2547c99 commit 12b6db3
Show file tree
Hide file tree
Showing 27 changed files with 522 additions and 85 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -51,7 +51,7 @@
"css-loader": "2.1.0",
"enzyme": "3.8.0",
"enzyme-adapter-react-16": "1.7.1",
"farmbot": "6.6.3-rc6",
"farmbot": "6.6.3-rc8",
"farmbot-toastr": "1.0.3",
"fastclick": "1.0.6",
"file-loader": "3.0.1",
Expand Down
1 change: 1 addition & 0 deletions webpack/account/dev/__tests__/dev_mode_test.tsx
Expand Up @@ -13,6 +13,7 @@ import { warning } from "farmbot-toastr";

describe("<DevMode/>", () => {
it("triggers callbacks after 15 clicks", () => {
console.log = jest.fn();
const dispatch = jest.fn();
const el = mount(<DevMode dispatch={dispatch} />);
range(0, 16).map(() => el.simulate("click"));
Expand Down
1 change: 1 addition & 0 deletions webpack/constants.ts
Expand Up @@ -743,6 +743,7 @@ export enum Actions {

// Sequences
SELECT_SEQUENCE = "SELECT_SEQUENCE",
SET_SEQUENCE_POPUP_STATE = "SET_SEQUENCE_POPUP_STATE",

// Farmware
SELECT_FARMWARE = "SELECT_FARMWARE",
Expand Down
18 changes: 18 additions & 0 deletions webpack/css/global.scss
Expand Up @@ -611,6 +611,24 @@ ul {
}
}

.fb-button-popover-wrapper {
float: right;
margin-right: 1rem;
}

.parameter-assignment-menu {
.test-button-div {
text-align: center;
}
.fb-button {
float: none;
}
}

.parameter-assignment-menu-popover {
max-width: 400px;
}

.note {
font-style: italic;
font-size: 1.2rem;
Expand Down
23 changes: 16 additions & 7 deletions webpack/devices/__tests__/actions_test.ts
Expand Up @@ -35,7 +35,7 @@ jest.mock("axios", () => ({

import * as actions from "../actions";
import {
fakeSequence, fakeFbosConfig, fakeFirmwareConfig
fakeFbosConfig, fakeFirmwareConfig
} from "../../__test_support__/fake_state/resources";
import { fakeState } from "../../__test_support__/fake_state";
import {
Expand Down Expand Up @@ -106,6 +106,12 @@ describe("emergencyLock() / emergencyUnlock", function () {
actions.emergencyUnlock();
expect(mockDevice.emergencyUnlock).toHaveBeenCalled();
});

it("doesn't call emergencyUnlock", () => {
window.confirm = () => false;
actions.emergencyUnlock();
expect(mockDevice.emergencyUnlock).not.toHaveBeenCalled();
});
});

describe("sync()", function () {
Expand Down Expand Up @@ -139,16 +145,19 @@ describe("sync()", function () {

describe("execSequence()", function () {
it("calls execSequence", async () => {
const s = fakeSequence().body;
await actions.execSequence(s);
expect(mockDevice.execSequence).toHaveBeenCalledWith(s.id);
await actions.execSequence(1);
expect(mockDevice.execSequence).toHaveBeenCalledWith(1);
expect(success).toHaveBeenCalled();
});

it("calls execSequence with variables", async () => {
await actions.execSequence(1, []);
expect(mockDevice.execSequence).toHaveBeenCalledWith(1, []);
expect(success).toHaveBeenCalled();
});

it("implodes when executing unsaved sequences", () => {
const ok = fakeSequence().body;
ok.id = undefined;
expect(() => actions.execSequence(ok)).toThrow();
expect(() => actions.execSequence(undefined)).toThrow();
expect(mockDevice.execSequence).not.toHaveBeenCalled();
});
});
Expand Down
14 changes: 9 additions & 5 deletions webpack/devices/actions.ts
Expand Up @@ -9,9 +9,8 @@ import {
} from "./interfaces";
import { Thunk, ReduxAction } from "../redux/interfaces";
import {
McuParams, Configuration, TaggedFirmwareConfig
McuParams, Configuration, TaggedFirmwareConfig, VariableDeclaration
} from "farmbot";
import { Sequence } from "../sequences/interfaces";
import { ControlPanelState } from "../devices/interfaces";
import { oneOf, versionOK, trim } from "../util";
import { Actions, Content } from "../constants";
Expand Down Expand Up @@ -136,11 +135,16 @@ export function sync(): Thunk {
};
}

export function execSequence(sequence: Sequence) {
export function execSequence(
sequenceId: number | undefined,
declarations?: VariableDeclaration[]
) {
const noun = "Sequence execution";
if (sequence.id) {
if (sequenceId) {
commandOK(noun)();
return getDevice().execSequence(sequence.id).catch(commandErr(noun));
return declarations
? getDevice().execSequence(sequenceId, declarations).catch(commandErr(noun))
: getDevice().execSequence(sequenceId).catch(commandErr(noun));
} else {
throw new Error(t("Can't execute unsaved sequences"));
}
Expand Down
6 changes: 5 additions & 1 deletion webpack/farm_designer/farm_events/edit_fe_form.tsx
Expand Up @@ -39,7 +39,7 @@ import { LocalsList } from "../../sequences/locals_list/locals_list";
import { ResourceIndex } from "../../resources/interfaces";
import { ShouldDisplay, Feature } from "../../devices/interfaces";
import {
addOrEditVarDeclaration, declarationList
addOrEditVarDeclaration, declarationList, getRegimenVariableData
} from "../../sequences/locals_list/declaration_support";
import {
AllowedDeclaration
Expand Down Expand Up @@ -185,6 +185,10 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
}

get variableData() {
if (this.executable.kind === "Regimen") {
const regimenVariables = this.executable.body.body;
return getRegimenVariableData(regimenVariables, this.props.resources);
}
return this.props.resources.sequenceMetas[this.executable.uuid];
}

Expand Down
2 changes: 1 addition & 1 deletion webpack/regimens/editor/active_editor.tsx
Expand Up @@ -36,7 +36,7 @@ export function ActiveEditor(props: ActiveEditorProps) {
sequenceUuid={props.regimen.uuid}
resources={props.resources}
onChange={editRegimenDeclarations(regimenProps)(props.regimen.body.body)}
allowedDeclarations={AllowedDeclaration.variable}
allowedDeclarations={AllowedDeclaration.parameter}
shouldDisplay={props.shouldDisplay} />
<hr />
</div>
Expand Down
5 changes: 3 additions & 2 deletions webpack/sequences/__tests__/reducer_test.ts
@@ -1,6 +1,7 @@
import { sequenceReducer } from "../reducer";
import { Actions } from "../../constants";
import { fakeSequence } from "../../__test_support__/fake_state/resources";
import { SequenceReducerState } from "../interfaces";

describe("sequence reducer", () => {
function resourcePayload(
Expand All @@ -9,7 +10,7 @@ describe("sequence reducer", () => {
after: string | undefined) {
const sequence = fakeSequence();
sequence.uuid = "sequence";
const state = { current: before };
const state: SequenceReducerState = { current: before, menuOpen: false };
const action = { type: actionType, payload: sequence };
const stateAfter = sequenceReducer(state, action);
expect(stateAfter.current).toBe(after);
Expand All @@ -20,7 +21,7 @@ describe("sequence reducer", () => {
});

it("sets current sequence with string", () => {
const state = { current: undefined };
const state: SequenceReducerState = { current: undefined, menuOpen: false };
const action = { type: Actions.SELECT_SEQUENCE, payload: "sequence" };
const stateAfter = sequenceReducer(state, action);
expect(stateAfter.current).toBe("sequence");
Expand Down
40 changes: 22 additions & 18 deletions webpack/sequences/__tests__/sequence_editor_middle_active_test.tsx
Expand Up @@ -21,6 +21,7 @@ jest.mock("../../devices/actions", () => ({
jest.mock("../locals_list/locals_list", () => ({
LocalsList: () => <div />,
localListCallback: jest.fn(() => jest.fn()),
isParameterDeclaration: jest.fn(),
}));

import * as React from "react";
Expand All @@ -45,23 +46,26 @@ import { clickButton } from "../../__test_support__/helpers";
import { fakeVariableNameSet } from "../../__test_support__/fake_variables";

describe("<SequenceEditorMiddleActive/>", () => {
const sequence = fakeSequence();
sequence.specialStatus = SpecialStatus.DIRTY;
const fakeProps = (): ActiveMiddleProps => ({
dispatch: jest.fn(),
sequence,
resources: buildResourceIndex(FAKE_RESOURCES).index,
syncStatus: "synced",
hardwareFlags: fakeHardwareFlags(),
farmwareInfo: {
farmwareNames: [],
firstPartyFarmwareNames: [],
showFirstPartyFarmware: false,
farmwareConfigs: {},
},
shouldDisplay: jest.fn(),
confirmStepDeletion: false,
});
const fakeProps = (): ActiveMiddleProps => {
const sequence = fakeSequence();
sequence.specialStatus = SpecialStatus.DIRTY;
return {
dispatch: jest.fn(),
sequence,
resources: buildResourceIndex(FAKE_RESOURCES).index,
syncStatus: "synced",
hardwareFlags: fakeHardwareFlags(),
farmwareInfo: {
farmwareNames: [],
firstPartyFarmwareNames: [],
showFirstPartyFarmware: false,
farmwareConfigs: {},
},
shouldDisplay: jest.fn(),
confirmStepDeletion: false,
menuOpen: false,
};
};

it("saves", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
Expand All @@ -75,7 +79,7 @@ describe("<SequenceEditorMiddleActive/>", () => {
p.sequence.specialStatus = SpecialStatus.SAVED;
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
clickButton(wrapper, 1, "Test");
expect(execSequence).toHaveBeenCalledWith(p.sequence.body);
expect(execSequence).toHaveBeenCalledWith(p.sequence.body.id);
});

it("deletes", () => {
Expand Down
Expand Up @@ -26,6 +26,7 @@ describe("<SequenceEditorMiddle/>", () => {
},
shouldDisplay: jest.fn(),
confirmStepDeletion: false,
menuOpen: false,
};
}

Expand Down
8 changes: 4 additions & 4 deletions webpack/sequences/__tests__/sequences_list_test.tsx
Expand Up @@ -3,8 +3,8 @@ jest.mock("../../history", () => ({
history: { getCurrentLocation: () => ({ pathname: "" }) }
}));

jest.mock("../actions", () => ({
selectSequence: jest.fn()
jest.mock("../set_active_sequence_by_name", () => ({
setActiveSequenceByName: jest.fn()
}));

jest.mock("../../api/crud", () => ({
Expand All @@ -19,11 +19,11 @@ import { SequencesListProps } from "../interfaces";
import { Actions } from "../../constants";
import { init } from "../../api/crud";
import { push } from "../../history";
import { selectSequence } from "../actions";
import { resourceUsageList } from "../../resources/in_use";
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
import { resourceReducer } from "../../resources/reducer";
import { resourceReady } from "../../sync/actions";
import { setActiveSequenceByName } from "../set_active_sequence_by_name";

describe("<SequencesList />", () => {
const fakeSequences = () => {
Expand Down Expand Up @@ -119,6 +119,6 @@ describe("<SequencesList />", () => {
const p = fakeProps();
const wrapper = shallow(<SequencesList {...p} />);
wrapper.find("Link").first().simulate("click");
expect(selectSequence).toHaveBeenCalledWith(p.sequences[0].uuid);
expect(setActiveSequenceByName).toHaveBeenCalled();
});
});
1 change: 1 addition & 0 deletions webpack/sequences/__tests__/sequences_test.tsx
Expand Up @@ -32,6 +32,7 @@ describe("<Sequences/>", () => {
},
shouldDisplay: jest.fn(),
confirmStepDeletion: false,
menuOpen: false,
};
}

Expand Down
48 changes: 48 additions & 0 deletions webpack/sequences/__tests__/state_to_props_test.ts
Expand Up @@ -5,6 +5,10 @@ jest.mock("react-redux", () => ({
import { mapStateToProps } from "../state_to_props";
import { fakeState } from "../../__test_support__/fake_state";
import { Feature } from "../../devices/interfaces";
import { fakeFarmware } from "../../__test_support__/fake_farmwares";
import { fakeSequence } from "../../__test_support__/fake_state/resources";
import { buildResourceIndex } from "../../__test_support__/resource_index_builder";
import { TaggedSequence } from "farmbot";

describe("mapStateToProps()", () => {
it("returns props", () => {
Expand All @@ -23,4 +27,48 @@ describe("mapStateToProps()", () => {
expect(props.shouldDisplay("some_feature" as any)).toBeFalsy();
expect(props.shouldDisplay(Feature.jest_feature)).toBeTruthy();
});

it("checks for step tags: ok", () => {
const sequence = fakeSequence();
sequence.body.body = [{ kind: "wait", args: { milliseconds: 100 } }];
const state = fakeState();
state.resources = buildResourceIndex([sequence]);
state.resources.consumers.sequences.current = sequence.uuid;
expect(() => mapStateToProps(state)).not.toThrowError();
const props = mapStateToProps(state);
expect(props.sequence).toEqual(expect.objectContaining({
uuid: sequence.uuid,
body: expect.objectContaining({
body: [expect.objectContaining({
kind: "wait", args: { milliseconds: 100 },
uuid: expect.any(String)
})]
})
}));
});

it("checks for step tags: error", () => {
const sequence = fakeSequence();
const state = fakeState();
state.resources = buildResourceIndex([sequence]);
state.resources.consumers.sequences.current = sequence.uuid;
(state.resources.index.references[sequence.uuid] as TaggedSequence).body.body =
[{ kind: "wait", args: { milliseconds: 100 } }];
expect(() => mapStateToProps(state)).toThrowError(/No tag on step/);
});

it("returns farmwareConfigs", () => {
const state = fakeState();
state.resources.consumers.sequences.current = undefined;
state.bot.hardware.process_info.farmwares = {
"My Fake Farmware": fakeFarmware()
};
const props = mapStateToProps(state);
expect(props.farmwareInfo.farmwareNames).toEqual(["My Fake Farmware"]);
expect(props.farmwareInfo.farmwareConfigs).toEqual({
"My Fake Farmware": [{
name: "config_1", label: "Config 1", value: "4"
}]
});
});
});

0 comments on commit 12b6db3

Please sign in to comment.