@@ -113,6 +113,10 @@ describe("DownloadPanel", () => {
113113 ) . toBeInTheDocument ( ) ;
114114 } ) ;
115115
116+ test ( "Does not render the save button" , ( ) => {
117+ expect ( container . queryByText ( "header.save" ) ) . not . toBeInTheDocument ( ) ;
118+ } ) ;
119+
116120 test ( "The download button initiates a download" , async ( ) => {
117121 const webComponentDownloadButton = screen . getByText (
118122 "downloadPanel.downloadButton" ,
@@ -122,7 +126,7 @@ describe("DownloadPanel", () => {
122126 } ) ;
123127 } ) ;
124128
125- describe ( "When logged in" , ( ) => {
129+ describe ( "When logged in and not the project owner " , ( ) => {
126130 beforeEach ( ( ) => {
127131 const middlewares = [ ] ;
128132 const mockStore = configureStore ( middlewares ) ;
@@ -144,10 +148,14 @@ describe("DownloadPanel", () => {
144148 } ,
145149 ] ,
146150 } ,
151+ loading : "success" ,
147152 } ,
148153 auth : {
149154 user : {
150155 access_token : "39a09671-be55-4847-baf5-8919a0c24a25" ,
156+ profile : {
157+ user : "some-user-id" ,
158+ } ,
151159 } ,
152160 } ,
153161 } ;
@@ -201,6 +209,107 @@ describe("DownloadPanel", () => {
201209 ) . toBeInTheDocument ( ) ;
202210 } ) ;
203211
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+
204313 test ( "The download button initiates a download" , async ( ) => {
205314 const webComponentDownloadButton = screen . getByText (
206315 "downloadPanel.downloadButton" ,
0 commit comments