Skip to content

Commit

Permalink
Clean up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jun 26, 2024
1 parent 42a199b commit d35af44
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 137 deletions.
20 changes: 10 additions & 10 deletions src/components/__tests__/BookDetailsEditor-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import BookEditForm from "../BookEditForm";
import ErrorMessage from "../ErrorMessage";

describe("BookDetailsEditor", () => {
let fetchBook;
let fetchBookData;
let fetchRoles;
let fetchMedia;
let fetchLanguages;
let editBook;
let postBookData;
let dispatchProps;

beforeEach(() => {
fetchBook = stub();
fetchBookData = stub();
fetchRoles = stub();
fetchMedia = stub();
fetchLanguages = stub();
editBook = stub();
postBookData = stub();
dispatchProps = {
fetchBook,
fetchBookData,
fetchRoles,
fetchMedia,
fetchLanguages,
editBook,
postBookData,
};
});

Expand All @@ -42,8 +42,8 @@ describe("BookDetailsEditor", () => {
/>
);

expect(fetchBook.callCount).to.equal(1);
expect(fetchBook.args[0][0]).to.equal("admin/works/1234");
expect(fetchBookData.callCount).to.equal(1);
expect(fetchBookData.args[0][0]).to.equal("admin/works/1234");
expect(fetchRoles.callCount).to.equal(1);
expect(fetchMedia.callCount).to.equal(1);
expect(fetchLanguages.callCount).to.equal(1);
Expand All @@ -63,8 +63,8 @@ describe("BookDetailsEditor", () => {
wrapper.setProps({ bookUrl: newPermalink });
wrapper.update();

expect(fetchBook.callCount).to.equal(2);
expect(fetchBook.args[1][0]).to.equal("admin/works/5555");
expect(fetchBookData.callCount).to.equal(2);
expect(fetchBookData.args[1][0]).to.equal("admin/works/5555");
});

it("shows title", () => {
Expand Down
10 changes: 2 additions & 8 deletions src/features/book/bookEditorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,9 @@ const bookEditorSlice = createSlice({
state.editError = null;
})
.addCase(submitBookData.rejected, (state, action) => {
state.isFetching = true;
state.isFetching = false;
state.editError = action.payload as RequestError;
})
.addMatcher(
(action) => true,
(state, action) => {
// console.log("Unhandled action", action.type, {action, state});
}
);
});
},
});

Expand Down
119 changes: 0 additions & 119 deletions src/reducers/__tests__/book-test.ts

This file was deleted.

36 changes: 36 additions & 0 deletions tests/jest/features/book.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,42 @@ describe("Redux bookEditorSlice...", () => {
expect(state.fetchError).to.deep.equal(errorObject);
expect(state.editError).to.be.null;
});

it("should handle submitBookData.pending", () => {
const action = { type: submitBookData.pending.type };
const previousState = { ...fetchedState, isFetching: false };
const state = reducer(previousState, action);

expect(state).to.deep.equal({ ...fetchedState, isFetching: true });
});
it("should handle submitBookData.fulfilled", () => {
const action = {
type: submitBookData.fulfilled.type,
payload: "some value",
};
const previousState = { ...fetchedState, isFetching: true };
const state = reducer(previousState, action);

expect(state).to.deep.equal({
...fetchedState,
isFetching: false,
editError: null,
});
});
it("should handle submitBookData.rejected", () => {
const action = {
type: submitBookData.rejected.type,
payload: "some value",
};
const previousState = { ...fetchedState, isFetching: true };
const state = reducer(previousState, action);

expect(state).to.deep.equal({
...fetchedState,
isFetching: false,
editError: "some value",
});
});
});

describe("thunks...", () => {
Expand Down

0 comments on commit d35af44

Please sign in to comment.