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

Refactor PDFMetadata tests #3373

Merged
merged 4 commits into from
May 11, 2021
Merged

Refactor PDFMetadata tests #3373

merged 4 commits into from
May 11, 2021

Conversation

robertknight
Copy link
Member

This PR is some refactoring of the tests for the code that reads metadata (URL, fingerprint, title) from PDFs in preparation for fixing #3372. There are no functional changes.

See individual commit messages for full details, but in summary:

  • Move some setup logic from beforeEach blocks to helper functions so that it can be customized by individual tests
  • Convert async/await to promise chains
  • Refactor tests for getMetadata so that individual tests only check properties of the result they are interested in, rather than the whole result.
  • Add missing explicit tests for the presence of the document fingerprint and PDF URL in the links property of the getMetadata result

Refactor the setup steps in PDFMetadata tests to make it easier
to customize the PDF metadata exposed by the fake PDF.js environment.
Instead of creating a fake `PDFViewerApplication` and `PDFMetadata`
instance before each test, provide a helper function that creates both
using the provided metadata.
@codecov
Copy link

codecov bot commented May 5, 2021

Codecov Report

Merging #3373 (b06e863) into master (6267210) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3373   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         213      213           
  Lines        7761     7761           
  Branches     1752     1752           
=======================================
  Hits         7640     7640           
  Misses        121      121           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6267210...b06e863. Read the comment docs.

 - Convert promise chains to async/await

 - Add missing tests to check that the PDF URL and fingerprint URL
   appear in the object returned by `getMetadata`. These were previously
   tested indirectly in other tests.

 - Change tests to only check the specific properties of the returned
   object that are of interest. This reduces the changes needed when
   tests change unrelated parts of the output.
Convert remaining promise chains in `PDFMetadata` tests to async/await.
Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

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

The conversion to async/await and other modernizing and structure updates make sense just fine.

I'm not going to pretend to fully have my head wrapped around the multiple levels of fakes—let me know if you'd like me to invest time in that deeper understanding, or if this surface-level evaluation of the tests themselves suffices!

}

describe('#getUri', () => {
it('returns the non-file URI', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly does non-file mean here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means any URL with a scheme other than file:. In practice it means a URL with a scheme that is http: or https:. I'll update the test description to clarify.

assert.equal(metadata.title, testMetadata.metadata['dc:title']);
});

it('gets the title from the documentInfo.Title field', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be helpful to detail what context causes the title to come from documentInfo.title vs. dc:title?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a comment above these tests to spell out the intended behavior.

 - Clarify what a "non-file URL" means and add an additional test case
   for HTTPS URLs
 - Add a comment to clarify the precedence order of titles. The tests
   could more directly check that the expected precedence order is
   respected, but the logic here is expected to change very soon, so
   just add a comment for now.
@robertknight robertknight merged commit 87956ee into master May 11, 2021
@robertknight robertknight deleted the refactor-pdf-metadata-tests branch May 11, 2021 08:51
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