Update two display_utils unit-tests to use native functionality rather than the createObjectURL helper function

Given that most of the code-base is already using native functionality, we can update these unit-tests similarily as well.
 - For the `blob:`-URL test, we simply use `URL.createObjectURL(...)` and `Blob` directly instead.
 - For the `data:`-URL test, we simply use `btoa` to do the Base64 encoding and then build the final URL-string.
This commit is contained in:
Jonas Jenwald 2022-02-10 11:42:42 +01:00
parent f8b2a99ddc
commit 0daab88a48

View File

@ -21,7 +21,7 @@ import {
isValidFetchUrl, isValidFetchUrl,
PDFDateString, PDFDateString,
} from "../../src/display/display_utils.js"; } from "../../src/display/display_utils.js";
import { createObjectURL } from "../../src/shared/util.js"; import { bytesToString } from "../../src/shared/util.js";
import { isNodeJS } from "../../src/shared/is_node.js"; import { isNodeJS } from "../../src/shared/is_node.js";
describe("display_utils", function () { describe("display_utils", function () {
@ -320,7 +320,9 @@ describe("display_utils", function () {
pending("Blob in not supported in Node.js."); pending("Blob in not supported in Node.js.");
} }
const typedArray = new Uint8Array([1, 2, 3, 4, 5]); const typedArray = new Uint8Array([1, 2, 3, 4, 5]);
const blobUrl = createObjectURL(typedArray, "application/pdf"); const blobUrl = URL.createObjectURL(
new Blob([typedArray], { type: "application/pdf" })
);
// Sanity check to ensure that a "blob:" URL was returned. // Sanity check to ensure that a "blob:" URL was returned.
expect(blobUrl.startsWith("blob:")).toEqual(true); expect(blobUrl.startsWith("blob:")).toEqual(true);
@ -328,12 +330,9 @@ describe("display_utils", function () {
}); });
it('gets fallback filename from query string appended to "data:" URL', function () { it('gets fallback filename from query string appended to "data:" URL', function () {
const typedArray = new Uint8Array([1, 2, 3, 4, 5]); const typedArray = new Uint8Array([1, 2, 3, 4, 5]),
const dataUrl = createObjectURL( str = bytesToString(typedArray);
typedArray, const dataUrl = `data:application/pdf;base64,${btoa(str)}`;
"application/pdf",
/* forceDataSchema = */ true
);
// Sanity check to ensure that a "data:" URL was returned. // Sanity check to ensure that a "data:" URL was returned.
expect(dataUrl.startsWith("data:")).toEqual(true); expect(dataUrl.startsWith("data:")).toEqual(true);