Options.test.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import {Options} from '../../src/ts/util/Options';
  2. describe('Options', () => {
  3. test('Options toolbar', () => {
  4. const options = new Options({
  5. toolbar: ['br', 'fullscreen', {
  6. hotkey: "⌘-a",
  7. name: "preview",
  8. }]
  9. });
  10. expect(options.merge()).toMatchObject({
  11. toolbar: [{
  12. name: "br",
  13. }, {
  14. hotkey: "⌘-'",
  15. name: "fullscreen",
  16. tipPosition: "nw",
  17. }, {
  18. hotkey: "⌘-a",
  19. name: "preview",
  20. tipPosition: "nw",
  21. }],
  22. })
  23. });
  24. test('Options upload', () => {
  25. const options = new Options({
  26. upload: {
  27. accept: '.jpg'
  28. }
  29. });
  30. expect(options.merge()).toMatchObject({
  31. upload: {
  32. filename: expect.anything(),
  33. linkToImgUrl: "",
  34. max: 10 * 1024 * 1024,
  35. url: "",
  36. accept: '.jpg'
  37. },
  38. })
  39. })
  40. test('Options classes', () => {
  41. const options = new Options({
  42. classes: {
  43. preview: "content-reset",
  44. },
  45. });
  46. expect(options.merge()).toMatchObject({
  47. classes: {
  48. preview: "content-reset",
  49. },
  50. })
  51. });
  52. test('Options preview', () => {
  53. const options = new Options({
  54. preview: {
  55. url: 'https://hacpai.com/md',
  56. mode: 'both',
  57. },
  58. });
  59. expect(options.merge()).toMatchObject({
  60. preview: {
  61. url: 'https://hacpai.com/md',
  62. delay: 1000,
  63. mode: 'both',
  64. },
  65. })
  66. });
  67. test('Options preview hljs', () => {
  68. const options = new Options({
  69. preview: {
  70. mode: 'both',
  71. hljs: {
  72. style: 'github'
  73. }
  74. },
  75. });
  76. expect(options.merge().preview).toEqual({
  77. delay: 1000,
  78. mode: 'both',
  79. hljs: {
  80. style: 'github',
  81. enable: true,
  82. }
  83. })
  84. });
  85. test('Options hint', () => {
  86. const options = new Options({
  87. hint: {
  88. emojiTail: '前往设置',
  89. emoji: {
  90. "+1": "👍",
  91. },
  92. },
  93. });
  94. expect(options.merge()).toMatchObject({
  95. hint: {
  96. delay: 200,
  97. emojiTail: '前往设置',
  98. emoji: {
  99. "+1": "👍",
  100. },
  101. emojiPath: "https://cdn.jsdelivr.net/npm/vditor/src/assets/emoji",
  102. },
  103. })
  104. });
  105. test('Options resize', () => {
  106. const options = new Options({
  107. resize: {
  108. enable: true,
  109. },
  110. })
  111. expect(options.merge()).toMatchObject({
  112. resize: {
  113. enable: true,
  114. position: "bottom",
  115. },
  116. })
  117. });
  118. })