@@ -113,6 +113,10 @@ describe("DownloadPanel", () => {
113
113
) . toBeInTheDocument ( ) ;
114
114
} ) ;
115
115
116
+ test ( "Does not render the save button" , ( ) => {
117
+ expect ( container . queryByText ( "header.save" ) ) . not . toBeInTheDocument ( ) ;
118
+ } ) ;
119
+
116
120
test ( "The download button initiates a download" , async ( ) => {
117
121
const webComponentDownloadButton = screen . getByText (
118
122
"downloadPanel.downloadButton" ,
@@ -122,7 +126,7 @@ describe("DownloadPanel", () => {
122
126
} ) ;
123
127
} ) ;
124
128
125
- describe ( "When logged in" , ( ) => {
129
+ describe ( "When logged in and not the project owner " , ( ) => {
126
130
beforeEach ( ( ) => {
127
131
const middlewares = [ ] ;
128
132
const mockStore = configureStore ( middlewares ) ;
@@ -144,10 +148,14 @@ describe("DownloadPanel", () => {
144
148
} ,
145
149
] ,
146
150
} ,
151
+ loading : "success" ,
147
152
} ,
148
153
auth : {
149
154
user : {
150
155
access_token : "39a09671-be55-4847-baf5-8919a0c24a25" ,
156
+ profile : {
157
+ user : "some-user-id" ,
158
+ } ,
151
159
} ,
152
160
} ,
153
161
} ;
@@ -201,6 +209,107 @@ describe("DownloadPanel", () => {
201
209
) . toBeInTheDocument ( ) ;
202
210
} ) ;
203
211
212
+ test ( "Renders the save button" , ( ) => {
213
+ expect ( container . getByText ( "header.save" ) ) . toBeInTheDocument ( ) ;
214
+ } ) ;
215
+
216
+ test ( "The download button initiates a download" , async ( ) => {
217
+ const webComponentDownloadButton = screen . getByText (
218
+ "downloadPanel.downloadButton" ,
219
+ ) . parentElement ;
220
+ fireEvent . click ( webComponentDownloadButton ) ;
221
+ await waitFor ( ( ) => expect ( FileSaver . saveAs ) . toHaveBeenCalled ( ) ) ;
222
+ } ) ;
223
+ } ) ;
224
+
225
+ describe ( "When logged in and the project owner" , ( ) => {
226
+ beforeEach ( ( ) => {
227
+ const middlewares = [ ] ;
228
+ const mockStore = configureStore ( middlewares ) ;
229
+ const initialState = {
230
+ editor : {
231
+ project : {
232
+ name : "My epic project" ,
233
+ identifier : "hello-world-project" ,
234
+ components : [
235
+ {
236
+ name : "main" ,
237
+ extension : "py" ,
238
+ content : "print('hello world')" ,
239
+ } ,
240
+ ] ,
241
+ image_list : [
242
+ {
243
+ url : "a.com/b" ,
244
+ } ,
245
+ ] ,
246
+ user_id : "some-user-id" ,
247
+ } ,
248
+ loading : "success" ,
249
+ } ,
250
+ auth : {
251
+ user : {
252
+ access_token : "39a09671-be55-4847-baf5-8919a0c24a25" ,
253
+ profile : {
254
+ user : "some-user-id" ,
255
+ } ,
256
+ } ,
257
+ } ,
258
+ } ;
259
+ const store = mockStore ( initialState ) ;
260
+
261
+ container = render (
262
+ < Provider store = { store } >
263
+ < MemoryRouter >
264
+ < DownloadPanel />
265
+ </ MemoryRouter >
266
+ </ Provider > ,
267
+ ) ;
268
+ } ) ;
269
+ test ( "Renders the correct heading" , ( ) => {
270
+ expect ( container . getByText ( "downloadPanel.heading" ) ) . toBeInTheDocument ( ) ;
271
+ } ) ;
272
+
273
+ test ( "Does not render the log-in subtitle" , ( ) => {
274
+ expect (
275
+ container . queryByText ( "downloadPanel.logInTitle" ) ,
276
+ ) . not . toBeInTheDocument ( ) ;
277
+ } ) ;
278
+
279
+ test ( "Does not render the log-in hint" , ( ) => {
280
+ expect (
281
+ container . queryByText ( "downloadPanel.logInHint" ) ,
282
+ ) . not . toBeInTheDocument ( ) ;
283
+ } ) ;
284
+
285
+ test ( "Does not render the log-in button" , ( ) => {
286
+ expect (
287
+ container . queryByText ( "downloadPanel.logInButton" ) ,
288
+ ) . not . toBeInTheDocument ( ) ;
289
+ } ) ;
290
+
291
+ test ( "Does not render the sign-up button" , ( ) => {
292
+ expect (
293
+ container . queryByText ( "downloadPanel.signUpButton" ) ,
294
+ ) . not . toBeInTheDocument ( ) ;
295
+ } ) ;
296
+
297
+ test ( "Renders the download hint" , ( ) => {
298
+ expect (
299
+ container . getByText ( "downloadPanel.downloadHint" ) ,
300
+ ) . toBeInTheDocument ( ) ;
301
+ } ) ;
302
+
303
+ test ( "Renders the download button" , ( ) => {
304
+ expect (
305
+ container . getByText ( "downloadPanel.downloadButton" ) ,
306
+ ) . toBeInTheDocument ( ) ;
307
+ } ) ;
308
+
309
+ test ( "Does not render the save button" , ( ) => {
310
+ expect ( container . queryByText ( "header.save" ) ) . not . toBeInTheDocument ( ) ;
311
+ } ) ;
312
+
204
313
test ( "The download button initiates a download" , async ( ) => {
205
314
const webComponentDownloadButton = screen . getByText (
206
315
"downloadPanel.downloadButton" ,
0 commit comments