Skip to content

Commit 49b5796

Browse files
waridroxjywarren
andauthored
Added functionality for downloading spectrum image (#245)
* Added function for downloading spectrum img * Adding dropdown for camera switching * download file and check length * Update spectral-workbench-demo.spec.js * Update spectral-workbench-demo.spec.js * Update spectral-workbench-demo.spec.js * increase file length test for downloaded image Co-authored-by: Jeffrey Warren <[email protected]>
1 parent b3b2760 commit 49b5796

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

cypress/integration/spectral-workbench-demo.spec.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/// <reference types="cypress" />
2+
const path = require('path')
23

34
context('Actions', () => {
45

56
beforeEach(() => {
67
cy.visit('http://127.0.0.1:8080/examples/new-capture/')
78
})
89

9-
1010
it('It reach the default landing page', () => {
1111
cy.get('#landing-page-content').contains('Spectral WorkBench');
1212
cy.get('#landing-page-content').contains('What is Spectral Workbench?');
@@ -28,5 +28,23 @@ context('Actions', () => {
2828
cy.get('.bs-stepper-header>div').eq(6).not('have.class', 'active')
2929
});
3030

31-
32-
})
31+
const downloadsFolder = Cypress.config('downloadsFolder')
32+
33+
it('can be clicked through to begin capturing', () => {
34+
cy.get('#landing-page-next').click()
35+
cy.get('#setting-page-next').click()
36+
cy.get('#download-spectrum').click()
37+
38+
cy.log('**read downloaded file**')
39+
40+
// file path is relative to the working folder
41+
const filename = path.join(downloadsFolder, 'spectrum_img.png')
42+
43+
// browser might take a while to download the file,
44+
// so use "cy.readFile" to retry until the file exists
45+
// and has length - and we assume that it has finished downloading then
46+
cy.readFile(filename, { timeout: 15000 })
47+
.should('have.length.gt', 50)
48+
});
49+
50+
})

examples/capture/capture.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ $W = {
161161
this_.getRecentCalibrations("#calibration_id");
162162
},
163163

164+
downloadSpectrum: function() {
165+
let base64_imgdata = $('#dataurl').val($W.canvas.toDataURL())[0].defaultValue;
166+
console.log(base64_imgdata);
167+
168+
let a = document.createElement('a');
169+
a.href = base64_imgdata;
170+
a.download = ('spectrum_img.png');
171+
a.click();
172+
},
173+
164174
getRecentCalibrations: function(selector) {
165175
$.ajax({
166176
url: "/capture/recent_calibrations.json?calibration_id=" + $W.calibration_id,

examples/new-capture/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,14 @@ <h1>
246246
</div>
247247
</div>
248248

249+
<input name="dataurl" type="hidden" id="dataurl" />
250+
249251
<button class="demo-button next" id="capture-page-next">Save Capture</button>
250252
<p style="margin-top: 0.5em">Once you save the capture, you cannot go back here.</p>
251253
<img style="display:none;background:#333;" id="spectrum-preview" />
254+
255+
<button class="demo-button next" id="download-spectrum" onClick="$W.downloadSpectrum();">Download</button>
256+
252257
</div>
253258

254259

0 commit comments

Comments
 (0)