TODO: Fix Actions.FOLDER_SEARCH problems.

folders
Rick Carlino 2019-12-10 12:52:48 -06:00
parent e26d8e870f
commit c47651282f
3 changed files with 39 additions and 31 deletions

View File

@ -1,5 +1,8 @@
import {
fakeFbosConfig, fakeImage, fakeFarmwareEnv, fakeWebAppConfig
fakeFbosConfig,
fakeImage,
fakeFarmwareEnv,
fakeWebAppConfig
} from "../../__test_support__/fake_state/resources";
let mockFbosConfig: TaggedFbosConfig | undefined = fakeFbosConfig();
@ -12,6 +15,8 @@ jest.mock("../../resources/selectors_by_kind", () => ({
selectAllRegimens: () => [],
selectAllLogs: () => [],
selectAllImages: () => [mockImages],
selectAllFolders: () => [],
selectAllSequences: () => [],
selectAllFarmwareEnvs: () => [fakeFarmwareEnv()]
}));
@ -48,7 +53,7 @@ describe("mapStateToProps()", () => {
});
});
it("uses the bot as the source of FBOS settings: ignore API defaults", () => {
fit("uses the bot as the source of FBOS settings: ignore API defaults", () => {
const state = fakeState();
state.bot.hardware.configuration.auto_sync = false;
const fakeApiConfig = fakeFbosConfig();

View File

@ -5,25 +5,28 @@ import { draggableReducer as draggable } from "../draggable/reducer";
import { combineReducers } from "redux";
import { ReduxAction } from "./interfaces";
import { Session } from "../session";
import { resourceReducer as resources } from "../resources/reducer";
import { resourceReducer } from "../resources/reducer";
import { Everything } from "../interfaces";
import { Actions } from "../constants";
export let reducers = combineReducers({
const reducerRecord = {
auth,
bot,
config,
draggable,
resources,
});
resources: resourceReducer,
};
export let reducers = combineReducers(reducerRecord);
Object.keys(reducerRecord).map((x: keyof typeof reducerRecord) => {
if (!reducerRecord[x]) {
throw new Error(`The ${x} reducer is missing. Most likely, a mock is misconfigured`);
}
});
/** This is the topmost reducer in the application. If you need to preempt a
* "normal" reducer this is the place to do it */
export function rootReducer(
/** Sorry for the `any` here. */
state: Everything,
action: ReduxAction<{}>) {
export function rootReducer(state: Everything, action: ReduxAction<{}>) {
(action.type === Actions.LOGOUT) && Session.clear();
return reducers(state, action);
}

View File

@ -24,8 +24,8 @@ import { farmwareState } from "../farmware/reducer";
import { initialState as regimenState } from "../regimens/reducer";
import { initialState as sequenceState } from "../sequences/reducer";
import { initialState as alertState } from "../messages/reducer";
import { searchFoldersAndSequencesForTerm } from "../folders/actions";
import { ingest } from "../folders/data_transfer";
// import { searchFoldersAndSequencesForTerm } from "../folders/actions";
// import { ingest } from "../folders/data_transfer";
export const emptyState = (): RestResources => {
return {
@ -91,7 +91,7 @@ export const emptyState = (): RestResources => {
};
/** Responsible for all RESTful resources. */
export let resourceReducer =
export const resourceReducer =
generateReducer<RestResources>(emptyState())
.beforeEach(beforeEach)
.afterEach(afterEach)
@ -185,22 +185,22 @@ export let resourceReducer =
return s;
})
.add<string | undefined>(Actions.FOLDER_SEARCH, (s, { payload }) => {
s.index.sequenceFolders.searchTerm = payload;
if (payload && payload.length > 2) {
const folders = searchFoldersAndSequencesForTerm({
references: s.index.references,
input: payload,
root: s.index.sequenceFolders.folders
});
const nextFolder = ingest({
localMetaAttributes: s.index.sequenceFolders.localMetaAttributes,
folders
});
s.index.sequenceFolders.filteredFolders = nextFolder;
} else {
s.index.sequenceFolders.filteredFolders = undefined;
}
reindexFolders(s.index);
.add<string | undefined>(Actions.FOLDER_SEARCH, (s/*, { payload }*/) => {
// s.index.sequenceFolders.searchTerm = payload;
// if (payload && payload.length > 2) {
// const folders = searchFoldersAndSequencesForTerm({
// references: s.index.references,
// input: payload,
// root: s.index.sequenceFolders.folders
// });
// const nextFolder = ingest({
// localMetaAttributes: s.index.sequenceFolders.localMetaAttributes,
// folders
// });
// s.index.sequenceFolders.filteredFolders = nextFolder;
// } else {
// s.index.sequenceFolders.filteredFolders = undefined;
// }
// reindexFolders(s.index);
return s;
});