Skip to content
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions examples/capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ $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

function getFormattedTime() {
let current_date = new Date();
let year = current_date.getFullYear();
let month = current_date.getMonth() + 1;
let day = current_date.getDate();
let hours = current_date.getHours();
let minutes = current_date.getMinutes();
let seconds = current_date.getSeconds();
return (year + '-' + month + '-' + day + '-' + hours + '-' + minutes + '-' + seconds);
}

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-' + getFormattedTime() + '.png');
a.click();
},

getRecentCalibrations: function(selector) {
$.ajax({
url: "/capture/recent_calibrations.json?calibration_id=" + $W.calibration_id,
Expand Down