Skip to content

Commit

Permalink
Code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jun 26, 2024
1 parent d35af44 commit 7165959
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 131 deletions.
27 changes: 0 additions & 27 deletions src/__tests__/actions-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/components/BookDetailsTabContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/ClassificationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
19 changes: 9 additions & 10 deletions src/components/__tests__/ClassificationsForm-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
});
});
});
10 changes: 0 additions & 10 deletions src/features/apiSlice.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/features/book/bookEditorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 0 additions & 62 deletions src/reducers/book.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/reducers/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -62,7 +61,6 @@ import {
} from "../interfaces";

export interface State {
book: BookState;
complaints: ComplaintsState;
classifications: ClassificationsState;
bookCoverPreview: BookCoverPreviewState;
Expand Down Expand Up @@ -101,7 +99,6 @@ export interface State {
}

export default combineReducers<State>({
book,
complaints,
classifications,
bookCoverPreview,
Expand Down
9 changes: 1 addition & 8 deletions tests/jest/features/book.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7165959

Please sign in to comment.