activity-image-upload.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import fs from 'node:fs'
  4. import path from 'node:path'
  5. const editorFile = path.resolve('src/components/editor/index.vue')
  6. const activityFile = path.resolve('src/views/modules/activity/add.vue')
  7. test('富文本图片上传配置大小限制并提示失败原因', () => {
  8. const source = fs.readFileSync(editorFile, 'utf8')
  9. assert.match(source, /MAX_IMAGE_SIZE\s*=\s*10\s*\*\s*1024\s*\*\s*1024/)
  10. assert.match(source, /maxFileSize:\s*MAX_IMAGE_SIZE/)
  11. assert.match(source, /onBeforeUpload\s*:\s*\(files\)[\s\S]*Object\.values\(files\s*\|\|\s*\{\}\)[\s\S]*file\s*&&\s*file\.size\s*>\s*MAX_IMAGE_SIZE/)
  12. assert.match(source, /return false/)
  13. assert.match(source, /onFailed\s*:\s*\(file,\s*res\)/)
  14. assert.match(source, /onError\s*:\s*\(file,\s*xhr,\s*error\)/)
  15. })
  16. test('富文本图片链接插入配置校验地址并反馈插入结果', () => {
  17. const source = fs.readFileSync(editorFile, 'utf8')
  18. assert.match(source, /insertImage:\s*\{[\s\S]*checkImage:\s*\(src\)[\s\S]*请输入有效的图片链接地址/)
  19. assert.match(source, /onInsertedImage:\s*\(image\)/)
  20. })
  21. test('活动封面和 banner 显示图片大小限制并处理裁剪上传失败', () => {
  22. const source = fs.readFileSync(activityFile, 'utf8')
  23. assert.match(source, /单张图片不超过\s*10MB/)
  24. assert.match(source, /file\.size\s*>\s*MAX_IMAGE_SIZE/)
  25. assert.match(source, /cropperUpload\s*\(data\)[\s\S]*\.catch\s*\(/)
  26. assert.match(source, /cropperUpload2\s*\(data\)[\s\S]*\.catch\s*\(/)
  27. })