19
19
/**
20
20
* Internal dependencies
21
21
*/
22
- import { createTestRegistry , provideModules } from '../../../tests/js/utils' ;
22
+ import {
23
+ createTestRegistry ,
24
+ provideModules ,
25
+ untilResolved ,
26
+ } from '../../../tests/js/utils' ;
23
27
import {
24
28
ERROR_CODE_MISSING_REQUIRED_SCOPE ,
25
29
ERROR_REASON_INSUFFICIENT_PERMISSIONS ,
26
30
} from '../util/errors' ;
27
31
import { fireEvent , render } from '../../../tests/js/test-utils' ;
28
32
import ErrorNotice from './ErrorNotice' ;
29
- import { MODULES_ANALYTICS } from '../modules/analytics /datastore/constants' ;
33
+ import { MODULES_TAGMANAGER } from '../modules/tagmanager /datastore/constants' ;
30
34
31
35
describe ( 'ErrorNotice' , ( ) => {
32
36
let registry ;
@@ -39,7 +43,7 @@ describe( 'ErrorNotice', () => {
39
43
{ slug : moduleName , name : 'Test Module' } ,
40
44
] ) ;
41
45
invalidateResolutionSpy = jest . spyOn (
42
- registry . dispatch ( MODULES_ANALYTICS ) ,
46
+ registry . dispatch ( MODULES_TAGMANAGER ) ,
43
47
'invalidateResolution'
44
48
) ;
45
49
} ) ;
@@ -48,161 +52,105 @@ describe( 'ErrorNotice', () => {
48
52
invalidateResolutionSpy . mockReset ( ) ;
49
53
} ) ;
50
54
51
- it ( "should not render the `Retry` button if the error's `selectorData.name` is not `getReport`" , ( ) => {
52
- const { queryByText } = render (
53
- < ErrorNotice
54
- error = { {
55
- code : 'test-error-code' ,
56
- message : 'Test error message' ,
57
- data : {
58
- reason : '' ,
59
- } ,
60
- selectorData : {
61
- args : [ ] ,
62
- name : 'getAccountID' ,
63
- storeName : MODULES_ANALYTICS ,
64
- } ,
65
- } }
66
- /> ,
55
+ async function renderErrorNotice ( { error, storeName } ) {
56
+ fetchMock . get (
57
+ / ^ \/ g o o g l e - s i t e - k i t \/ v 1 \/ m o d u l e s \/ t a g m a n a g e r \/ d a t a \/ a c c o u n t s / ,
67
58
{
68
- registry,
59
+ body : error ,
60
+ status : 403 ,
69
61
}
70
62
) ;
71
63
72
- expect ( queryByText ( / r e t r y / i ) ) . not . toBeInTheDocument ( ) ;
73
- } ) ;
64
+ registry . select ( MODULES_TAGMANAGER ) . getAccounts ( ) ;
65
+
66
+ await untilResolved ( registry , MODULES_TAGMANAGER ) . getAccounts ( ) ;
67
+
68
+ expect ( console ) . toHaveErrored ( ) ;
69
+
70
+ const selectorError = registry
71
+ . select ( MODULES_TAGMANAGER )
72
+ . getError ( 'getAccounts' , [ ] ) ;
74
73
75
- it ( 'should not render the `Retry` button if the error reason is `ERROR_REASON_INSUFFICIENT_PERMISSIONS`' , ( ) => {
76
- const { queryByText } = render (
77
- < ErrorNotice
78
- error = { {
79
- code : 'test-error-code' ,
80
- message : 'Test error message' ,
81
- data : {
82
- reason : ERROR_REASON_INSUFFICIENT_PERMISSIONS ,
83
- } ,
84
- selectorData : {
85
- args : [ ] ,
86
- name : 'getReport' ,
87
- storeName : MODULES_ANALYTICS ,
88
- } ,
89
- } }
90
- /> ,
74
+ return render (
75
+ < ErrorNotice error = { selectorError } storeName = { storeName } /> ,
91
76
{
92
77
registry,
93
78
}
94
79
) ;
80
+ }
81
+
82
+ it ( 'should not render the `Retry` button if the error reason is `ERROR_REASON_INSUFFICIENT_PERMISSIONS`' , async ( ) => {
83
+ const { queryByText } = await renderErrorNotice ( {
84
+ error : {
85
+ code : 'test-error-code' ,
86
+ message : 'Test error message' ,
87
+ data : {
88
+ reason : ERROR_REASON_INSUFFICIENT_PERMISSIONS ,
89
+ } ,
90
+ } ,
91
+ storeName : MODULES_TAGMANAGER ,
92
+ } ) ;
95
93
96
94
expect ( queryByText ( / r e t r y / i ) ) . not . toBeInTheDocument ( ) ;
97
95
} ) ;
98
96
99
- it ( 'should not render the `Retry` button if the error reason is `ERROR_CODE_MISSING_REQUIRED_SCOPE`' , ( ) => {
100
- const { queryByText } = render (
101
- < ErrorNotice
102
- error = { {
103
- code : ERROR_CODE_MISSING_REQUIRED_SCOPE ,
104
- message : 'Test error message' ,
105
- data : {
106
- reason : '' ,
107
- } ,
108
- selectorData : {
109
- args : [ ] ,
110
- name : 'getReport' ,
111
- storeName : MODULES_ANALYTICS ,
112
- } ,
113
- } }
114
- /> ,
115
- {
116
- registry,
117
- }
118
- ) ;
97
+ it ( 'should not render the `Retry` button if the error reason is `ERROR_CODE_MISSING_REQUIRED_SCOPE`' , async ( ) => {
98
+ const { queryByText } = await renderErrorNotice ( {
99
+ error : {
100
+ code : ERROR_CODE_MISSING_REQUIRED_SCOPE ,
101
+ message : 'Test error message' ,
102
+ data : {
103
+ reason : '' ,
104
+ } ,
105
+ } ,
106
+ storeName : MODULES_TAGMANAGER ,
107
+ } ) ;
119
108
120
109
expect ( queryByText ( / r e t r y / i ) ) . not . toBeInTheDocument ( ) ;
121
110
} ) ;
122
111
123
- it ( 'should not render the `Retry` button if the error is an auth error' , ( ) => {
124
- const { queryByText } = render (
125
- < ErrorNotice
126
- error = { {
127
- code : 'test-error-code' ,
128
- message : 'Test error message' ,
129
- data : {
130
- reason : '' ,
131
- reconnectURL : 'example.com' ,
132
- } ,
133
- selectorData : {
134
- args : [ ] ,
135
- name : 'getReport' ,
136
- storeName : MODULES_ANALYTICS ,
137
- } ,
138
- } }
139
- /> ,
140
- {
141
- registry,
142
- }
143
- ) ;
112
+ it ( 'should not render the `Retry` button if the error is an auth error' , async ( ) => {
113
+ const { queryByText } = await renderErrorNotice ( {
114
+ error : {
115
+ code : 'test-error-code' ,
116
+ message : 'Test error message' ,
117
+ data : {
118
+ reason : '' ,
119
+ reconnectURL : 'example.com' ,
120
+ } ,
121
+ } ,
122
+ storeName : MODULES_TAGMANAGER ,
123
+ } ) ;
144
124
145
125
expect ( queryByText ( / r e t r y / i ) ) . not . toBeInTheDocument ( ) ;
146
126
} ) ;
147
127
148
- it ( 'should render the `Retry` button if the error is retryable' , ( ) => {
149
- const { queryByText } = render (
150
- < ErrorNotice
151
- error = { {
152
- code : 'test-error-code' ,
153
- message : 'Test error message' ,
154
- data : {
155
- reason : '' ,
156
- } ,
157
- selectorData : {
158
- args : [
159
- {
160
- dimensions : [ 'ga:date' ] ,
161
- metrics : [ { expression : 'ga:users' } ] ,
162
- startDate : '2020-08-11' ,
163
- endDate : '2020-09-07' ,
164
- } ,
165
- ] ,
166
- name : 'getReport' ,
167
- storeName : MODULES_ANALYTICS ,
168
- } ,
169
- } }
170
- /> ,
171
- {
172
- registry,
173
- }
174
- ) ;
128
+ it ( 'should render the `Retry` button if the error is retryable' , async ( ) => {
129
+ const { queryByText } = await renderErrorNotice ( {
130
+ error : {
131
+ code : 'test-error-code' ,
132
+ message : 'Test error message' ,
133
+ data : {
134
+ reason : '' ,
135
+ } ,
136
+ } ,
137
+ storeName : MODULES_TAGMANAGER ,
138
+ } ) ;
175
139
176
140
expect ( queryByText ( / r e t r y / i ) ) . toBeInTheDocument ( ) ;
177
141
} ) ;
178
142
179
- it ( 'should dispatch the `invalidateResolution` if the error is retryable' , ( ) => {
180
- const { queryByText, getByRole } = render (
181
- < ErrorNotice
182
- error = { {
183
- code : 'test-error-code' ,
184
- message : 'Test error message' ,
185
- data : {
186
- reason : '' ,
187
- } ,
188
- selectorData : {
189
- args : [
190
- {
191
- dimensions : [ 'ga:date' ] ,
192
- metrics : [ { expression : 'ga:users' } ] ,
193
- startDate : '2020-08-11' ,
194
- endDate : '2020-09-07' ,
195
- } ,
196
- ] ,
197
- name : 'getReport' ,
198
- storeName : MODULES_ANALYTICS ,
199
- } ,
200
- } }
201
- /> ,
202
- {
203
- registry,
204
- }
205
- ) ;
143
+ it ( 'should dispatch the `invalidateResolution` if the error is retryable' , async ( ) => {
144
+ const { queryByText, getByRole } = await renderErrorNotice ( {
145
+ error : {
146
+ code : 'test-error-code' ,
147
+ message : 'Test error message' ,
148
+ data : {
149
+ reason : '' ,
150
+ } ,
151
+ } ,
152
+ storeName : MODULES_TAGMANAGER ,
153
+ } ) ;
206
154
207
155
expect ( queryByText ( / r e t r y / i ) ) . toBeInTheDocument ( ) ;
208
156
@@ -211,34 +159,18 @@ describe( 'ErrorNotice', () => {
211
159
expect ( invalidateResolutionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
212
160
} ) ;
213
161
214
- it ( 'should not render the retry button if the store name is not available' , ( ) => {
215
- const { queryByText } = render (
216
- < ErrorNotice
217
- error = { {
218
- code : 'test-error-code' ,
219
- message : 'Test error message' ,
220
- data : {
221
- reason : '' ,
222
- reconnectURL : 'example.com' ,
223
- } ,
224
- selectorData : {
225
- args : [
226
- {
227
- dimensions : [ 'ga:date' ] ,
228
- metrics : [ { expression : 'ga:users' } ] ,
229
- startDate : '2020-08-11' ,
230
- endDate : '2020-09-07' ,
231
- } ,
232
- ] ,
233
- name : 'getReport' ,
234
- storeName : '' ,
235
- } ,
236
- } }
237
- /> ,
238
- {
239
- registry,
240
- }
241
- ) ;
162
+ it ( 'should not render the retry button if the store name is not available' , async ( ) => {
163
+ const { queryByText } = await renderErrorNotice ( {
164
+ error : {
165
+ code : 'test-error-code' ,
166
+ message : 'Test error message' ,
167
+ data : {
168
+ reason : '' ,
169
+ reconnectURL : 'example.com' ,
170
+ } ,
171
+ } ,
172
+ storeName : '' ,
173
+ } ) ;
242
174
243
175
expect ( queryByText ( / r e t r y / i ) ) . not . toBeInTheDocument ( ) ;
244
176
} ) ;
0 commit comments