Remove irrelevant tests
parent
19eb8dfe62
commit
1deda97e87
|
@ -343,7 +343,7 @@ type ResourceLookupTable = Record<TaggedResource["kind"], ResourceGroupNumber>;
|
|||
|
||||
/** In the real app, resources are loaded in a particular order.
|
||||
* This table serves as a reference to prevent referential integrity issues. */
|
||||
const GROUPS: ResourceLookupTable = {
|
||||
const KIND_PRIORITY: ResourceLookupTable = {
|
||||
// GROUP 0
|
||||
Device: 0,
|
||||
FarmwareEnv: 0,
|
||||
|
@ -376,12 +376,12 @@ const GROUPS: ResourceLookupTable = {
|
|||
export function buildResourceIndex(resources: TaggedResource[] = FAKE_RESOURCES,
|
||||
state = emptyState()) {
|
||||
const sortedResources = repairBrokeReferences(resources)
|
||||
.sort((l, r) => c3(GROUPS[l.kind], GROUPS[r.kind]));
|
||||
type K = keyof typeof GROUPS;
|
||||
.sort((l, r) => c3(KIND_PRIORITY[l.kind], KIND_PRIORITY[r.kind]));
|
||||
type K = keyof typeof KIND_PRIORITY;
|
||||
return _(sortedResources)
|
||||
.groupBy(KIND)
|
||||
.toPairs()
|
||||
.sort((l, r) => c3(GROUPS[l[0] as K || 4], GROUPS[r[0] as K || 4]))
|
||||
.sort((l, r) => c3(KIND_PRIORITY[l[0] as K || 4], KIND_PRIORITY[r[0] as K || 4]))
|
||||
.map((x: [TaggedResource["kind"], TaggedResource[]]) => x)
|
||||
.map((y) => resourceReady(y[0], y[1]))
|
||||
.reduce(resourceReducer, state);
|
||||
|
|
|
@ -3,7 +3,7 @@ jest.mock("i18next", () => ({ t: (i: string) => i }));
|
|||
import { commitBulkEditor, setTimeOffset, toggleDay, setSequence } from "../actions";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
import { buildResourceIndex } from "../../../__test_support__/resource_index_builder";
|
||||
import { TaggedResource } from "farmbot";
|
||||
import { TaggedResource, TaggedSequence, TaggedRegimen } from "farmbot";
|
||||
import { Actions } from "../../../constants";
|
||||
import { Everything } from "../../../interfaces";
|
||||
import { ToggleDayParams } from "../interfaces";
|
||||
|
@ -11,39 +11,33 @@ import { error, warning } from "farmbot-toastr";
|
|||
import { newTaggedResource } from "../../../sync/actions";
|
||||
import { arrayUnwrap } from "../../../resources/util";
|
||||
|
||||
const sequence_id = 23;
|
||||
const regimen_id = 32;
|
||||
describe("commitBulkEditor()", () => {
|
||||
function newFakeState() {
|
||||
const state = fakeState();
|
||||
const fakeResources: TaggedResource[] = [
|
||||
arrayUnwrap(newTaggedResource("Regimen", {
|
||||
"id": 1,
|
||||
"name": "Test Regimen",
|
||||
"color": "gray",
|
||||
"regimen_items": [
|
||||
{
|
||||
"id": 1,
|
||||
"regimen_id": 1,
|
||||
"sequence_id": 1,
|
||||
"time_offset": 1000
|
||||
}
|
||||
]
|
||||
})),
|
||||
arrayUnwrap(newTaggedResource("Sequence", {
|
||||
"id": 1,
|
||||
"name": "Test Sequence",
|
||||
"color": "gray",
|
||||
"body": [{ kind: "wait", args: { milliseconds: 100 } }],
|
||||
"args": {
|
||||
"locals": { kind: "scope_declaration", args: {} },
|
||||
"version": 4
|
||||
},
|
||||
"kind": "sequence"
|
||||
}))
|
||||
];
|
||||
const regBody: TaggedRegimen["body"] = {
|
||||
"id": regimen_id,
|
||||
"name": "Test Regimen",
|
||||
"color": "gray",
|
||||
"regimen_items": [
|
||||
{ regimen_id, sequence_id, time_offset: 1000 }
|
||||
]
|
||||
};
|
||||
const reg = newTaggedResource("Regimen", regBody)[0];
|
||||
const seqBody: TaggedSequence["body"] = {
|
||||
"id": sequence_id,
|
||||
"name": "Test Sequence",
|
||||
"color": "gray",
|
||||
"body": [{ kind: "wait", args: { milliseconds: 100 } }],
|
||||
"args": { "locals": { kind: "scope_declaration", args: {} }, "version": 4 },
|
||||
"kind": "sequence"
|
||||
};
|
||||
const seq = arrayUnwrap(newTaggedResource("Sequence", seqBody));
|
||||
const regimenUuid = seq.uuid;
|
||||
const sequenceUuid = reg.uuid;
|
||||
const fakeResources: TaggedResource[] = [reg, seq];
|
||||
state.resources.index = buildResourceIndex(fakeResources).index;
|
||||
const all = Object.keys(state.resources.index.all);
|
||||
const regimenUuid = all[0];
|
||||
const sequenceUuid = all[1];
|
||||
|
||||
state.resources.consumers.regimens.currentRegimen = regimenUuid;
|
||||
state.resources.consumers.regimens.selectedSequenceUUID = sequenceUuid;
|
||||
|
@ -106,12 +100,16 @@ describe("commitBulkEditor()", () => {
|
|||
const getState = () => state;
|
||||
const dispatch = jest.fn();
|
||||
commitBulkEditor()(dispatch, getState);
|
||||
const expected = [
|
||||
{ id: 1, regimen_id, sequence_id, time_offset: 1000 },
|
||||
{ sequence_id, time_offset: 2000 }
|
||||
];
|
||||
const actual = dispatch.mock.calls[0][0].payload.update.regimen_items;
|
||||
console.dir(actual);
|
||||
expect(dispatch).toHaveBeenCalledWith({
|
||||
payload: expect.objectContaining({
|
||||
update: expect.objectContaining({
|
||||
regimen_items: [
|
||||
{ id: 1, regimen_id: 1, sequence_id: 1, time_offset: 1000 },
|
||||
{ sequence_id: 1, time_offset: 2000 }]
|
||||
regimen_items: expect.arrayContaining(expected)
|
||||
}),
|
||||
}),
|
||||
type: Actions.OVERWRITE_RESOURCE
|
||||
|
|
|
@ -13,8 +13,7 @@ import { GeneralizedError } from "../actions";
|
|||
import { Actions } from "../../constants";
|
||||
import { fakeResource } from "../../__test_support__/fake_resource";
|
||||
import { resourceReducer } from "../reducer";
|
||||
import { joinKindAndId, findByUuid } from "../reducer_support";
|
||||
import { resourceReady } from "../../sync/actions";
|
||||
import { findByUuid } from "../reducer_support";
|
||||
import { EditResourceParams } from "../../api/interfaces";
|
||||
|
||||
describe("resource reducer", () => {
|
||||
|
@ -65,20 +64,6 @@ describe("resource reducer", () => {
|
|||
"DiagnosticDump", "FarmEvent", "FarmwareInstallation", "FbosConfig",
|
||||
"FirmwareConfig", "Log", "Peripheral", "PinBinding", "PlantTemplate",
|
||||
"Point", "Regimen", "SavedGarden", "Sensor"];
|
||||
let id = 1;
|
||||
|
||||
it("covers save resource branches", () => {
|
||||
const testResource = (kind: TaggedResource["kind"]) => {
|
||||
const resource: TaggedResource = fakeResource(kind, { id: ++id });
|
||||
const action = resourceReady(resource.kind, [resource]);
|
||||
const newState = resourceReducer(fakeState().resources, action);
|
||||
const uuid = newState.index.byKindAndId[joinKindAndId(kind, resource.body.id)];
|
||||
const expectation = newState.index.references[uuid || "?"];
|
||||
|
||||
expect(expectation).toEqual(resource);
|
||||
};
|
||||
TEST_RESOURCE_NAMES.map(kind => testResource(kind));
|
||||
});
|
||||
|
||||
it("EDITs a _RESOURCE", () => {
|
||||
const startingState = fakeState().resources;
|
||||
|
|
Loading…
Reference in New Issue