Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality for downloading spectrum image #245

Merged
merged 8 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions cypress/integration/spectral-workbench-demo.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// <reference types="cypress" />
const path = require('path')

context('Actions', () => {

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


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


})
const downloadsFolder = Cypress.config('downloadsFolder')

it('can be clicked through to begin capturing', () => {
cy.get('#landing-page-next').click()
cy.get('#setting-page-next').click()
cy.get('#download-spectrum').click()

cy.log('**read downloaded file**')

// file path is relative to the working folder
const filename = path.join(downloadsFolder, 'spectrum_img.png')

// browser might take a while to download the file,
// so use "cy.readFile" to retry until the file exists
// and has length - and we assume that it has finished downloading then
cy.readFile(filename, { timeout: 15000 })
.should('have.length.gt', 5000000000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failed. Great!

jywarren marked this conversation as resolved.
Show resolved Hide resolved
});

})
10 changes: 10 additions & 0 deletions examples/capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ $W = {
this_.getRecentCalibrations("#calibration_id");
},

downloadSpectrum: function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome. Is this something we ought to write a test for? It seems like it could be a pretty easy test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, in which file would it make more sense tho 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the test assertion would be to confirm what a.href equals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try using Cypress to press the download button and then assert if a.href is not empty? If that doesn't work, then we can try inserting an image to the

let base64_imgdata = $('#dataurl').val($W.canvas.toDataURL())[0].defaultValue;
console.log(base64_imgdata);

let a = document.createElement('a');
a.href = base64_imgdata;
a.download = ('spectrum_img.png');
a.click();
},

getRecentCalibrations: function(selector) {
$.ajax({
url: "/capture/recent_calibrations.json?calibration_id=" + $W.calibration_id,
Expand Down
5 changes: 5 additions & 0 deletions examples/new-capture/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,14 @@ <h1>
</div>
</div>

<input name="dataurl" type="hidden" id="dataurl" />

<button class="demo-button next" id="capture-page-next">Save Capture</button>
<p style="margin-top: 0.5em">Once you save the capture, you cannot go back here.</p>
<img style="display:none;background:#333;" id="spectrum-preview" />

<button class="demo-button next" id="download-spectrum" onClick="$W.downloadSpectrum();">Download</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the button


</div>


Expand Down