annotation_storage_spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 _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. });
  41. describe("SetValue", function () {
  42. it("should set a new value in the annotation storage", function () {
  43. const annotationStorage = new _annotation_storage.AnnotationStorage();
  44. annotationStorage.setValue("123A", {
  45. value: "an other string"
  46. });
  47. const value = annotationStorage.getAll()["123A"].value;
  48. expect(value).toEqual("an other string");
  49. });
  50. it("should call onSetModified() if value is changed", function () {
  51. const annotationStorage = new _annotation_storage.AnnotationStorage();
  52. let called = false;
  53. const callback = function () {
  54. called = true;
  55. };
  56. annotationStorage.onSetModified = callback;
  57. annotationStorage.setValue("asdf", {
  58. value: "original"
  59. });
  60. expect(called).toBe(true);
  61. annotationStorage.setValue("asdf", {
  62. value: "modified"
  63. });
  64. expect(called).toBe(true);
  65. called = false;
  66. annotationStorage.setValue("asdf", {
  67. value: "modified"
  68. });
  69. expect(called).toBe(false);
  70. });
  71. });
  72. describe("ResetModified", function () {
  73. it("should call onResetModified() if set", function () {
  74. const annotationStorage = new _annotation_storage.AnnotationStorage();
  75. let called = false;
  76. const callback = function () {
  77. called = true;
  78. };
  79. annotationStorage.onResetModified = callback;
  80. annotationStorage.setValue("asdf", {
  81. value: "original"
  82. });
  83. annotationStorage.resetModified();
  84. expect(called).toBe(true);
  85. called = false;
  86. annotationStorage.setValue("asdf", {
  87. value: "original"
  88. });
  89. annotationStorage.resetModified();
  90. expect(called).toBe(false);
  91. annotationStorage.setValue("asdf", {
  92. value: "modified"
  93. });
  94. annotationStorage.resetModified();
  95. expect(called).toBe(true);
  96. });
  97. });
  98. });