@@ -158,4 +158,35 @@ describe('FlowForge - Application - Snapshots', () => {
158158 // check an SVG in present the content section
159159 cy . get ( '[data-el="dialog-compare-snapshot"] .ff-dialog-content svg' ) . should ( 'exist' )
160160 } )
161+ it ( 'download snapshot package.json' , ( ) => {
162+ cy . intercept ( 'GET' , '/api/*/projects/*/snapshots' , deviceSnapshots ) . as ( 'snapshotData' )
163+ cy . intercept ( 'GET' , '/api/*/snapshots/*' ) . as ( 'snapshot' )
164+
165+ cy . get ( '[data-nav="application-snapshots"]' ) . click ( )
166+
167+ // ensure package.json does not exist in the downloads folder before the test
168+ cy . task ( 'clearDownloads' )
169+ // click kebab menu in row 1
170+ cy . get ( '[data-el="snapshots"] tbody' ) . find ( '.ff-kebab-menu' ) . eq ( 0 ) . click ( )
171+ // click the Download Package.json option
172+ cy . get ( '[data-el="snapshots"] tbody .ff-kebab-menu .ff-kebab-options' ) . find ( '.ff-list-item' ) . eq ( IDX_DOWNLOAD_PACKAGE ) . click ( )
173+
174+ cy . wait ( '@snapshot' ) . then ( async interception => {
175+ // At this point, the endpoint has returned but occasionally, the test fails as the file is not yet written to the filesystem.
176+ // To counter this, there is a short 250ms wait to allow time for the file to be written to the filesystem.
177+ // A better solution would be to use a cy.command (named waitForFileDownload) that polls the downloads folder
178+ // and calls `cy.wait` with timeout and retry. This would allow the test to wait for the file in a more reliable way.
179+ // For now, a small delay here gets the job done.
180+ cy . wait ( 250 ) // eslint-disable-line cypress/no-unnecessary-waiting
181+ const downloadsFolder = Cypress . config ( 'downloadsFolder' )
182+ return cy . readFile ( `${ downloadsFolder } /package.json` )
183+ } ) . then ( ( packageObject ) => {
184+ expect ( packageObject ) . to . have . property ( 'name' , 'instance-2-with-devices' )
185+ expect ( packageObject ) . to . have . property ( 'description' )
186+ expect ( packageObject ) . to . have . property ( 'dependencies' )
187+ // expect(packageObject.dependencies).to.have.property('node-red', '4.0.0')
188+ // expect(packageObject.dependencies).to.have.property('@flowfuse/nr-project-nodes', '0.6.4')
189+ // expect(packageObject.dependencies).to.have.property('@flowfuse/node-red-dashboard', '*')
190+ } )
191+ } )
161192} )
0 commit comments