image-labels.client.spec.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { describe, expect, it } from 'vitest'
  2. import { makeTranslate } from '@deepseek-ai/dsh-client-test-runtime'
  3. import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts'
  4. import { attachmentErrorText, imageSizeText } from '../src/client/image-labels.ts'
  5. import { en, zh } from '../src/client/locales.ts'
  6. const t = makeTranslate(zh, commonZh)
  7. const enT = makeTranslate(en, commonZh)
  8. describe('attachment rejection copy', () => {
  9. const limits = {
  10. maxImageBytes: 5 * 1024 * 1024,
  11. maxImagesPerMessage: 20,
  12. maxMessageImageBytes: 100 * 1024 * 1024,
  13. maxImagePixels: 40_000_000,
  14. maxImageDimension: 2000,
  15. mediaTypes: ['image/png'] as const,
  16. }
  17. it('renders megabytes without a trailing fraction unless one exists', () => {
  18. expect(imageSizeText(10 * 1024 * 1024)).toBe('10MB')
  19. expect(imageSizeText(2.5 * 1024 * 1024)).toBe('2.5MB')
  20. })
  21. it('maps user-solvable reasons to limit-naming copy', () => {
  22. expect(attachmentErrorText(t, 'MODEL_DOES_NOT_SUPPORT_IMAGES')).toBe('当前模型不支持图片,请切换支持图片的模型')
  23. expect(attachmentErrorText(t, 'IMAGE_TOO_MANY_PIXELS')).toBe('图片分辨率过大,请压缩后重试')
  24. expect(attachmentErrorText(t, 'INVALID_IMAGE')).toBe('仅支持 PNG、JPG、WebP、GIF 格式的图片')
  25. expect(attachmentErrorText(t, 'IMAGE_TYPE_MISMATCH')).toBe('仅支持 PNG、JPG、WebP、GIF 格式的图片')
  26. expect(attachmentErrorText(t, 'TOO_MANY_IMAGES', limits)).toBe('一条消息最多添加 20 张图片')
  27. expect(attachmentErrorText(t, 'IMAGE_TOO_LARGE', limits)).toBe('单张图片不能超过 5MB')
  28. expect(attachmentErrorText(t, 'IMAGES_TOO_LARGE', limits)).toBe('图片总大小超过 100MB,请移除部分图片')
  29. expect(attachmentErrorText(t, 'IMAGE_DIMENSION_TOO_LARGE', limits)).toBe('图片宽高不能超过 2000px,请缩小后重试')
  30. expect(attachmentErrorText(enT, 'TOO_MANY_IMAGES', limits)).toBe('A message can include up to 20 images')
  31. })
  32. it('folds unknown reasons and limit reasons without projected limits into the send-failed line', () => {
  33. expect(attachmentErrorText(t, 'INVALID_IMAGE_BASE64')).toBe('图片发送失败(INVALID_IMAGE_BASE64),请重新添加图片后再试')
  34. expect(attachmentErrorText(t, 'TOO_MANY_IMAGES')).toBe('图片发送失败(TOO_MANY_IMAGES),请重新添加图片后再试')
  35. expect(attachmentErrorText(t, 'IMAGE_TOO_LARGE')).toBe('图片发送失败(IMAGE_TOO_LARGE),请重新添加图片后再试')
  36. expect(attachmentErrorText(t, 'IMAGES_TOO_LARGE')).toBe('图片发送失败(IMAGES_TOO_LARGE),请重新添加图片后再试')
  37. expect(attachmentErrorText(t, 'IMAGE_DIMENSION_TOO_LARGE')).toBe('图片发送失败(IMAGE_DIMENSION_TOO_LARGE),请重新添加图片后再试')
  38. })
  39. })