fix:图片上传修改
build / task (16.x, npm, macOS-latest) (push) Canceled after 0s
build / task (16.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, npm, windows-latest) (push) Canceled after 0s
build / task (16.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (16.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (16.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (16.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, yarn, windows-latest) (push) Canceled after 0s
build / task (18.x, npm, macOS-latest) (push) Canceled after 0s
build / task (18.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, npm, windows-latest) (push) Canceled after 0s
build / task (18.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (18.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (18.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (18.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, yarn, windows-latest) (push) Canceled after 0s
build / task (20.x, npm, macOS-latest) (push) Canceled after 0s
build / task (20.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, npm, windows-latest) (push) Canceled after 0s
build / task (20.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (20.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (20.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (20.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, yarn, windows-latest) (push) Canceled after 0s
build / task (16.x, npm, macOS-latest) (push) Canceled after 0s
build / task (16.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, npm, windows-latest) (push) Canceled after 0s
build / task (16.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (16.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (16.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (16.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, yarn, windows-latest) (push) Canceled after 0s
build / task (18.x, npm, macOS-latest) (push) Canceled after 0s
build / task (18.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, npm, windows-latest) (push) Canceled after 0s
build / task (18.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (18.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (18.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (18.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, yarn, windows-latest) (push) Canceled after 0s
build / task (20.x, npm, macOS-latest) (push) Canceled after 0s
build / task (20.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, npm, windows-latest) (push) Canceled after 0s
build / task (20.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (20.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (20.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (20.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, yarn, windows-latest) (push) Canceled after 0s
This commit is contained in:
1 parent
fb3f8ae277
commit
fbf163e3f2
4 files changed
+103
-53
No files matched your search
@@ -0,0 +1,62 @@
|
||||
const { test } = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const vue = require('vue')
|
||||
const { parse, compileScript } = require('@vue/compiler-sfc')
|
||||
const { compile, root } = require('./helpers/file-access-runtime.cjs')
|
||||
|
||||
function setup(name, request) {
|
||||
const notifications = [], events = [], model = vue.ref('')
|
||||
const descriptor = parse(fs.readFileSync(path.join(root, 'src/components/Upload', name), 'utf8')).descriptor
|
||||
const loaded = { exports: {} }
|
||||
const mockVue = { ...vue, inject() {}, onMounted() {}, onBeforeUnmount() {}, useModel: () => model }
|
||||
const mocks = {
|
||||
vue: mockVue,
|
||||
'element-plus': { ElNotification: value => notifications.push(value), formContextKey: Symbol(), formItemContextKey: Symbol() },
|
||||
'@element-plus/icons-vue': {},
|
||||
'/@/utils/request': { default: request },
|
||||
'/@/utils/other': { generateUUID: () => 'upload-test' },
|
||||
'/@/utils/file-access': { fileUrl: value => value, originalFileUrl: value => value, resolveFileUrl: value => value },
|
||||
'/@/utils/file-access-dom': { bindFileAccessDom() {} },
|
||||
}
|
||||
const globals = { inject: mockVue.inject, computed: vue.computed, onMounted() {}, onBeforeUnmount() {} }
|
||||
const source = compileScript(descriptor, { id: name }).content.replace(/import\.meta\.env/g, '({})')
|
||||
new Function('module', 'exports', 'require', ...Object.keys(globals), compile(source))(
|
||||
loaded, loaded.exports, key => key in mocks ? mocks[key] : require(key), ...Object.values(globals))
|
||||
const props = {}
|
||||
for (const [name, settings] of Object.entries(loaded.exports.default.props)) {
|
||||
if ('default' in settings) props[name] = typeof settings.default === 'function' ? settings.default() : settings.default
|
||||
}
|
||||
const state = loaded.exports.default.setup(props, { expose() {}, emit: (...args) => events.push(args) })
|
||||
return { state, props, notifications, events, model }
|
||||
}
|
||||
|
||||
for (const name of ['Image.vue', 'Images.vue', 'qnImages.vue']) {
|
||||
test(name + ': WebP is allowed by default and backend errors never trigger a success notification', async () => {
|
||||
const failure = { msg: '图片实际格式未在白名单中' }
|
||||
const { state, props, notifications, events } = setup(name, async () => { throw failure })
|
||||
const file = new File(['public test fixture'], 'logo.webp', { type: 'image/webp' })
|
||||
assert.ok(props.fileType.includes('image/webp'))
|
||||
assert.equal(state.beforeUpload(file), true)
|
||||
assert.equal(notifications.length, 0)
|
||||
let callbackCount = 0
|
||||
await state.handleHttpUpload({ file, onError() { callbackCount++ } })
|
||||
.then(state.uploadSuccess, state.uploadError)
|
||||
assert.equal(callbackCount, 0, 'Element Plus handles the rejected Promise once')
|
||||
assert.deepEqual(notifications.map(value => [value.type, value.message]), [['error', failure.msg]])
|
||||
assert.equal(events.length, 0)
|
||||
props.fileType = ['image/png']
|
||||
assert.equal(state.beforeUpload(file), false, 'explicit business type restrictions are respected')
|
||||
})
|
||||
}
|
||||
|
||||
test('single-image uploads preserve the canonical raw WebP URL returned by the server', async () => {
|
||||
const raw = '/admin/sys-file/oss/file?fileName=logo.webp'
|
||||
const { state, events } = setup('Image.vue', async options => {
|
||||
assert.equal(options.data.get('file').name, 'logo.png')
|
||||
return { code: 0, data: { url: raw } }
|
||||
})
|
||||
await state.handleHttpUpload({ file: new File(['test'], 'logo.png', { type: 'image/png' }) })
|
||||
assert.deepEqual(events, [['update:imageUrl', raw]])
|
||||
})
|
||||
Reference in new issue
Block a user