More tests. NEXT: Tests for Actions.FOLDER_SEARCH

folders
Rick Carlino 2019-12-13 13:32:06 -06:00
parent f71ff37caf
commit 6092abc03f
1 changed files with 40 additions and 9 deletions

View File

@ -9,23 +9,23 @@ import {
} from "../../__test_support__/resource_index_builder";
import { Actions } from "../../constants";
const f1 = fakeFolder();
const f2 = fakeFolder({ parent_id: f1.body.id });
const f3 = fakeFolder({ parent_id: f2.body.id });
const f1 = fakeFolder({ name: "@" });
const f2 = fakeFolder({ name: "#", parent_id: f1.body.id });
const f3 = fakeFolder({ name: "$", parent_id: f2.body.id });
function initialState(): RestResources {
return buildResourceIndex([
f1,
f2,
f3,
fakeSequence({ folder_id: f1.body.id }),
fakeSequence({ folder_id: f2.body.id }),
fakeSequence({ folder_id: f3.body.id })
fakeSequence({ name: "%", folder_id: f1.body.id }),
fakeSequence({ name: "^", folder_id: f2.body.id }),
fakeSequence({ name: "&", folder_id: f3.body.id })
]);
}
describe("folder-related reducer functions", () => {
it("toggled a folder's open state", () => {
describe("Actions.FOLDER_TOGGLE", () => {
it("toggles a folder's open state", () => {
const state = initialState();
const id = f1.body.id;
const action = { type: Actions.FOLDER_TOGGLE, payload: { id } };
@ -34,6 +34,37 @@ describe("folder-related reducer functions", () => {
state.index.sequenceFolders.localMetaAttributes[f1.body.id || 0];
const nextOpen = index.sequenceFolders.localMetaAttributes[f1.body.id || 0];
expect(oldOpen).not.toEqual(nextOpen);
expect(oldOpen.open).not.toEqual(nextOpen.open);
});
});
describe("Actions.FOLDER_TOGGLE_ALL", () => {
it("toggles a folder's open state", () => {
const state = initialState();
[true, false].map(payload => {
const action = { type: Actions.FOLDER_TOGGLE_ALL, payload };
const { index } = resourceReducer(state, action);
[f1, f2, f3].map(f => {
const nextOpen = index
.sequenceFolders
.localMetaAttributes[f.body.id || 0];
expect(nextOpen.open).toEqual(payload);
});
});
});
});
describe("Actions.FOLDER_TOGGLE_EDIT", () => {
it("toggles a folder's edit state", () => {
const state = initialState();
const id = f1.body.id;
const action = { type: Actions.FOLDER_TOGGLE_EDIT, payload: { id } };
const { index } = resourceReducer(state, action);
const oldedit =
state.index.sequenceFolders.localMetaAttributes[f1.body.id || 0];
const nextedit = index.sequenceFolders.localMetaAttributes[f1.body.id || 0];
expect(oldedit.editing).not.toEqual(nextedit.editing);
});
});