Explorar o código

fix: align public upload validation

Developer hai 3 días
pai
achega
5d44adb47b

+ 1 - 1
src/components/team-background/TeamBackgroundUploadQueue.vue

@@ -21,7 +21,7 @@
           @click="$emit('retry', item)"
         >重试</el-button>
         <el-button
-          v-if="item.status !== 'uploading'"
+          v-if="item.status !== 'uploading' && item.status !== 'success'"
           type="text"
           size="mini"
           @click="$emit('remove', item)"

+ 11 - 0
src/utils/teamBackgroundFile.js

@@ -2,6 +2,17 @@ export const ALLOWED_EXTENSIONS = ['pdf','doc','docx','xls','xlsx','ppt','pptx',
 export const ACCEPT = ALLOWED_EXTENSIONS.map(ext => `.${ext}`).join(',')
 export const MAX_FILE_SIZE = 50 * 1024 * 1024
 
+export function validateEnterpriseWebsite(value) {
+  const normalized = String(value || '').trim()
+  if (!normalized) return '请输入企业官网,无官网请填写“无”'
+  if (normalized.length > 500) return '企业官网不能超过500个字符'
+  if (normalized === '无') return ''
+  if (!/^https?:\/\/[^/\s?#]+(?:[/?#][^\s]*)?$/i.test(normalized)) {
+    return '请输入以http://或https://开头的企业官网'
+  }
+  return ''
+}
+
 export function validateBackgroundFile(file) {
   if (!file || !file.name || file.size === 0) return '请选择非空文件'
   if (file.name.length > 255) return '文件名不能超过255个字符'

+ 1 - 0
src/views/pages/team-background-upload.vue

@@ -350,6 +350,7 @@ export default {
     },
     removeQueueItem(item) {
       if (this.state !== 'ready' || this.completing) return
+      if (!item || item.status === 'success') return
       const index = this.queue.findIndex(candidate => candidate.id === item.id)
       if (index >= 0) this.queue.splice(index, 1)
     },

+ 14 - 1
tests/unit/teamBackgroundFile.spec.js

@@ -1,4 +1,9 @@
-import { ACCEPT, formatFileSize, validateBackgroundFile } from '@/utils/teamBackgroundFile'
+import {
+  ACCEPT,
+  formatFileSize,
+  validateBackgroundFile,
+  validateEnterpriseWebsite
+} from '@/utils/teamBackgroundFile'
 import request from '@/utils/request2'
 import {
   completePublicUpload,
@@ -73,6 +78,14 @@ test('formats byte counts across byte, KB and MB thresholds', () => {
   expect(formatFileSize(1.5 * 1024 * 1024)).toBe('1.5 MB')
 })
 
+test('enforces the backend enterprise website 500-character boundary', () => {
+  const website = length => `https://example.com/${'a'.repeat(length - 20)}`
+
+  expect(validateEnterpriseWebsite(website(499))).toBe('')
+  expect(validateEnterpriseWebsite(website(500))).toBe('')
+  expect(validateEnterpriseWebsite(website(501))).toContain('500')
+})
+
 test('uses backend-controlled authenticated file routes', () => {
   listTeamBackgroundFiles(7)
   createTeamBackgroundSession(7)

+ 22 - 0
tests/unit/teamBackgroundPublicUpload.spec.js

@@ -8,6 +8,7 @@ process.env.BROWSERSLIST_IGNORE_OLD_DATA = 'true'
 
 const routerPath = path.resolve(__dirname, '../../src/router/index.js')
 const pagePath = path.resolve(__dirname, '../../src/views/pages/team-background-upload.vue')
+const queuePath = path.resolve(__dirname, '../../src/components/team-background/TeamBackgroundUploadQueue.vue')
 
 const readIfPresent = file => fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : ''
 
@@ -687,6 +688,27 @@ describe('public team background upload page state machine', () => {
     expect(api.completePublicUpload).toHaveBeenCalledTimes(1)
   })
 
+  test('a successful upload cannot be removed or omitted from the completion count', async () => {
+    if (!expectPage(source)) return
+    const successful = { id: 'success', status: 'success' }
+    const failed = { id: 'failed', status: 'failed' }
+    const vm = createPageVm(api, {
+      state: 'ready',
+      session: { uploadToken: 'upload-token' },
+      queue: [successful, failed]
+    })
+    api.completePublicUpload.mockResolvedValue({ code: 0 })
+
+    vm.removeQueueItem(successful)
+    expect(vm.queue).toContain(successful)
+    await vm.completeUpload()
+
+    expect(vm.successCount).toBe(1)
+    expect(readIfPresent(queuePath)).toContain(
+      'v-if="item.status !== \'uploading\' && item.status !== \'success\'"'
+    )
+  })
+
   test('completion closes empty and all-failed queues with a zero success count', async () => {
     if (!expectPage(source)) return
     api.completePublicUpload.mockResolvedValue({ code: 0 })