-
Notifications
You must be signed in to change notification settings - Fork 4
/
bookCoverPreview-test.ts
81 lines (69 loc) · 2.3 KB
/
bookCoverPreview-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { expect } from "chai";
import reducer, { BookCoverPreviewState } from "../bookCoverPreview";
import ActionCreator from "../../actions";
describe("book cover preview reducer", () => {
const preview = "image data";
const initState: BookCoverPreviewState = {
data: null,
isFetching: false,
fetchError: null,
};
const errorState: BookCoverPreviewState = {
data: null,
isFetching: false,
fetchError: { status: 401, response: "test error", url: "test url" },
};
const loadedState = Object.assign({}, initState, {
data: preview,
});
it("returns initial state for unrecognized action", () => {
expect(reducer(undefined, {})).to.deep.equal(initState);
});
it("handles PREVIEW_BOOK_COVER_REQUEST", () => {
const action = {
type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.REQUEST}`,
url: "test url",
};
// start with empty state
let newState = Object.assign({}, initState, {
isFetching: true,
});
expect(reducer(initState, action)).to.deep.equal(newState);
// start with error state
newState = Object.assign({}, errorState, {
isFetching: true,
fetchError: null,
});
expect(reducer(errorState, action)).to.deep.equal(newState);
});
it("handles PREVIEW_BOOK_COVER_FAILURE", () => {
const action = {
type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.FAILURE}`,
error: "test error",
};
const oldState = Object.assign({}, initState, { isFetching: true });
const newState = Object.assign({}, oldState, {
fetchError: "test error",
isFetching: false,
});
expect(reducer(oldState, action)).to.deep.equal(newState);
});
it("handles PREVIEW_BOOK_COVER_LOAD", () => {
const action = {
type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.LOAD}`,
data: preview,
};
const newState = Object.assign({}, initState, {
data: preview,
isFetching: false,
});
expect(reducer(initState, action)).to.deep.equal(newState);
});
it("handles PREVIEW_BOOK_COVER_CLEAR", () => {
const action = {
type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.CLEAR}`,
};
expect(reducer(loadedState, action)).to.deep.equal(initState);
expect(reducer(errorState, action)).to.deep.equal(initState);
});
});