@@ -25,6 +25,7 @@ describe("Downloading project with name set", () => {
2525 project : {
2626 name : "My epic project" ,
2727 identifier : "hello-world-project" ,
28+ instructions : "print hello world to the console" ,
2829 components : [
2930 {
3031 name : "main" ,
@@ -53,6 +54,18 @@ describe("Downloading project with name set", () => {
5354 expect ( downloadButton ) . toBeInTheDocument ( ) ;
5455 } ) ;
5556
57+ test ( "Clicking download zips instructions" , async ( ) => {
58+ fireEvent . click ( downloadButton ) ;
59+ const JSZipInstance = JSZip . mock . instances [ 0 ] ;
60+ const mockFile = JSZipInstance . file ;
61+ await waitFor ( ( ) =>
62+ expect ( mockFile ) . toHaveBeenCalledWith (
63+ "INSTRUCTIONS.md" ,
64+ "print hello world to the console" ,
65+ ) ,
66+ ) ;
67+ } ) ;
68+
5669 test ( "Clicking download zips project file content" , async ( ) => {
5770 fireEvent . click ( downloadButton ) ;
5871 const JSZipInstance = JSZip . mock . instances [ 0 ] ;
@@ -123,3 +136,48 @@ describe("Downloading project with no name set", () => {
123136 ) ;
124137 } ) ;
125138} ) ;
139+
140+ describe ( "Downloading project with no instructions set" , ( ) => {
141+ let downloadButton ;
142+
143+ beforeEach ( ( ) => {
144+ JSZip . mockClear ( ) ;
145+ const middlewares = [ ] ;
146+ const mockStore = configureStore ( middlewares ) ;
147+ const initialState = {
148+ editor : {
149+ project : {
150+ name : "My epic project" ,
151+ identifier : "hello-world-project" ,
152+ components : [
153+ {
154+ name : "main" ,
155+ extension : "py" ,
156+ content : "" ,
157+ } ,
158+ ] ,
159+ image_list : [ ] ,
160+ } ,
161+ } ,
162+ } ;
163+ const store = mockStore ( initialState ) ;
164+ render (
165+ < Provider store = { store } >
166+ < DownloadButton buttonText = "Download" Icon = { ( ) => { } } />
167+ </ Provider > ,
168+ ) ;
169+ downloadButton = screen . queryByText ( "Download" ) . parentElement ;
170+ } ) ;
171+
172+ test ( "Clicking download button does not zip instructions" , async ( ) => {
173+ fireEvent . click ( downloadButton ) ;
174+ const JSZipInstance = JSZip . mock . instances [ 0 ] ;
175+ const mockFile = JSZipInstance . file ;
176+ await waitFor ( ( ) =>
177+ expect ( mockFile ) . not . toHaveBeenCalledWith (
178+ "INSTRUCTIONS.md" ,
179+ expect . anything ( ) ,
180+ ) ,
181+ ) ;
182+ } ) ;
183+ } ) ;
0 commit comments