-
Notifications
You must be signed in to change notification settings - Fork 557
Expand file tree
/
Copy pathChatComposer.i18n.test.ts
More file actions
115 lines (105 loc) · 3.41 KB
/
Copy pathChatComposer.i18n.test.ts
File metadata and controls
115 lines (105 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// @vitest-environment happy-dom
import { afterEach, describe, expect, it } from 'vitest'
import { createApp, h, nextTick, ref } from 'vue'
import i18n, { loadLocaleMessages } from '@/i18n'
import type { Attachment } from '@/types/chat'
import ChatComposer from './ChatComposer.vue'
const BASE_PROPS = {
modelValue: '',
'onUpdate:modelValue': () => {},
busySendMode: 'queue',
hasSendContent: false,
isStreaming: false,
canStop: false,
isNewLanding: false,
placeholder: 'Send a message',
sendButtonTitle: 'Send',
runMode: 'safe',
allowedRunModes: ['safe', 'full'],
sessionRoutingMode: 'off',
sessionRoutingBusy: false,
routerVisualEffectsEnabled: true,
codingModeEnabled: false,
codingModeSettingsBusy: false,
voiceBusy: false,
voiceRecording: false,
voiceReady: true,
}
afterEach(() => {
document.body.innerHTML = ''
i18n.global.locale.value = 'en'
})
describe('ChatComposer attachment localization', () => {
it('renders and removes the intended attachment when recovered and new IDs differ', async () => {
const attachments = ref<Attachment[]>([
{
kind: 'staged',
local_id: -1,
name: 'recovered.txt',
mime: 'text/plain',
file_uuid: 'recovered-upload',
},
{
kind: 'staged',
local_id: 1,
name: 'new.txt',
mime: 'text/plain',
file_uuid: 'new-upload',
},
])
const el = document.createElement('div')
document.body.appendChild(el)
const app = createApp({
render: () => h(ChatComposer, {
...BASE_PROPS,
attachments: attachments.value,
onRemoveAttachment: (index: number) => attachments.value.splice(index, 1),
} as any),
})
app.use(i18n)
app.mount(el)
await nextTick()
expect([...el.querySelectorAll('.attachment-chip__name')].map(node => node.textContent))
.toEqual(['recovered.txt', 'new.txt'])
el.querySelectorAll<HTMLButtonElement>('.attachment-remove')[0]?.click()
await nextTick()
expect([...el.querySelectorAll('.attachment-chip__name')].map(node => node.textContent))
.toEqual(['new.txt'])
app.unmount()
})
it('localizes failed status, fallback file label, and retry accessibility text', async () => {
await loadLocaleMessages('zh-Hans')
i18n.global.locale.value = 'zh-Hans'
const attachments: Attachment[] = [
{
kind: 'failed',
local_id: 1,
name: '报告.pdf',
mime: 'application/pdf',
file: new File(['content'], '报告.pdf', { type: 'application/pdf' }),
},
{
kind: 'staged',
local_id: 2,
name: '无类型附件',
mime: '',
},
]
const el = document.createElement('div')
document.body.appendChild(el)
const app = createApp(ChatComposer, { ...BASE_PROPS, attachments })
app.use(i18n)
app.mount(el)
await nextTick()
const chips = el.querySelectorAll<HTMLElement>('.attachment-chip')
const retry = chips[0]?.querySelector<HTMLButtonElement>(
'.attachment-action:not(.attachment-remove)',
)
expect(chips[0]?.querySelector('.attachment-chip__meta')?.textContent).toBe('已失败')
expect(chips[0]?.title).toBe('报告.pdf 上传失败')
expect(retry?.title).toBe('重新上传')
expect(retry?.getAttribute('aria-label')).toBe('重新上传')
expect(chips[1]?.querySelector('.attachment-chip__meta')?.textContent).toBe('文件')
app.unmount()
})
})