pdf_history_spec.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _pdf_history = require("../../web/pdf_history.js");
  24. describe("pdf_history", function () {
  25. describe("isDestHashesEqual", function () {
  26. it("should reject non-equal destination hashes", function () {
  27. expect((0, _pdf_history.isDestHashesEqual)(null, "page.157")).toEqual(false);
  28. expect((0, _pdf_history.isDestHashesEqual)("title.0", "page.157")).toEqual(false);
  29. expect((0, _pdf_history.isDestHashesEqual)("page=1&zoom=auto", "page.157")).toEqual(false);
  30. expect((0, _pdf_history.isDestHashesEqual)("nameddest-page.157", "page.157")).toEqual(false);
  31. expect((0, _pdf_history.isDestHashesEqual)("page.157", "nameddest=page.157")).toEqual(false);
  32. const destArrayString = JSON.stringify([{
  33. num: 3757,
  34. gen: 0
  35. }, {
  36. name: "XYZ"
  37. }, 92.918, 748.972, null]);
  38. expect((0, _pdf_history.isDestHashesEqual)(destArrayString, "page.157")).toEqual(false);
  39. expect((0, _pdf_history.isDestHashesEqual)("page.157", destArrayString)).toEqual(false);
  40. });
  41. it("should accept equal destination hashes", function () {
  42. expect((0, _pdf_history.isDestHashesEqual)("page.157", "page.157")).toEqual(true);
  43. expect((0, _pdf_history.isDestHashesEqual)("nameddest=page.157", "page.157")).toEqual(true);
  44. expect((0, _pdf_history.isDestHashesEqual)("nameddest=page.157&zoom=100", "page.157")).toEqual(true);
  45. });
  46. });
  47. describe("isDestArraysEqual", function () {
  48. const firstDest = [{
  49. num: 1,
  50. gen: 0
  51. }, {
  52. name: "XYZ"
  53. }, 0, 375, null];
  54. const secondDest = [{
  55. num: 5,
  56. gen: 0
  57. }, {
  58. name: "XYZ"
  59. }, 0, 375, null];
  60. const thirdDest = [{
  61. num: 1,
  62. gen: 0
  63. }, {
  64. name: "XYZ"
  65. }, 750, 0, null];
  66. const fourthDest = [{
  67. num: 1,
  68. gen: 0
  69. }, {
  70. name: "XYZ"
  71. }, 0, 375, 1.0];
  72. const fifthDest = [{
  73. gen: 0,
  74. num: 1
  75. }, {
  76. name: "XYZ"
  77. }, 0, 375, null];
  78. it("should reject non-equal destination arrays", function () {
  79. expect((0, _pdf_history.isDestArraysEqual)(firstDest, undefined)).toEqual(false);
  80. expect((0, _pdf_history.isDestArraysEqual)(firstDest, [1, 2, 3, 4, 5])).toEqual(false);
  81. expect((0, _pdf_history.isDestArraysEqual)(firstDest, secondDest)).toEqual(false);
  82. expect((0, _pdf_history.isDestArraysEqual)(firstDest, thirdDest)).toEqual(false);
  83. expect((0, _pdf_history.isDestArraysEqual)(firstDest, fourthDest)).toEqual(false);
  84. });
  85. it("should accept equal destination arrays", function () {
  86. expect((0, _pdf_history.isDestArraysEqual)(firstDest, firstDest)).toEqual(true);
  87. expect((0, _pdf_history.isDestArraysEqual)(firstDest, fifthDest)).toEqual(true);
  88. const firstDestCopy = firstDest.slice();
  89. expect(firstDest).not.toBe(firstDestCopy);
  90. expect((0, _pdf_history.isDestArraysEqual)(firstDest, firstDestCopy)).toEqual(true);
  91. });
  92. });
  93. });