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

Conversation

waridrox
Copy link
Member

@waridrox waridrox commented Aug 6, 2021

The current Download button at http://spectralworkbench.org doesn't work. A blank page is open instead. The added function could be utilised wherever possible for example in the new interface to download the spectrum images with the timestamp. Here's a demo for the same:

download-test.mov
  • tests pass -- see README.md for how to run them
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request are descriptively named
  • if possible, multiple commits squashed if they're smaller changes
  • reviewed/confirmed/tested by another contributor or maintainer

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

Please alert developers on [email protected] when your request is ready or if you need assistance.

Thanks!

@welcome
Copy link

welcome bot commented Aug 6, 2021

Thanks for opening this pull request! Dangerbot will test out your code and reply in a bit with some pointers and requests.
There may be some errors, but don't worry! We're here to help! 👍🎉😄

@gitpod-io
Copy link

gitpod-io bot commented Aug 6, 2021

@waridrox waridrox requested a review from jywarren August 6, 2021 07:54
@@ -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

@waridrox
Copy link
Member Author

So I think the a.href attribute is actually generated during the click of the download button.

@jywarren
Copy link
Member

So I think the a.href attribute is actually generated during the click of the download button.

Yes that should be fine, we can simulate a click and then check the href attribute to see if it correctly generated?

@jywarren
Copy link
Member

Another way you could insert the image is to just overwrite $W.data, I think, before clicking download, but that might test a narrower set of steps. Still useful!

@waridrox
Copy link
Member Author

So the anchor tag is generated and destroyed really fast according to the implementation. Even after checking for its presence, the tests prove to be really slow to detect it.

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

Same's the case for $W.data. If we try to get the current data after clicking the Download button, then that wouldn't work since by that time, the base64 of the spectrum would be changed to a new one 😕

@waridrox waridrox mentioned this pull request Aug 21, 2021
5 tasks
@jywarren
Copy link
Member

jywarren commented Aug 22, 2021 via email

@waridrox
Copy link
Member Author

The data keeps changing due to the default nature of cypress which provides --use-fake-device-for-media-stream flag that enables a sample video feed running in the background.
Screenshot 2021-08-22 at 6 31 48 PM

This means we can't assert the base64 data as it is since that will change really fast - cypress-io/cypress#2704

The other thing is that the cypress tests stop since there is a prompt for downloading the spectrum_img.

cypress-download-prompt.mp4

@jywarren
Copy link
Member

However, we can set a test video with --use-fake-device-for-media-stream manually and make it one which does not change -- then we can predict the displayed values. What do you think? Some very simple video with all same frames?

@jywarren
Copy link
Member

The other thing is that the cypress tests stop since there is a prompt for downloading the spectrum_img.

I think there ought to be a cypress tool for accepting the prompt... https://testersdock.com/cypress-javascript-alert-confirm-prompt/

@waridrox
Copy link
Member Author

I think there ought to be a cypress tool for accepting the prompt... https://testersdock.com/cypress-javascript-alert-confirm-prompt/

Sure, this prompt however I think is not a JS generated so there are means to get passed this like - https://www.npmjs.com/package/cypress-downloadfile / Cypress v6.xx

@jywarren
Copy link
Member

jywarren commented Aug 22, 2021

Ahhh this prompt -- it's an HTML feature, so there should be a cypress way around it, OR maybe we could just click and then compare the a.download attribute...

Screen Shot 2021-08-22 at 6 55 15 PM

@jywarren
Copy link
Member

@jywarren
Copy link
Member

jywarren commented Sep 5, 2021

Hi @waridrox would you like me to give this one a try? Happy to if you'd like!

@waridrox
Copy link
Member Author

waridrox commented Sep 6, 2021

Hi @jywarren!, I’m currently busy with my exams right now for the upcoming week or two 😅. If you would like to experiment, please by all means go ahead 🙌

@jywarren
Copy link
Member

jywarren commented Sep 7, 2021

OK, will give it a try if I have a moment - good luck in your exams!!!

<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

@jywarren
Copy link
Member

Let's start by testing that it's /some/ minimum length. Then we can also try presetting the video output using publiclab/spectral-workbench#710 for a more specific test.

@jywarren
Copy link
Member


  Actions
    ✓ It reach the default landing page (1421ms)
    ✓ The header navigation stepper is present and it is in the correct order (422ms)
    ✓ The default Home page step should be highlighted but not the rest (327ms)
    1) can be clicked through to begin capturing


  3 passing (4s)
  1 failing

  1) Actions
       can be clicked through to begin capturing:
     ReferenceError: path is not defined
      at Context.eval (http://127.0.0.1:8080/__cypress/tests?p=cypress/integration/spectral-workbench-demo.spec.js:128:22)

// 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 jywarren merged commit 49b5796 into publiclab:main Sep 21, 2021
@jywarren
Copy link
Member

Nice!!! Woohoo!!

jywarren added a commit that referenced this pull request Sep 21, 2021
* Update README.md

* Update README.md

* Bump jasmine from 3.6.1 to 3.7.0 (#216)

Bumps [jasmine](https://github.com/jasmine/jasmine-npm) from 3.6.1 to 3.7.0.
- [Release notes](https://github.com/jasmine/jasmine-npm/releases)
- [Commits](jasmine/jasmine-npm@v3.6.1...v3.7.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump tape from 5.2.0 to 5.2.2 (#211)

Bumps [tape](https://github.com/substack/tape) from 5.2.0 to 5.2.2.
- [Release notes](https://github.com/substack/tape/releases)
- [Commits](tape-testing/tape@v5.2.0...v5.2.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* [Security] Bump ini from 1.3.5 to 1.3.8 (#198)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. **This update includes a security fix.**
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.8)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* bump to v0.2.0 (#238)

* Camera switching in a dropdown list (#247)

* Added camera switching in a dropdown

* Added dropdown element for camera switching on old and new interface

Added dropdown element on old interface

* bump to v0.2.1

* Bump moment from 2.10.6 to 2.19.3 (#230)

Bumps [moment](https://github.com/moment/moment) from 2.10.6 to 2.19.3.
- [Release notes](https://github.com/moment/moment/releases)
- [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md)
- [Commits](moment/moment@2.10.6...2.19.3)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump jquery from 3.5.1 to 3.6.0 (#232)

Bumps [jquery](https://github.com/jquery/jquery) from 3.5.1 to 3.6.0.
- [Release notes](https://github.com/jquery/jquery/releases)
- [Commits](jquery/jquery@3.5.1...3.6.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump grunt-cli from 1.3.2 to 1.4.3 (#234)

Bumps [grunt-cli](https://github.com/gruntjs/grunt-cli) from 1.3.2 to 1.4.3.
- [Release notes](https://github.com/gruntjs/grunt-cli/releases)
- [Changelog](https://github.com/gruntjs/grunt-cli/blob/main/CHANGELOG.md)
- [Commits](gruntjs/grunt-cli@v1.3.2...v1.4.3)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump cypress from 5.1.0 to 8.1.0 (#244)

Bumps [cypress](https://github.com/cypress-io/cypress) from 5.1.0 to 8.1.0.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js)
- [Commits](https://github.com/cypress-io/cypress/compare/@cypress/react-v5.1.0...v8.1.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump path-parse from 1.0.6 to 1.0.7 (#246)

Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Upgrade to GitHub-native Dependabot (#226)

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump cypress from 8.1.0 to 8.3.0 (#253)

Bumps [cypress](https://github.com/cypress-io/cypress) from 8.1.0 to 8.3.0.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js)
- [Commits](cypress-io/cypress@v8.1.0...v8.3.0)

---
updated-dependencies:
- dependency-name: cypress
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump grunt from 1.3.0 to 1.4.1 (#252)

Bumps [grunt](https://github.com/gruntjs/grunt) from 1.3.0 to 1.4.1.
- [Release notes](https://github.com/gruntjs/grunt/releases)
- [Changelog](https://github.com/gruntjs/grunt/blob/main/CHANGELOG)
- [Commits](gruntjs/grunt@v1.3.0...v1.4.1)

---
updated-dependencies:
- dependency-name: grunt
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump jquery.steps from 1.1.1 to 1.1.2 (#250)

Bumps [jquery.steps](https://github.com/oguzhanoya/jquery-steps) from 1.1.1 to 1.1.2.
- [Release notes](https://github.com/oguzhanoya/jquery-steps/releases)
- [Commits](oguzhanoya/jquery-steps@v1.1.1...v1.1.2)

---
updated-dependencies:
- dependency-name: jquery.steps
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump tape from 5.2.2 to 5.3.1 (#249)

Bumps [tape](https://github.com/substack/tape) from 5.2.2 to 5.3.1.
- [Release notes](https://github.com/substack/tape/releases)
- [Commits](tape-testing/tape@v5.2.2...v5.3.1)

---
updated-dependencies:
- dependency-name: tape
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump jasmine from 3.7.0 to 3.9.0 (#248)

Bumps [jasmine](https://github.com/jasmine/jasmine-npm) from 3.7.0 to 3.9.0.
- [Release notes](https://github.com/jasmine/jasmine-npm/releases)
- [Commits](jasmine/jasmine-npm@v3.7.0...v3.9.0)

---
updated-dependencies:
- dependency-name: jasmine
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump moment from 2.19.3 to 2.29.1 (#257)

Bumps [moment](https://github.com/moment/moment) from 2.19.3 to 2.29.1.
- [Release notes](https://github.com/moment/moment/releases)
- [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md)
- [Commits](moment/moment@2.19.3...2.29.1)

---
updated-dependencies:
- dependency-name: moment
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump cypress from 8.3.0 to 8.3.1 (#259)

Bumps [cypress](https://github.com/cypress-io/cypress) from 8.3.0 to 8.3.1.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js)
- [Commits](cypress-io/cypress@v8.3.0...v8.3.1)

---
updated-dependencies:
- dependency-name: cypress
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump http-server from 0.12.3 to 13.0.1 (#258)

Bumps [http-server](https://github.com/http-party/http-server) from 0.12.3 to 13.0.1.
- [Release notes](https://github.com/http-party/http-server/releases)
- [Commits](http-party/http-server@v0.12.3...v13.0.1)

---
updated-dependencies:
- dependency-name: http-server
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* 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]>

* Bump http-server from 13.0.1 to 13.0.2 (#260)

Bumps [http-server](https://github.com/http-party/http-server) from 13.0.1 to 13.0.2.
- [Release notes](https://github.com/http-party/http-server/releases)
- [Commits](http-party/http-server@v13.0.1...v13.0.2)

---
updated-dependencies:
- dependency-name: http-server
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Mohammad Warid <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants