1
- import sidebarActions from 'actions/challenge-listing/sidebar' ;
2
-
3
- const actions = sidebarActions . challengeListing . sidebar ;
4
-
5
- const mockFetch = ( ok , resolvesTo ) => jest . fn (
6
- ( ) => Promise . resolve ( { ok, json : ( ) => resolvesTo } ) ,
7
- ) ;
8
-
9
- const createXHRmock = ( ) => {
10
- const open = jest . fn ( ) ;
11
- // be aware we use *function* because we need to get *this*
12
- // from *new XmlHttpRequest()* call
13
- const send = jest . fn ( ) . mockImplementation ( ( ) => {
14
- this . onload ( ) ;
15
- } ) ;
16
- const xhrMockClass = {
17
- open,
18
- send,
19
- setRequestHeader : jest . fn ( ) ,
20
- getAllResponseHeaders : jest . fn ( ) ,
21
- } ;
22
-
23
- window . XMLHttpRequest = jest . fn ( ) . mockImplementation ( xhrMockClass ) ;
24
- } ;
25
-
26
1
let originalFetch ;
27
2
28
3
beforeAll ( ( ) => {
@@ -34,145 +9,8 @@ afterAll(() => {
34
9
jest . clearAllMocks ( ) ;
35
10
} ) ;
36
11
37
- describe ( 'challengeListing.sidebar.changeFilterName' , ( ) => {
38
- const a = actions . changeFilterName ( 'index' , 'name' ) ;
39
-
40
- test ( 'has expected type' , ( ) => {
41
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/CHANGE_FILTER_NAME' ) ;
42
- } ) ;
43
-
44
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( {
45
- index : 'index' ,
46
- name : 'name' ,
47
- } ) ) ;
48
- } ) ;
49
-
50
- describe ( 'challengeListing.sidebar.deleteSavedFilter' , ( ) => {
51
- global . fetch = mockFetch ( true , 'dummy' ) ;
52
- createXHRmock ( ) ;
53
-
54
- const a = actions . deleteSavedFilter ( 'id' , 'token' ) ;
55
-
56
- test ( 'has expected type' , ( ) => {
57
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/DELETE_SAVED_FILTER' ) ;
58
- } ) ;
59
-
60
- // FIXME: Broken in topcoder-react-lib v1000.8.0
61
- // test('payload is a promise which resolves to the expected object', () =>
62
- // a.payload.then(res => expect(res).toEqual('id')));
63
- } ) ;
64
-
65
- describe ( 'challengeListing.sidebar.dragSavedFilterMove' , ( ) => {
66
- const a = actions . dragSavedFilterMove (
67
- { target : { offsetHeight : 10 } } ,
68
- { y : 0 , startIndex : 0 , index : 10 } ,
69
- ) ;
70
-
71
- test ( 'has expected type' , ( ) => {
72
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE' ) ;
73
- } ) ;
74
-
75
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( { y : 0 , startIndex : 0 , index : 10 } ) ) ;
76
- } ) ;
77
-
78
- describe ( 'challengeListing.sidebar.dragSavedFilterMove with screenY' , ( ) => {
79
- const a = actions . dragSavedFilterMove (
80
- { screenY : 10 , target : { offsetHeight : 10 } } ,
81
- { y : 0 , startIndex : 0 , index : 10 } ,
82
- ) ;
83
-
84
- test ( 'has expected type' , ( ) => {
85
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE' ) ;
86
- } ) ;
87
-
88
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( {
89
- y : 0 , startIndex : 0 , index : 10 , currentIndex : 1 ,
90
- } ) ) ;
91
- } ) ;
92
-
93
- describe ( 'challengeListing.sidebar.dragSavedFilterMove same index' , ( ) => {
94
- const a = actions . dragSavedFilterMove (
95
- { screenY : 10 , target : { offsetHeight : 10 } } ,
96
- { y : 0 , startIndex : 9 , index : 10 } ,
97
- ) ;
98
-
99
- test ( 'has expected type' , ( ) => {
100
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_MOVE' ) ;
12
+ describe ( 'challengeListing.sidebar' , ( ) => {
13
+ test ( 'not needed' , ( ) => {
14
+ expect ( true ) . toBe ( true ) ;
101
15
} ) ;
102
-
103
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( { y : 0 , startIndex : 9 , index : 10 } ) ) ;
104
- } ) ;
105
-
106
- describe ( 'challengeListing.sidebar.dragSavedFilterStart' , ( ) => {
107
- const a = actions . dragSavedFilterStart ( 10 , { screenY : 5 } ) ;
108
-
109
- test ( 'has expected type' , ( ) => {
110
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/DRAG_SAVED_FILTER_START' ) ;
111
- } ) ;
112
-
113
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( { y : 5 , startIndex : 10 , currentIndex : 10 } ) ) ;
114
- } ) ;
115
-
116
- describe ( 'challengeListing.sidebar.getSavedFilters' , ( ) => {
117
- global . fetch = mockFetch ( true , [ ] ) ;
118
-
119
- const a = actions . getSavedFilters ( 'id' , 'token' ) ;
120
-
121
- test ( 'has expected type' , ( ) => {
122
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/GET_SAVED_FILTERS' ) ;
123
- } ) ;
124
-
125
- // FIXME: Broken in topcoder-react-lib v0.3.0
126
- // test('payload is a promise which resolves to the expected object', () =>
127
- // a.payload.then(res => expect(res).toEqual([])));
128
- } ) ;
129
-
130
- describe ( 'challengeListing.sidebar.resetFilterName' , ( ) => {
131
- const a = actions . resetFilterName ( 1 ) ;
132
-
133
- test ( 'has expected type' , ( ) => {
134
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/RESET_FILTER_NAME' ) ;
135
- } ) ;
136
-
137
- test ( 'payload is expected object' , ( ) => expect ( a . payload ) . toEqual ( 1 ) ) ;
138
- } ) ;
139
-
140
- describe ( 'challengeListing.sidebar.saveFilter' , ( ) => {
141
- global . fetch = mockFetch ( true , 'dummy' ) ;
142
-
143
- const a = actions . saveFilterDone ( 'name' , { } , 'token' ) ;
144
-
145
- test ( 'has expected type' , ( ) => {
146
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/SAVE_FILTER_DONE' ) ;
147
- } ) ;
148
-
149
- // FIXME: Broken in topcoder-react-lib v0.3.0
150
- // test('payload is a promise which resolves to the expected object', () =>
151
- // a.payload.then(res => expect(res).toEqual('dummy')));
152
- } ) ;
153
-
154
- describe ( 'challengeListing.sidebar.updateAllSavedFilters' , ( ) => {
155
- global . fetch = mockFetch ( true , 'dummy' ) ;
156
-
157
- const a = actions . updateAllSavedFilters ( [ { filter : { } } ] , 'token' ) ;
158
-
159
- test ( 'has expected type' , ( ) => {
160
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/UPDATE_ALL_SAVED_FILTERS' ) ;
161
- } ) ;
162
-
163
- test ( 'payload is undefined' , ( ) => expect ( a . payload ) . toBeUndefined ( ) ) ;
164
- } ) ;
165
-
166
- describe ( 'challengeListing.sidebar.updateSavedFilter' , ( ) => {
167
- global . fetch = mockFetch ( true , 'dummy' ) ;
168
-
169
- const a = actions . updateSavedFilter ( { } , 'token' ) ;
170
-
171
- test ( 'has expected type' , ( ) => {
172
- expect ( a . type ) . toBe ( 'CHALLENGE_LISTING/SIDEBAR/UPDATE_SAVED_FILTER' ) ;
173
- } ) ;
174
-
175
- // FIXME: Broken in topcoder-react-lib v0.3.0
176
- // test('payload is a promise which resolves to the expected object', () =>
177
- // a.payload.then(res => expect(res).toEqual('dummy')));
178
16
} ) ;
0 commit comments