annotation_storage_spec.js 3.4 KB

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