minor cleanup

pull/1254/head
gabrielburnworth 2019-06-28 12:05:37 -07:00
parent db203a444a
commit 9e186b1152
7 changed files with 73 additions and 15 deletions

View File

@ -478,14 +478,15 @@ fieldset {
display: flex;
margin: auto;
max-height: 650px;
min-height: 200px;
}
img {
max-width: 100%;
min-height: 100px;
}
iframe {
width: 100%;
border: none;
min-height: 300px;
}
}

View File

@ -118,8 +118,19 @@ describe("<FarmEventForm/>", () => {
expect(i.state.fe.executable_id).toEqual("wow");
});
it("allows proper changes to the executable", () => {
const p = props();
p.farmEvent.body.id = 0;
p.farmEvent.body.executable_type = "Sequence";
const i = instance(p);
i.executableSet({ value: "wow", label: "hey", headingId: "Regimen" });
expect(error).not.toHaveBeenCalled();
expect(history.push).not.toHaveBeenCalled();
});
it("doesn't allow improper changes to the executable", () => {
const p = props();
p.farmEvent.body.id = 1;
p.farmEvent.body.executable_type = "Regimen";
const i = instance(p);
i.executableSet({ value: "wow", label: "hey", headingId: "Sequence" });

View File

@ -222,9 +222,10 @@ export class EditFEForm extends React.Component<EditFEProps, State> {
executableSet = (ddi: DropDownItem) => {
if (ddi.value) {
const prev_executable_type = this.props.farmEvent.body.executable_type;
const { id, executable_type } = this.props.farmEvent.body;
const prev_executable_type = executable_type;
const next_executable_type = executableType(ddi.headingId);
if (prev_executable_type !== next_executable_type) {
if (id && prev_executable_type !== next_executable_type) {
error(t("Cannot change between Sequences and Regimens."));
history.push("/app/designer/events");
} else {

View File

@ -10,6 +10,7 @@ import { SpecialStatus, TaggedWebAppConfig } from "farmbot";
import { fakeState } from "../../__test_support__/fake_state";
import { fakeSequence } from "../../__test_support__/fake_state/resources";
import { betterCompact } from "../../util";
import { WebAppConfig } from "farmbot/dist/resources/configs/web_app";
describe("unsavedCheck", () => {
beforeEach(() => {
@ -18,8 +19,7 @@ describe("unsavedCheck", () => {
function setItUp(
dirty: Record<"seqDirty" | "otherDirty", boolean>,
// body: Partial<WebAppConfig> | undefined,
body: {} | undefined,
body: Partial<WebAppConfig> | undefined,
) {
const status = (isDirty: boolean) =>
isDirty ? SpecialStatus.DIRTY : SpecialStatus.SAVED;

View File

@ -15,7 +15,7 @@ const shouldStop =
const discardUnsaved = config && config.body.discard_unsaved;
const sequenceResources = allResources.filter(r => r.kind === "Sequence");
const discardUnsavedSequences =
config && config.body["discard_unsaved_sequences"];
config && config.body.discard_unsaved_sequences;
/**
* For the unsaved notification to show, a user must:

View File

@ -31,7 +31,9 @@ jest.mock("../../config_storage/actions", () => ({
import * as React from "react";
import {
SequenceEditorMiddleActive, onDrop, SequenceNameAndColor, AddCommandButton,
SequenceSettingsMenu
SequenceSettingsMenu,
SequenceSetting,
SequenceSettingProps
} from "../sequence_editor_middle_active";
import { mount, shallow } from "enzyme";
import { ActiveMiddleProps, SequenceHeaderProps } from "../interfaces";
@ -262,3 +264,46 @@ describe("<SequenceSettingsMenu />", () => {
BooleanSetting.show_pins, true);
});
});
describe("<SequenceSetting />", () => {
const fakeProps = (): SequenceSettingProps => ({
label: "setting label",
description: "setting description",
dispatch: jest.fn(),
setting: BooleanSetting.discard_unsaved_sequences,
getWebAppConfigValue: jest.fn(),
confirmation: "setting confirmation",
});
it("confirms setting enable", () => {
const p = fakeProps();
p.getWebAppConfigValue = () => false;
const wrapper = mount(<SequenceSetting {...p} />);
window.confirm = jest.fn(() => true);
wrapper.find("button").simulate("click");
expect(window.confirm).toHaveBeenCalledWith("setting confirmation");
expect(setWebAppConfigValue).toHaveBeenCalledWith(
BooleanSetting.discard_unsaved_sequences, true);
});
it("cancels setting enable", () => {
const p = fakeProps();
p.getWebAppConfigValue = () => false;
const wrapper = mount(<SequenceSetting {...p} />);
window.confirm = jest.fn(() => false);
wrapper.find("button").simulate("click");
expect(window.confirm).toHaveBeenCalledWith("setting confirmation");
expect(setWebAppConfigValue).not.toHaveBeenCalled();
});
it("doesn't confirm setting disable", () => {
const p = fakeProps();
p.getWebAppConfigValue = () => true;
const wrapper = mount(<SequenceSetting {...p} />);
window.confirm = jest.fn();
wrapper.find("button").simulate("click");
expect(window.confirm).not.toHaveBeenCalled();
expect(setWebAppConfigValue).toHaveBeenCalledWith(
BooleanSetting.discard_unsaved_sequences, false);
});
});

View File

@ -55,7 +55,7 @@ export interface SequenceSettingsMenuProps {
getWebAppConfigValue: GetWebAppConfigValue;
}
interface SettingProps {
export interface SequenceSettingProps {
label: string;
description: string;
dispatch: Function;
@ -64,10 +64,10 @@ interface SettingProps {
confirmation?: string;
}
const Setting = (props: SettingProps) => {
export const SequenceSetting = (props: SequenceSettingProps) => {
const value = !!props.getWebAppConfigValue(props.setting);
const proceed = () =>
props.confirmation ? confirm(t(props.confirmation)) : true;
(props.confirmation && !value) ? confirm(t(props.confirmation)) : true;
return <fieldset>
<label>
{t(props.label)}
@ -84,20 +84,20 @@ export const SequenceSettingsMenu =
({ dispatch, getWebAppConfigValue }: SequenceSettingsMenuProps) => {
const commonProps = { dispatch, getWebAppConfigValue };
return <div className="sequence-settings-menu">
<Setting {...commonProps}
<SequenceSetting {...commonProps}
setting={BooleanSetting.confirm_step_deletion}
label={t("Confirm step deletion")}
description={Content.CONFIRM_STEP_DELETION} />
<Setting {...commonProps}
<SequenceSetting {...commonProps}
setting={BooleanSetting.show_pins}
label={t("Show pins")}
description={Content.SHOW_PINS} />
<Setting {...commonProps}
<SequenceSetting {...commonProps}
setting={BooleanSetting.expand_step_options}
label={t("Open options by default")}
description={Content.EXPAND_STEP_OPTIONS} />
<Setting {...commonProps}
setting={"discard_unsaved_sequences"}
<SequenceSetting {...commonProps}
setting={BooleanSetting.discard_unsaved_sequences}
confirmation={Content.DISCARD_UNSAVED_SEQUENCE_CHANGES_CONFIRM}
label={t("Discard unsaved sequence changes")}
description={Content.DISCARD_UNSAVED_SEQUENCE_CHANGES} />