Options.test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. const globalAny: any = global;
  2. globalAny.VDITOR_VERSION = "version";
  3. import {Options} from "../../src/ts/util/Options";
  4. describe("Options", () => {
  5. const cache = {
  6. enable: true,
  7. id: "vditorTest",
  8. };
  9. test("Options toolbar", () => {
  10. const options = new Options({
  11. cache,
  12. toolbar: ["br", "fullscreen", {
  13. hotkey: "⌘-a",
  14. name: "preview",
  15. }],
  16. });
  17. expect(options.merge()).toMatchObject({
  18. cache,
  19. toolbar: [{
  20. name: "br",
  21. }, {
  22. hotkey: "⌘-'",
  23. name: "fullscreen",
  24. tipPosition: "nw",
  25. }, {
  26. hotkey: "⌘-a",
  27. name: "preview",
  28. tipPosition: "nw",
  29. }],
  30. });
  31. });
  32. test("Options upload", () => {
  33. const options = new Options({
  34. cache,
  35. upload: {
  36. accept: ".jpg",
  37. },
  38. });
  39. expect(options.merge()).toMatchObject({
  40. cache,
  41. upload: {
  42. accept: ".jpg",
  43. filename: expect.anything(),
  44. linkToImgUrl: "",
  45. max: 10 * 1024 * 1024,
  46. url: "",
  47. },
  48. });
  49. });
  50. test("Options classes", () => {
  51. const options = new Options({
  52. cache,
  53. classes: {
  54. preview: "content-reset",
  55. },
  56. });
  57. expect(options.merge()).toMatchObject({
  58. cache,
  59. classes: {
  60. preview: "content-reset",
  61. },
  62. });
  63. });
  64. test("Options preview", () => {
  65. const options = new Options({
  66. cache,
  67. preview: {
  68. mode: "both",
  69. url: "https://ld246.com/md",
  70. },
  71. });
  72. expect(options.merge()).toMatchObject({
  73. cache,
  74. preview: {
  75. delay: 1000,
  76. mode: "both",
  77. url: "https://ld246.com/md",
  78. },
  79. });
  80. });
  81. test("Options preview hljs", () => {
  82. const options = new Options({
  83. cache,
  84. preview: {
  85. hljs: {
  86. style: "github",
  87. },
  88. mode: "both",
  89. },
  90. });
  91. expect(options.merge().preview).toEqual({
  92. delay: 1000,
  93. hljs: {
  94. enable: true,
  95. lineNumber: false,
  96. style: "github",
  97. },
  98. markdown: {
  99. autoSpace: false,
  100. codeBlockPreview: true,
  101. fixTermTypo: false,
  102. footnotes: true,
  103. linkBase: "",
  104. listStyle: false,
  105. sanitize: true,
  106. setext: false,
  107. toc: false,
  108. },
  109. math: {
  110. engine: "KaTeX",
  111. inlineDigit: false,
  112. macros: {},
  113. },
  114. maxWidth: 800,
  115. mode: "both",
  116. theme: "light",
  117. themes: {dark: "", light: "", wechat: ""},
  118. });
  119. });
  120. test("Options hint", () => {
  121. const options = new Options({
  122. cache,
  123. hint: {
  124. emoji: {
  125. "+1": "👍",
  126. },
  127. emojiTail: "前往设置",
  128. },
  129. });
  130. expect(options.merge()).toMatchObject({
  131. cache,
  132. hint: {
  133. delay: 200,
  134. emoji: {
  135. "+1": "👍",
  136. },
  137. emojiPath: "https://unpkg.com/vditor@version/dist/images/emoji",
  138. emojiTail: "前往设置",
  139. },
  140. });
  141. });
  142. test("Options resize", () => {
  143. const options = new Options({
  144. cache,
  145. resize: {
  146. enable: true,
  147. },
  148. });
  149. expect(options.merge()).toMatchObject({
  150. cache,
  151. resize: {
  152. enable: true,
  153. position: "bottom",
  154. },
  155. });
  156. });
  157. });