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

feat(print): add check to see if printing is available #1177

Merged
merged 4 commits into from
Mar 2, 2020

Conversation

mickr
Copy link
Contributor

@mickr 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
@mickr mickr requested a review from a team as a code owner February 28, 2020 00:52
@mickr
Copy link
Contributor Author

mickr commented Feb 28, 2020

This will be used by the contentPreview to check whether a file type will support printing, there is a PR coming for that.

@@ -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()) {
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure


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);
Copy link
Collaborator

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');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the !! necessary here?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

ConradJChan
ConradJChan previously approved these changes Feb 29, 2020
* @return {boolean}
*/
canPrint() {
return !!canDownload(this.file, this.options) && checkFeature(this.viewer, 'print');
Copy link
Collaborator

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.

@mickr mickr merged commit 4a19c53 into box:master Mar 2, 2020
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.

4 participants