-
Notifications
You must be signed in to change notification settings - Fork 116
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
feat(print): add check to see if printing is available #1177
Conversation
mickr
commented
Feb 28, 2020
- Adds helper method to check if printing is available on the preview instance
* Adds helper method to check if printing is available on the preview instance
This will be used by the contentPreview to check whether a file type will support printing, there is a PR coming for that. |
src/lib/Preview.js
Outdated
@@ -1299,7 +1309,7 @@ class Preview extends EventEmitter { | |||
if (canDownload(this.file, this.options)) { | |||
this.ui.showDownloadButton(this.download); | |||
|
|||
if (checkFeature(this.viewer, 'print')) { | |||
if (this.canPrint()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably move this outside the canDownload check to flatten the conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
src/lib/__tests__/Preview-test.js
Outdated
|
||
it('should return true is file is downloadable and has printing feature', () => { | ||
stubs.canDownload.returns(true); | ||
stubs.checkFeature.withArgs(sinon.match.any, 'print').returns(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid using withArgs if possible. It’s difficult to migrate to other test frameworks like Jest.
* @return {boolean} | ||
*/ | ||
canPrint() { | ||
return !!canDownload(this.file, this.options) && checkFeature(this.viewer, 'print'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the !!
necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both return booleans, but figured to ensure it is a boolean in case those interfaces change, I don't believe it hurts anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the !!
should be omitted if it's not needed.
* @return {boolean} | ||
*/ | ||
canPrint() { | ||
return !!canDownload(this.file, this.options) && checkFeature(this.viewer, 'print'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the !!
should be omitted if it's not needed.