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

[MB-8798] Fix deprecation warning for progress callback in pdf getDocument method #5

Merged
merged 3 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"css-loader": "^3.6.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"enzyme-wait": "^1.0.9",
"eslint": "^7.3.1",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-webpack": "^0.12.2",
Expand Down
12 changes: 6 additions & 6 deletions src/components/drivers/pdf-viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ export default class PDFDriver extends React.Component {
const { filePath } = this.props
const containerWidth = this.container.offsetWidth

PDFJS.getDocument(
filePath,
null,
null,
this.progressCallback.bind(this)
).then((pdf) => {
const loadingTask = PDFJS.getDocument(filePath)
loadingTask.onProgress = (progressData) => {
this.progressCallback(progressData)
}

loadingTask.then((pdf) => {
this.setState({ pdf, containerWidth })
})
}
Expand Down
13 changes: 13 additions & 0 deletions tests/components/pdf-viewer.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) 2017 PlanGrid, Inc.
import { readFileSync } from 'fs'

import React from 'react';
import { mount } from 'enzyme';
import { createWaitForElement } from 'enzyme-wait';
import { PDFPage } from 'components/drivers/pdf-viewer';
import PDFDriver from '../../src/components/drivers/pdf-viewer'

describe('pdf-viewer', () => {
let spy;
Expand Down Expand Up @@ -34,4 +37,14 @@ describe('pdf-viewer', () => {
);
expect(spy).not.toHaveBeenCalled();
});

it('updates loading progress state', async () => {
const fileContents = readFileSync('./example_files/sample.pdf', {encoding: 'base64'});
const wrapper = mount(
<PDFDriver fileType='pdf' filePath={"data:application/pdf;base64, " + fileContents} />
);
createWaitForElement('.pdf-canvas')(wrapper).then((componentReady) => {
expect(componentReady.state().percent).toBe('100')
})
});
});
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,11 @@ assert@^1.1.1:
object-assign "^4.1.1"
util "0.10.3"

assertion-error@^1.0.2:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==

assign-symbols@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
Expand Down Expand Up @@ -3382,6 +3387,13 @@ enzyme-shallow-equal@^1.0.1:
has "^1.0.3"
object-is "^1.0.2"

enzyme-wait@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/enzyme-wait/-/enzyme-wait-1.0.9.tgz#f7a08bf49c7047358fa03e1f411a565c3a15101a"
integrity sha1-96CL9JxwRzWPoD4fQRpWXDoVEBo=
dependencies:
assertion-error "^1.0.2"

enzyme@^3.8.0:
version "3.11.0"
resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-3.11.0.tgz#71d680c580fe9349f6f5ac6c775bc3e6b7a79c28"
Expand Down