-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathslice.test.ts
More file actions
136 lines (120 loc) · 3.95 KB
/
slice.test.ts
File metadata and controls
136 lines (120 loc) · 3.95 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import {
configureStore,
type EnhancedStore,
type StoreEnhancer,
type ThunkDispatch,
type Tuple,
type UnknownAction,
} from '@reduxjs/toolkit';
import {
CourseOptimizerState,
reducer,
updateLinkCheckInProgress,
updateLinkCheckResult,
updateLastScannedAt,
updateCurrentStage,
updateDownloadPath,
updateSuccessDate,
updateError,
updateIsErrorModalOpen,
reset,
updateLoadingStatus,
updateSavingStatus,
updateRerunLinkUpdateInProgress,
updateRerunLinkUpdateResult,
} from './slice';
describe('courseOptimizer slice', () => {
let store: EnhancedStore<CourseOptimizerState, UnknownAction, Tuple<[StoreEnhancer<{
dispatch: ThunkDispatch<CourseOptimizerState, undefined, UnknownAction>;
}>, StoreEnhancer]>>;
beforeEach(() => {
store = configureStore({ reducer });
});
it('should handle initial state', () => {
expect(store.getState()).toEqual({
linkCheckInProgress: null,
linkCheckResult: null,
lastScannedAt: null,
currentStage: null,
error: { msg: null, unitUrl: null },
downloadPath: null,
successDate: null,
isErrorModalOpen: false,
loadingStatus: '',
rerunLinkUpdateInProgress: null,
rerunLinkUpdateResult: null,
savingStatus: '',
});
});
it('should handle updateLinkCheckInProgress', () => {
store.dispatch(updateLinkCheckInProgress(true));
expect(store.getState().linkCheckInProgress).toBe(true);
});
it('should handle updateLinkCheckResult', () => {
const result = { valid: true };
store.dispatch(updateLinkCheckResult(result));
expect(store.getState().linkCheckResult).toEqual(result);
});
it('should handle updateLastScannedAt', () => {
const date = '2023-10-01';
store.dispatch(updateLastScannedAt(date));
expect(store.getState().lastScannedAt).toBe(date);
});
it('should handle updateCurrentStage', () => {
store.dispatch(updateCurrentStage(2));
expect(store.getState().currentStage).toBe(2);
});
it('should handle updateDownloadPath', () => {
const path = '/path/to/download';
store.dispatch(updateDownloadPath(path));
expect(store.getState().downloadPath).toBe(path);
});
it('should handle updateSuccessDate', () => {
const date = '2023-10-01';
store.dispatch(updateSuccessDate(date));
expect(store.getState().successDate).toBe(date);
});
it('should handle updateError', () => {
const error = { msg: 'Error message', unitUrl: 'http://example.com' };
store.dispatch(updateError(error));
expect(store.getState().error).toEqual(error);
});
it('should handle updateIsErrorModalOpen', () => {
store.dispatch(updateIsErrorModalOpen(true));
expect(store.getState().isErrorModalOpen).toBe(true);
});
it('should handle reset', () => {
store.dispatch(reset());
expect(store.getState()).toEqual({
linkCheckInProgress: null,
linkCheckResult: null,
lastScannedAt: null,
currentStage: null,
error: { msg: null, unitUrl: null },
downloadPath: null,
successDate: null,
isErrorModalOpen: false,
loadingStatus: '',
rerunLinkUpdateInProgress: null,
rerunLinkUpdateResult: null,
savingStatus: '',
});
});
it('should handle updateLoadingStatus', () => {
store.dispatch(updateLoadingStatus({ status: 'loading' }));
expect(store.getState().loadingStatus).toBe('loading');
});
it('should handle updateSavingStatus', () => {
store.dispatch(updateSavingStatus({ status: 'saving' }));
expect(store.getState().savingStatus).toBe('saving');
});
it('should handle updateRerunLinkUpdateInProgress', () => {
store.dispatch(updateRerunLinkUpdateInProgress(true));
expect(store.getState().rerunLinkUpdateInProgress).toBe(true);
});
it('should handle updateRerunLinkUpdateResult', () => {
const linkResult = { valid: true };
store.dispatch(updateRerunLinkUpdateResult(linkResult));
expect(store.getState().rerunLinkUpdateResult).toEqual(linkResult);
});
});