annotation_storage_spec.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2022 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 _annotation_storage = require("../../display/annotation_storage.js");
  24. describe("AnnotationStorage", function () {
  25. describe("GetOrDefaultValue", function () {
  26. it("should get and set a new value in the annotation storage", function () {
  27. const annotationStorage = new _annotation_storage.AnnotationStorage();
  28. let value = annotationStorage.getValue("123A", {
  29. value: "hello world"
  30. }).value;
  31. expect(value).toEqual("hello world");
  32. annotationStorage.setValue("123A", {
  33. value: "hello world"
  34. });
  35. value = annotationStorage.getValue("123A", {
  36. value: "an other string"
  37. }).value;
  38. expect(value).toEqual("hello world");
  39. });
  40. it("should get set values and default ones in the annotation storage", function () {
  41. const annotationStorage = new _annotation_storage.AnnotationStorage();
  42. annotationStorage.setValue("123A", {
  43. value: "hello world",
  44. hello: "world"
  45. });
  46. const result = annotationStorage.getValue("123A", {
  47. value: "an other string",
  48. world: "hello"
  49. });
  50. expect(result).toEqual({
  51. value: "hello world",
  52. hello: "world",
  53. world: "hello"
  54. });
  55. });
  56. });
  57. describe("SetValue", function () {
  58. it("should set a new value in the annotation storage", function () {
  59. const annotationStorage = new _annotation_storage.AnnotationStorage();
  60. annotationStorage.setValue("123A", {
  61. value: "an other string"
  62. });
  63. const value = annotationStorage.getAll()["123A"].value;
  64. expect(value).toEqual("an other string");
  65. });
  66. it("should call onSetModified() if value is changed", function () {
  67. const annotationStorage = new _annotation_storage.AnnotationStorage();
  68. let called = false;
  69. const callback = function () {
  70. called = true;
  71. };
  72. annotationStorage.onSetModified = callback;
  73. annotationStorage.setValue("asdf", {
  74. value: "original"
  75. });
  76. expect(called).toBe(true);
  77. annotationStorage.setValue("asdf", {
  78. value: "modified"
  79. });
  80. expect(called).toBe(true);
  81. called = false;
  82. annotationStorage.setValue("asdf", {
  83. value: "modified"
  84. });
  85. expect(called).toBe(false);
  86. });
  87. });
  88. describe("ResetModified", function () {
  89. it("should call onResetModified() if set", function () {
  90. const annotationStorage = new _annotation_storage.AnnotationStorage();
  91. let called = false;
  92. const callback = function () {
  93. called = true;
  94. };
  95. annotationStorage.onResetModified = callback;
  96. annotationStorage.setValue("asdf", {
  97. value: "original"
  98. });
  99. annotationStorage.resetModified();
  100. expect(called).toBe(true);
  101. called = false;
  102. annotationStorage.setValue("asdf", {
  103. value: "original"
  104. });
  105. annotationStorage.resetModified();
  106. expect(called).toBe(false);
  107. annotationStorage.setValue("asdf", {
  108. value: "modified"
  109. });
  110. annotationStorage.resetModified();
  111. expect(called).toBe(true);
  112. });
  113. });
  114. });