Files
gochat/frontend/app/javascript/dashboard/components-next/message/bubbles/specs/Activity.spec.js
T
Rogeeandrogee 1b5ea7c227 HH-551: localize activity messages (#132)
* fix(HH-551): localize activity messages

* fix(HH-551): handle null activity content

---------

Co-authored-by: Rogee <rogee@ipao.vip>
2026-08-23 21:21:44 +08:00

109 lines
3.1 KiB
JavaScript

import { config, mount } from '@vue/test-utils';
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import Activity from '../Activity.vue';
const mocks = vi.hoisted(() => ({
content: '',
}));
vi.mock('shared/helpers/timeHelper', () => ({
messageTimestamp: () => '8月6日 下午 3:12',
}));
const longURL =
'https://ada.baidu.com/site/wjzt6ah8/agent?imid=e159aa97cd2c403f2fba76899e47615f&trinfo=XzFWIaclcWbzcMY&word=%E4%B8%89%E9%98%B3%E7%97%85%E6%AF%92%E6%90%BA%E5%B8%A6';
const i18n = config.global.plugins.find(plugin => plugin.global?.locale);
const initialLocale = i18n.global.locale.value;
beforeAll(() => {
i18n.global.locale.value = 'zh_CN';
});
afterAll(() => {
i18n.global.locale.value = initialLocale;
});
vi.mock('../../provider.js', async () => {
const { ref } = await vi.importActual('vue');
return {
useMessageContext: () => ({
content: ref(mocks.content),
createdAt: ref(1786018000),
}),
};
});
const mountActivity = () =>
mount(Activity, {
global: {
directives: {
dompurifyHtml: (element, binding) => {
element.innerHTML = binding.value;
},
},
stubs: {
BaseBubble: {
template: '<div><slot /></div>',
},
},
},
});
describe('Activity bubble', () => {
it('allows long links in system messages to wrap inside the bubble', () => {
mocks.content = `来源页面:<a href="${longURL}">${longURL}</a>`;
const wrapper = mountActivity();
expect(wrapper.get('[data-bubble-name="activity"]').classes()).toContain(
'max-w-full'
);
const content = wrapper.get('span');
expect(content.classes()).toContain('min-w-0');
expect(content.classes()).toContain('max-w-full');
expect(content.classes()).toContain('[overflow-wrap:anywhere]');
expect(content.get('a').text()).toBe(longURL);
});
it.each([
['Conversation was resolved by Anonymous Visitor', '会话已由匿名访客解决'],
['Conversation was resolved by Alice', '会话已由Alice解决'],
[
'Conversation was reopened due to agent bot webhook failure',
'由于客服机器人 Webhook 失败,会话已重新打开',
],
[
'CSAT survey not sent due to outgoing message restrictions',
'由于发送消息受限,未发送 CSAT 调查',
],
[
'Linear issue ENG-1 was created by Alice',
'Linear 问题 ENG-1 已由 Alice 创建',
],
[
'Linear issue ENG-1 was linked by Alice',
'Linear 问题 ENG-1 已由 Alice 关联',
],
[
'Linear issue ENG-1 was unlinked by Alice',
'Linear 问题 ENG-1 已由 Alice 取消关联',
],
])('localizes known backend activity content: %s', (content, expected) => {
mocks.content = content;
const wrapper = mountActivity();
expect(wrapper.get('[data-bubble-name="activity"] span').text()).toBe(
expected
);
});
it('renders an empty activity when content is null', () => {
mocks.content = null;
const wrapper = mountActivity();
expect(wrapper.get('[data-bubble-name="activity"] span').text()).toBe('');
});
});