fix scan image offline bug

pull/1170/head^2
gabrielburnworth 2019-04-25 10:02:30 -07:00
parent cdd72f3c9d
commit 0f67cc3fdf
2 changed files with 22 additions and 2 deletions

View File

@ -1,9 +1,12 @@
import React from "react";
import { mount } from "enzyme";
import { ImageWorkspace, ImageWorkspaceProps } from "../image_workspace";
import { fakeImage } from "../../../__test_support__/fake_state/resources";
import { TaggedImage } from "farmbot";
import { fakeTimeSettings } from "../../../__test_support__/fake_time_settings";
import { clickButton } from "../../../__test_support__/helpers";
describe("<Body/>", () => {
describe("<ImageWorkspace />", () => {
const fakeProps = (): ImageWorkspaceProps => ({
onFlip: jest.fn(),
onProcessPhoto: jest.fn(),
@ -84,4 +87,21 @@ describe("<Body/>", () => {
iw.maybeProcessPhoto();
expect(p.onProcessPhoto).toHaveBeenCalledWith(photo2.body.id);
});
it("scans image", () => {
const image = fakeImage();
const p = fakeProps();
p.botOnline = true;
p.images = [image];
const wrapper = mount(<ImageWorkspace {...p} />);
clickButton(wrapper, 0, "scan image");
expect(p.onProcessPhoto).toHaveBeenCalledWith(image.body.id);
});
it("disables scan image button when offline", () => {
const p = fakeProps();
p.botOnline = false;
const wrapper = mount(<ImageWorkspace {...p} />);
expect(wrapper.find("button").first().props().disabled).toBeTruthy();
});
});

View File

@ -156,7 +156,7 @@ export class ImageWorkspace extends React.Component<ImageWorkspaceProps, {}> {
className="green fb-button"
title="Scan this image"
onClick={this.maybeProcessPhoto}
disabled={this.props.botOnline}
disabled={!this.props.botOnline}
hidden={!this.props.images.length} >
{t("Scan image")}
</button>