Options.test.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. chinesePunct: false,
  101. codeBlockPreview: true,
  102. fixTermTypo: false,
  103. footnotes: true,
  104. linkBase: "",
  105. listStyle: false,
  106. sanitize: true,
  107. setext: false,
  108. toc: false,
  109. },
  110. math: {
  111. engine: "KaTeX",
  112. inlineDigit: false,
  113. macros: {},
  114. },
  115. maxWidth: 800,
  116. mode: "both",
  117. theme: "light",
  118. themes: {dark: "", light: "", wechat: ""},
  119. });
  120. });
  121. test("Options hint", () => {
  122. const options = new Options({
  123. cache,
  124. hint: {
  125. emoji: {
  126. "+1": "👍",
  127. },
  128. emojiTail: "前往设置",
  129. },
  130. });
  131. expect(options.merge()).toMatchObject({
  132. cache,
  133. hint: {
  134. delay: 200,
  135. emoji: {
  136. "+1": "👍",
  137. },
  138. emojiPath: "https://cdn.jsdelivr.net/npm/vditor@version/dist/images/emoji",
  139. emojiTail: "前往设置",
  140. },
  141. });
  142. });
  143. test("Options resize", () => {
  144. const options = new Options({
  145. cache,
  146. resize: {
  147. enable: true,
  148. },
  149. });
  150. expect(options.merge()).toMatchObject({
  151. cache,
  152. resize: {
  153. enable: true,
  154. position: "bottom",
  155. },
  156. });
  157. });
  158. });