annotation_storage_spec.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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("GetOrCreateValue", 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.getOrCreateValue("123A", "hello world");
  29. expect(value).toEqual("hello world");
  30. value = annotationStorage.getOrCreateValue("123A", "an other string");
  31. expect(value).toEqual("hello world");
  32. done();
  33. });
  34. });
  35. describe("SetValue", function () {
  36. it("should set a new value in the annotation storage", function (done) {
  37. const annotationStorage = new _annotation_storage.AnnotationStorage();
  38. annotationStorage.setValue("123A", "an other string");
  39. const value = annotationStorage.getAll()["123A"];
  40. expect(value).toEqual("an other string");
  41. done();
  42. });
  43. it("should call onSetModified() if value is changed", function (done) {
  44. const annotationStorage = new _annotation_storage.AnnotationStorage();
  45. let called = false;
  46. const callback = function () {
  47. called = true;
  48. };
  49. annotationStorage.onSetModified = callback;
  50. annotationStorage.getOrCreateValue("asdf", "original");
  51. expect(called).toBe(false);
  52. annotationStorage.setValue("asdf", "original");
  53. expect(called).toBe(false);
  54. annotationStorage.setValue("asdf", "modified");
  55. expect(called).toBe(true);
  56. done();
  57. });
  58. });
  59. describe("ResetModified", function () {
  60. it("should call onResetModified() if set", function (done) {
  61. const annotationStorage = new _annotation_storage.AnnotationStorage();
  62. let called = false;
  63. const callback = function () {
  64. called = true;
  65. };
  66. annotationStorage.onResetModified = callback;
  67. annotationStorage.getOrCreateValue("asdf", "original");
  68. annotationStorage.setValue("asdf", "original");
  69. annotationStorage.resetModified();
  70. expect(called).toBe(false);
  71. annotationStorage.setValue("asdf", "modified");
  72. annotationStorage.resetModified();
  73. expect(called).toBe(true);
  74. done();
  75. });
  76. });
  77. });