diff --git a/src/__tests__/actions-test.ts b/src/__tests__/actions-test.ts index e60107b7a..6db166a8c 100644 --- a/src/__tests__/actions-test.ts +++ b/src/__tests__/actions-test.ts @@ -293,33 +293,6 @@ describe("actions", () => { }); }); - // TODO: add tests for editBook actions - // describe("editBook", () => { - // it("dispatches request and success", async () => { - // const editBookUrl = "http://example.com/editBook"; - // const dispatch = stub(); - // const formData = new (window as any).FormData(); - // formData.append("title", "title"); - // - // fetchMock.post(editBookUrl, "done"); - // - // await actions.editBook(editBookUrl, formData)(dispatch); - // const fetchArgs = fetchMock.calls(); - // - // expect(dispatch.callCount).to.equal(3); - // expect(dispatch.args[0][0].type).to.equal( - // ActionCreator.EDIT_BOOK_REQUEST - // ); - // expect(dispatch.args[1][0].type).to.equal( - // ActionCreator.EDIT_BOOK_SUCCESS - // ); - // expect(fetchMock.called()).to.equal(true); - // expect(fetchArgs[0][0]).to.equal(editBookUrl); - // expect(fetchArgs[0][1].method).to.equal("POST"); - // expect(fetchArgs[0][1].body).to.equal(formData); - // }); - // }); - describe("fetchComplaints", () => { it("dispatches request, load, and success", async () => { const dispatch = stub(); diff --git a/src/components/BookDetailsTabContainer.tsx b/src/components/BookDetailsTabContainer.tsx index 76103f36f..1c5cdd9c9 100644 --- a/src/components/BookDetailsTabContainer.tsx +++ b/src/components/BookDetailsTabContainer.tsx @@ -7,10 +7,8 @@ import BookDetailsEditor from "./BookDetailsEditor"; import Classifications from "./Classifications"; import BookCoverEditor from "./BookCoverEditor"; import CustomListsForBook from "./CustomListsForBook"; -import { BookData } from "../interfaces"; import { TabContainer, TabContainerProps } from "./TabContainer"; import { RootState } from "../store"; -import { Store } from "@reduxjs/toolkit"; interface BookDetailsTabContainerOwnProps extends TabContainerProps { bookUrl: string; @@ -45,9 +43,6 @@ export class BookDetailsTabContainer extends TabContainer< BookDetailsTabContainerProps > { componentWillUnmount() { - console.log( - "\n\nUnmounting BookDetailsTabContainer... and clearing book data\n\n" - ); this.props.clearBook(); } diff --git a/src/components/ClassificationsForm.tsx b/src/components/ClassificationsForm.tsx index 99e5c1069..7e3f17d23 100644 --- a/src/components/ClassificationsForm.tsx +++ b/src/components/ClassificationsForm.tsx @@ -236,7 +236,7 @@ export default class ClassificationsForm extends React.Component< newBook.targetAgeRange[0] !== this.props.book.targetAgeRange[0] || newBook.targetAgeRange[1] !== this.props.book.targetAgeRange[1] || newBook.fiction !== this.props.book.fiction || - new Set(newBook.categories) !== new Set(this.props.book.categories) + newBook.categories.sort() !== this.props.book.categories.sort() ); } diff --git a/src/components/__tests__/ClassificationsForm-test.tsx b/src/components/__tests__/ClassificationsForm-test.tsx index 7300d5da4..56f17766e 100644 --- a/src/components/__tests__/ClassificationsForm-test.tsx +++ b/src/components/__tests__/ClassificationsForm-test.tsx @@ -402,15 +402,14 @@ describe("ClassificationsForm", () => { expect(wrapper.state("genres")).to.deep.equal(["Cooking"]); }); - // TODO: Fix this test - // it("doesn't update state upon receiving new state-unrelated props", () => { - // // state updated with new form inputs - // wrapper.setState({ fiction: false, genres: ["Cooking"] }); - // // form submitted, disabling form - // wrapper.setProps({ disabled: true }); - // // state should not change back to earlier book props - // expect(wrapper.state("fiction")).to.equal(false); - // expect(wrapper.state("genres")).to.deep.equal(["Cooking"]); - // }); + it("doesn't update state upon receiving new state-unrelated props", () => { + // state updated with new form inputs + wrapper.setState({ fiction: false, genres: ["Cooking"] }); + // form submitted, disabling form + wrapper.setProps({ disabled: true }); + // state should not change back to earlier book props + expect(wrapper.state("fiction")).to.equal(false); + expect(wrapper.state("genres")).to.deep.equal(["Cooking"]); + }); }); }); diff --git a/src/features/apiSlice.ts b/src/features/apiSlice.ts deleted file mode 100644 index 24695683f..000000000 --- a/src/features/apiSlice.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; - -// export const api = createApi({ -// baseQuery: fetchBaseQuery({ -// baseUrl: "" -// }), -// endpoints: (builder) => ({ -// -// }, -// }); diff --git a/src/features/book/bookEditorSlice.ts b/src/features/book/bookEditorSlice.ts index a4b10cf2d..d8848e5c1 100644 --- a/src/features/book/bookEditorSlice.ts +++ b/src/features/book/bookEditorSlice.ts @@ -39,14 +39,9 @@ const bookEditorSlice = createSlice({ builder .addCase(ActionCreator.BOOK_CLEAR, (state, action) => { // Handle resetting the book data via actions from the web-opds-client. - console.log("*** Handling clear book data action ***", action.type, { - action, - state, - }); return initialState; }) .addCase(getBookData.pending, (state, action) => { - // console.log("getBookData.pending", { action, state }); const { url } = action.meta.arg; state.url = url; state.data = null; diff --git a/src/reducers/book.ts b/src/reducers/book.ts deleted file mode 100644 index 48ecca028..000000000 --- a/src/reducers/book.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { BookData } from "../interfaces"; -import { RequestError } from "@thepalaceproject/web-opds-client/lib/DataFetcher"; -import ActionCreator from "../actions"; - -export interface BookState { - url: string; - data: BookData; - isFetching: boolean; - fetchError: RequestError; - editError: RequestError; -} - -const initialState: BookState = { - url: null, - data: null, - isFetching: false, - fetchError: null, - editError: null, -}; - -export default (state: BookState = initialState, action) => { - switch (action.type) { - // case ActionCreator.BOOK_ADMIN_REQUEST: - // return Object.assign({}, state, { - // url: action.url, - // isFetching: true, - // fetchError: null, - // editError: null, - // }); - - // case ActionCreator.BOOK_ADMIN_LOAD: - // return Object.assign({}, state, { - // url: action.url, - // data: action.data, - // isFetching: false, - // }); - - // case ActionCreator.BOOK_ADMIN_FAILURE: - // return Object.assign({}, state, { - // fetchError: action.error, - // isFetching: false, - // }); - - // case ActionCreator.BOOK_CLEAR: - // return initialState; - // - // case ActionCreator.EDIT_BOOK_REQUEST: - // return Object.assign({}, state, { - // isFetching: true, - // editError: null, - // }); - // - // case ActionCreator.EDIT_BOOK_FAILURE: - // return Object.assign({}, state, { - // editError: action.error, - // isFetching: false, - // }); - - default: - return state; - } -}; diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 4ebf606f9..e766a191a 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -1,5 +1,4 @@ import { combineReducers } from "redux"; -import book, { BookState } from "./book"; import complaints, { ComplaintsState } from "./complaints"; import classifications, { ClassificationsState } from "./classifications"; import bookCoverPreview, { BookCoverPreviewState } from "./bookCoverPreview"; @@ -62,7 +61,6 @@ import { } from "../interfaces"; export interface State { - book: BookState; complaints: ComplaintsState; classifications: ClassificationsState; bookCoverPreview: BookCoverPreviewState; @@ -101,7 +99,6 @@ export interface State { } export default combineReducers({ - book, complaints, classifications, bookCoverPreview, diff --git a/tests/jest/features/book.test.ts b/tests/jest/features/book.test.ts index 311b52bfc..a3249d9d1 100644 --- a/tests/jest/features/book.test.ts +++ b/tests/jest/features/book.test.ts @@ -70,6 +70,7 @@ describe("Redux bookEditorSlice...", () => { ); }); it("should handle BOOK_CLEAR", () => { + // This is dispatched by `web-opds`client`, but we need to handle it, too. const action = { type: ActionCreator.BOOK_CLEAR }; expect(reducer(fetchedState, action)).to.deep.equal(initialState); @@ -285,14 +286,6 @@ describe("Redux bookEditorSlice...", () => { detail: "There was an error saving your changes.", }; - // it("handles EDIT_BOOK_REQUEST", () => { - // const action = { type: ActionCreator.EDIT_BOOK_REQUEST }; - // const newState = Object.assign({}, fetchedState, { - // isFetching: true, - // }); - // expect(book(fetchedState, action)).to.deep.equal(newState); - // }); - const dispatch = jest.fn(); const getState = jest.fn().mockReturnValue({ bookEditor: initialState,