[UNSTABLE] Fix most (not all) failed test examples

pull/1027/head
Rick Carlino 2018-10-29 19:13:41 -05:00
parent 3f300f3122
commit 8a4be67fde
24 changed files with 114 additions and 145 deletions

View File

@ -1,4 +1,3 @@
import { emptyState } from "../resources/reducer_support";
import {
ResourceName,
SpecialStatus,
@ -8,8 +7,8 @@ import {
TaggedResource,
} from "farmbot";
import * as _ from "lodash";
import { Actions } from "../constants";
import { resourceReducer } from "../resources/reducer";
import { resourceReducer, emptyState } from "../resources/reducer";
import { resourceReady } from "../sync/actions";
export function fakeDevice(): TaggedDevice {
return {
"kind": "Device",
@ -325,9 +324,8 @@ export
.groupBy(KIND)
.toPairs()
.map((x: [(TaggedResource["kind"]), TaggedResource[]]) => x)
.map((y: [ResourceName, TaggedResource[]]) => ({
type: Actions.RESOURCE_READY,
payload: { name: y[0], data: y[1].map(x => x.body) }
}))
.map((y: [ResourceName, TaggedResource[]]) => {
return resourceReady((y[0] as any), y[1].map(x => x.body as any));
})
.reduce(resourceReducer, state);
}

View File

@ -1,8 +1,10 @@
import { generateReducer } from "../redux/generate_reducer";
import { Actions } from "../constants";
import { ConnectionState, EdgeStatus, ResourceReady } from "./interfaces";
import { ConnectionState, EdgeStatus } from "./interfaces";
import { computeBestTime } from "./reducer_support";
import { padEnd } from "lodash";
import { TaggedResource } from "farmbot";
import { SyncResponse } from "../sync/actions";
export const DEFAULT_STATE: ConnectionState = {
"bot.mqtt": undefined,
@ -26,11 +28,10 @@ export let connectivityReducer =
s[payload.name] = payload.status;
return s;
})
.add<ResourceReady>(Actions.RESOURCE_READY, (s, a) => {
const isRelevant = a.payload.name === "devices";
if (isRelevant) {
const [d] = a.payload.data;
s["bot.mqtt"] = computeBestTime(s["bot.mqtt"], d && d.last_saw_mq);
.add<SyncResponse<TaggedResource>["payload"]>(Actions.RESOURCE_READY, (s, a) => {
const d = a.payload.body[0];
if (d && a.payload.kind === "Device") {
s["bot.mqtt"] = computeBestTime(s["bot.mqtt"], d && (d as any).last_saw_mq);
}
return s;
})

View File

@ -5,11 +5,11 @@ jest.mock("../../../account/request_account_export", () => {
jest.mock("../../../api/crud", () => {
return { destroy: jest.fn() };
});
import * as React from "react";
import { mount } from "enzyme";
import { DiagnosticDumpRow } from "../diagnostic_dump_row";
import { fakeDiagnosticDump } from "../../../__test_support__/fake_state/resources";
// import { jsonDownload } from "../../../account/request_account_export";
import { destroy } from "../../../api/crud";
describe("<DiagnosticDumpRow/>", () => {
@ -19,8 +19,6 @@ describe("<DiagnosticDumpRow/>", () => {
diag.body.ticket_identifier = "0000";
const el = mount(<DiagnosticDumpRow dispatch={dispatch} diag={diag} />);
expect(el.text()).toContain("0000");
// el.find("button.green").first().simulate("click");
// expect(jsonDownload).toHaveBeenCalledWith(diag.body, "farmbot_diagnostics_0000.json");
el.find("button.red").first().simulate("click");
expect(destroy).toHaveBeenCalledWith(diag.uuid);
});

View File

@ -3,7 +3,7 @@ jest.mock("axios", () => ({ default: { get: mockGet } }));
import { refreshLogs } from "../refresh_logs";
import axios from "axios";
import { API } from "../../api";
import { Actions } from "../../constants";
import { resourceReady } from "../../sync/actions";
describe("refreshLogs", () => {
it("dispatches the appropriate action", async () => {
@ -11,9 +11,7 @@ describe("refreshLogs", () => {
API.setBaseUrl("localhost");
await refreshLogs(dispatch);
expect(axios.get).toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: { data: [], name: "Log" },
type: Actions.RESOURCE_READY
});
expect(dispatch).toHaveBeenCalledWith(resourceReady("Log", []));
});
});

View File

@ -4,15 +4,14 @@ jest.mock("../../revert_to_english", () => {
import { revertToEnglishMiddleware } from "../revert_to_english_middleware";
import { revertToEnglish } from "../../revert_to_english";
import { Actions } from "../../constants";
import { resourceReady } from "../../sync/actions";
import { WebAppConfig } from "farmbot/dist/resources/configs/web_app";
describe("revertToEnglishMiddleware", () => {
it("calls `revertToEnglish` when appropriate", () => {
const dispatch = jest.fn(() => ({}));
const action = {
type: Actions.RESOURCE_READY,
payload: { name: "WebAppConfig", data: { disable_i18n: true } }
};
const data = { disable_i18n: true } as WebAppConfig;
const action = resourceReady("WebAppConfig", data);
expect(revertToEnglish).not.toHaveBeenCalled();
// tslint:disable-next-line:no-any
revertToEnglishMiddleware.fn({} as any)(dispatch)(action);

View File

@ -2,9 +2,6 @@ import {
buildResourceIndex, fakeDevice
} from "../../__test_support__/resource_index_builder";
import * as Selector from "../selectors";
import {
emptyState
} from "../reducer_support";
import {
TaggedTool,
TaggedToolSlotPointer,
@ -16,9 +13,9 @@ import {
fakeWebcamFeed,
fakeSequence
} from "../../__test_support__/fake_state/resources";
import { Actions } from "../../constants";
import * as _ from "lodash";
import { resourceReducer } from "../reducer";
import { resourceReducer, emptyState } from "../reducer";
import { resourceReady } from "../../sync/actions";
const TOOL_ID = 99;
const SLOT_ID = 100;
@ -75,13 +72,10 @@ describe("getFeeds", () => {
it("finds the only WebcamFeed", () => {
const feed = fakeWebcamFeed();
const state = [{
type: Actions.RESOURCE_READY,
payload: {
name: "WebcamFeed",
data: feed
}
}].reduce(resourceReducer, emptyState());
const state = [
resourceReady("WebcamFeed", feed.body)
].reduce(resourceReducer, emptyState());
expect(Selector.selectAllWebcamFeeds(state.index)[0].body).toEqual(feed);
});
});

View File

@ -3,11 +3,11 @@ import {
initResourceReducer,
mutateSpecialStatus,
afterEach,
emptyState,
} from "./reducer_support";
import {
defensiveClone,
equals
equals,
betterCompact
} from "../util";
import { generateReducer } from "../redux/generate_reducer";
import { RestResources, ResourceIndex } from "./interfaces";
@ -36,6 +36,56 @@ export function indexRemove(db: ResourceIndex, resources: TaggedResource | Tagge
arrayWrap(resources).map(resource => callback(resource, db));
});
}
import { initialState as regimenState } from "../regimens/reducer";
import { initialState as sequenceState } from "../sequences/reducer";
import { farmwareState } from "../farmware/reducer";
import { initialState as designerState } from "../farm_designer/reducer";
import { initialState as helpState } from "../help/reducer";
export const emptyState =
(): RestResources => {
return {
consumers: {
sequences: sequenceState,
regimens: regimenState,
farm_designer: designerState,
farmware: farmwareState,
help: helpState,
},
loaded: [],
index: {
all: [],
byKind: {
WebcamFeed: [],
Device: [],
FarmEvent: [],
Image: [],
Plant: [],
Log: [],
Peripheral: [],
Crop: [],
Point: [],
Regimen: [],
Sequence: [],
Tool: [],
User: [],
FbosConfig: [],
FirmwareConfig: [],
WebAppConfig: [],
SensorReading: [],
Sensor: [],
FarmwareInstallation: [],
FarmwareEnv: [],
PinBinding: [],
PlantTemplate: [],
SavedGarden: [],
DiagnosticDump: []
},
byKindAndId: {},
references: {}
}
};
};
/** Responsible for all RESTful resources. */
export let resourceReducer =
@ -62,20 +112,15 @@ export let resourceReducer =
})
.add<SyncResponse<TaggedResource>["payload"]>(Actions.RESOURCE_READY, (s, { payload }) => {
!s.loaded.includes(payload.kind) && s.loaded.push(payload.kind);
arrayWrap(payload.body).map(body => {
try {
const x = {
kind: payload.kind,
uuid: generateUuid(body.id, payload.kind),
specialStatus: SpecialStatus.SAVED,
body
};
if (isTaggedResource(x)) {
indexUpsert(s.index, x);
}
} catch (error) {
debugger;
betterCompact(arrayWrap(payload.body)).map(body => {
const x = {
kind: payload.kind,
uuid: generateUuid(body.id, payload.kind),
specialStatus: SpecialStatus.SAVED,
body
};
if (isTaggedResource(x)) {
indexUpsert(s.index, x);
}
});
return s;

View File

@ -1,81 +1,14 @@
import { RestResources, ResourceIndex } from "./interfaces";
import {
TaggedResource,
ResourceName,
SpecialStatus,
} from "farmbot";
import {
isTaggedResource,
} from "./tagged_resources";
import {
initialState as sequenceState,
sequenceReducer as sequences,
} from "../sequences/reducer";
import {
initialState as regimenState,
regimensReducer as regimens
} from "../regimens/reducer";
import { ResourceName, SpecialStatus, TaggedResource } from "farmbot";
import { combineReducers } from "redux";
import { farmwareReducer as farmware } from "../farmware/reducer";
import { designer as farm_designer } from "../farm_designer/reducer";
import { helpReducer as help } from "../help/reducer";
import { ReduxAction } from "../redux/interfaces";
import {
designer as farm_designer,
initialState as designerState
} from "../farm_designer/reducer";
import {
farmwareReducer as farmware,
farmwareState
} from "../farmware/reducer";
import {
helpReducer as help,
initialState as helpState
} from "../help/reducer";
import { regimensReducer as regimens } from "../regimens/reducer";
import { sequenceReducer as sequences } from "../sequences/reducer";
import { ResourceIndex, RestResources } from "./interfaces";
import { indexUpsert } from "./reducer";
export function emptyState(): RestResources {
return {
consumers: {
sequences: sequenceState,
regimens: regimenState,
farm_designer: designerState,
farmware: farmwareState,
help: helpState,
},
loaded: [],
index: {
all: [],
byKind: {
WebcamFeed: [],
Device: [],
FarmEvent: [],
Image: [],
Plant: [],
Log: [],
Peripheral: [],
Crop: [],
Point: [],
Regimen: [],
Sequence: [],
Tool: [],
User: [],
FbosConfig: [],
FirmwareConfig: [],
WebAppConfig: [],
SensorReading: [],
Sensor: [],
FarmwareInstallation: [],
FarmwareEnv: [],
PinBinding: [],
PlantTemplate: [],
SavedGarden: [],
DiagnosticDump: []
},
byKindAndId: {},
references: {}
}
};
}
export const initialState: RestResources = emptyState();
import { isTaggedResource } from "./tagged_resources";
export function joinKindAndId(kind: ResourceName, id: number | undefined) {
return `${kind}.${id || 0}`;

View File

@ -3,9 +3,9 @@ import { TileExecuteScript } from "../tile_execute_script";
import { mount, shallow } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { ExecuteScript } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { StepParams } from "../../interfaces";
import { Actions } from "../../../constants";
import { emptyState } from "../../../resources/reducer";
describe("<TileExecuteScript/>", () => {
const fakeProps = (): StepParams => {

View File

@ -8,8 +8,8 @@ import {
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { Execute, Point, Identifier, Coordinate, Tool } from "farmbot";
import { emptyState } from "../../../resources/reducer_support";
import { Actions } from "../../../constants";
import { emptyState } from "../../../resources/reducer";
function fakeProps(): ExecBlockParams {
const currentStep: Execute = {

View File

@ -3,11 +3,11 @@ import { TileFindHome, FindHomeParams } from "../tile_find_home";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { FindHome } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import {
fakeHardwareFlags
} from "../../../__test_support__/sequence_hardware_settings";
import { HardwareFlags } from "../../interfaces";
import { emptyState } from "../../../resources/reducer";
describe("<TileFindHome/>", () => {
const fakeProps = (): FindHomeParams => {

View File

@ -3,7 +3,7 @@ import { TileIf } from "../tile_if";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { If } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileIf/>", () => {
function bootstrapTest() {

View File

@ -3,10 +3,10 @@ import { TileMoveAbsolute } from "../tile_move_absolute";
import { mount, ReactWrapper } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { MoveAbsolute, SequenceBodyItem } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { buildResourceIndex } from "../../../__test_support__/resource_index_builder";
import { SpecialStatus } from "farmbot";
import { fakeHardwareFlags } from "../../../__test_support__/sequence_hardware_settings";
import { emptyState } from "../../../resources/reducer";
describe("<TileMoveAbsolute/>", () => {
const fakeProps = () => {

View File

@ -3,7 +3,7 @@ import { TileMoveRelative } from "../tile_move_relative";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { MoveRelative } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileMoveRelative/>", () => {
function bootstrapTest() {

View File

@ -13,7 +13,7 @@ import {
} from "../tile_pin_support";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { WritePin } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("Pin tile support functions", () => {
function fakeProps() {

View File

@ -3,7 +3,7 @@ import { TileReadPin } from "../tile_read_pin";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { ReadPin } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileReadPin/>", () => {
function bootstrapTest() {

View File

@ -3,8 +3,8 @@ import { TileSendMessage, RefactoredSendMessage } from "../tile_send_message";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { SendMessage, Channel } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { channel } from "../tile_send_message_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileSendMessage/>", () => {
function props() {

View File

@ -3,8 +3,8 @@ import { TileTakePhoto } from "../tile_take_photo";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { TakePhoto } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { StepParams } from "../../interfaces";
import { emptyState } from "../../../resources/reducer";
describe("<TileTakePhoto/>", () => {
const currentStep: TakePhoto = {

View File

@ -3,7 +3,7 @@ import { TileWait } from "../tile_wait";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { Wait } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileWait/>", () => {
function bootstrapTest() {

View File

@ -3,7 +3,7 @@ import { TileWritePin } from "../tile_write_pin";
import { mount } from "enzyme";
import { fakeSequence } from "../../../__test_support__/fake_state/resources";
import { WritePin } from "farmbot/dist";
import { emptyState } from "../../../resources/reducer_support";
import { emptyState } from "../../../resources/reducer";
describe("<TileWritePin/>", () => {
function fakeProps() {

View File

@ -3,8 +3,8 @@ import { Else } from "../else";
import { mount } from "enzyme";
import { fakeSequence } from "../../../../__test_support__/fake_state/resources";
import { If } from "farmbot/dist";
import { emptyState } from "../../../../resources/reducer_support";
import { IfParams } from "../index";
import { emptyState } from "../../../../resources/reducer";
describe("<Else/>", () => {
function fakeProps(): IfParams {

View File

@ -3,8 +3,8 @@ import { If_ } from "../if";
import { mount } from "enzyme";
import { fakeSequence } from "../../../../__test_support__/fake_state/resources";
import { If } from "farmbot/dist";
import { emptyState } from "../../../../resources/reducer_support";
import { IfParams } from "../index";
import { emptyState } from "../../../../resources/reducer";
describe("<If_/>", () => {
function fakeProps(): IfParams {

View File

@ -3,8 +3,8 @@ import { Then } from "../then";
import { mount } from "enzyme";
import { fakeSequence } from "../../../../__test_support__/fake_state/resources";
import { If } from "farmbot/dist";
import { emptyState } from "../../../../resources/reducer_support";
import { IfParams } from "../index";
import { emptyState } from "../../../../resources/reducer";
describe("<Then/>", () => {
function fakeProps(): IfParams {

View File

@ -6,7 +6,10 @@ import { Session } from "../session";
export interface SyncResponse<T extends TaggedResource> {
type: Actions.RESOURCE_READY;
payload: { kind: T["kind"]; body: T["body"] | T["body"][]; }
payload: {
kind: T["kind"];
body: T["body"][];
}
}
export const resourceReady =