button to add Farmduino peripherals

pull/541/head
gabrielburnworth 2017-11-27 15:20:34 -08:00
parent f5e811153f
commit 7ffbd8e549
2 changed files with 44 additions and 0 deletions

View File

@ -71,4 +71,24 @@ describe("<Peripherals />", () => {
save.simulate("click");
expect(p.dispatch).toHaveBeenCalled();
});
it("adds empty peripheral", () => {
const p = fakeProps();
const wrapper = mount(<Peripherals {...p } />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(2);
expect(add.text()).toEqual("");
add.simulate("click");
expect(p.dispatch).toHaveBeenCalled();
});
it("adds farmduino peripherals", () => {
const p = fakeProps();
const wrapper = mount(<Peripherals {...p } />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(3);
expect(add.text()).toEqual("Farmduino");
add.simulate("click");
expect(p.dispatch).toHaveBeenCalledTimes(5);
});
});

View File

@ -65,6 +65,22 @@ export class Peripherals extends React.Component<PeripheralsProps, PeripheralSta
};
}
farmduinoPeripherals = (dispatch: Function) => {
function newPeripheral(pin: number, label: string) {
dispatch(init({
uuid: "WILL_BE_CHANGED_BY_REDUCER",
specialStatus: SpecialStatus.SAVED,
kind: "Peripheral",
body: { pin, label }
}));
}
newPeripheral(7, "Lighting");
newPeripheral(8, "Water");
newPeripheral(9, "Vacuum");
newPeripheral(10, "Peripheral 4");
newPeripheral(12, "Peripheral 5");
}
render() {
const { dispatch, peripherals } = this.props;
const { isEditing } = this.state;
@ -91,6 +107,14 @@ export class Peripherals extends React.Component<PeripheralsProps, PeripheralSta
onClick={() => { dispatch(init(this.emptyPeripheral())); }}>
<i className="fa fa-plus" />
</button>
<button
hidden={!isEditing}
className="fb-button green"
type="button"
onClick={() => this.farmduinoPeripherals(dispatch)}>
<i className="fa fa-plus" style={{ marginRight: "0.5rem" }} />
Farmduino
</button>
</WidgetHeader>
<WidgetBody>
{this.showPins()}