editor_spec.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 _tools = require("../../display/editor/tools.js");
  24. var _ink = require("../../display/editor/ink.js");
  25. describe("editor", function () {
  26. describe("Command Manager", function () {
  27. it("should check undo/redo", function () {
  28. const manager = new _tools.CommandManager(4);
  29. let x = 0;
  30. const makeDoUndo = n => ({
  31. cmd: () => x += n,
  32. undo: () => x -= n
  33. });
  34. manager.add({ ...makeDoUndo(1),
  35. mustExec: true
  36. });
  37. expect(x).toEqual(1);
  38. manager.add({ ...makeDoUndo(2),
  39. mustExec: true
  40. });
  41. expect(x).toEqual(3);
  42. manager.add({ ...makeDoUndo(3),
  43. mustExec: true
  44. });
  45. expect(x).toEqual(6);
  46. manager.undo();
  47. expect(x).toEqual(3);
  48. manager.undo();
  49. expect(x).toEqual(1);
  50. manager.undo();
  51. expect(x).toEqual(0);
  52. manager.undo();
  53. expect(x).toEqual(0);
  54. manager.redo();
  55. expect(x).toEqual(1);
  56. manager.redo();
  57. expect(x).toEqual(3);
  58. manager.redo();
  59. expect(x).toEqual(6);
  60. manager.redo();
  61. expect(x).toEqual(6);
  62. manager.undo();
  63. expect(x).toEqual(3);
  64. manager.redo();
  65. expect(x).toEqual(6);
  66. });
  67. });
  68. it("should hit the limit of the manager", function () {
  69. const manager = new _tools.CommandManager(3);
  70. let x = 0;
  71. const makeDoUndo = n => ({
  72. cmd: () => x += n,
  73. undo: () => x -= n
  74. });
  75. manager.add({ ...makeDoUndo(1),
  76. mustExec: true
  77. });
  78. manager.add({ ...makeDoUndo(2),
  79. mustExec: true
  80. });
  81. manager.add({ ...makeDoUndo(3),
  82. mustExec: true
  83. });
  84. manager.add({ ...makeDoUndo(4),
  85. mustExec: true
  86. });
  87. expect(x).toEqual(10);
  88. manager.undo();
  89. manager.undo();
  90. expect(x).toEqual(3);
  91. manager.undo();
  92. expect(x).toEqual(1);
  93. manager.undo();
  94. expect(x).toEqual(1);
  95. manager.redo();
  96. manager.redo();
  97. expect(x).toEqual(6);
  98. manager.add({ ...makeDoUndo(5),
  99. mustExec: true
  100. });
  101. expect(x).toEqual(11);
  102. });
  103. describe("fitCurve", function () {
  104. it("should return a function", function () {
  105. expect(typeof _ink.fitCurve).toEqual("function");
  106. });
  107. it("should compute an Array of bezier curves", function () {
  108. const bezier = (0, _ink.fitCurve)([[1, 2], [4, 5]], 30, null);
  109. expect(bezier).toEqual([[[1, 2], [2, 3], [3, 4], [4, 5]]]);
  110. });
  111. });
  112. });