| 12345678910111213141516171819202122232425262728293031323334 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import fs from 'node:fs'
- import path from 'node:path'
- const editorFile = path.resolve('src/components/editor/index.vue')
- const activityFile = path.resolve('src/views/modules/activity/add.vue')
- test('富文本图片上传配置大小限制并提示失败原因', () => {
- const source = fs.readFileSync(editorFile, 'utf8')
- assert.match(source, /MAX_IMAGE_SIZE\s*=\s*10\s*\*\s*1024\s*\*\s*1024/)
- assert.match(source, /maxFileSize:\s*MAX_IMAGE_SIZE/)
- 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/)
- assert.match(source, /return false/)
- assert.match(source, /onFailed\s*:\s*\(file,\s*res\)/)
- assert.match(source, /onError\s*:\s*\(file,\s*xhr,\s*error\)/)
- })
- test('富文本图片链接插入配置校验地址并反馈插入结果', () => {
- const source = fs.readFileSync(editorFile, 'utf8')
- assert.match(source, /insertImage:\s*\{[\s\S]*checkImage:\s*\(src\)[\s\S]*请输入有效的图片链接地址/)
- assert.match(source, /onInsertedImage:\s*\(image\)/)
- })
- test('活动封面和 banner 显示图片大小限制并处理裁剪上传失败', () => {
- const source = fs.readFileSync(activityFile, 'utf8')
- assert.match(source, /单张图片不超过\s*10MB/)
- assert.match(source, /file\.size\s*>\s*MAX_IMAGE_SIZE/)
- assert.match(source, /cropperUpload\s*\(data\)[\s\S]*\.catch\s*\(/)
- assert.match(source, /cropperUpload2\s*\(data\)[\s\S]*\.catch\s*\(/)
- })
|