feat(support-chat): infer intent with model and remove scope tabs

This commit is contained in:
devops committed 2026-10-14 19:20:41 +00:00
1 parent e0581f22aa
commit 33afd7f45a
10 files changed
+110 -68

No files matched your search

@@ -5,13 +5,14 @@ import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/re
import SupportChat from './SupportChat';
afterEach(() => { cleanup(); vi.restoreAllMocks(); localStorage.clear(); });
describe('support widget', () => {
it('submits only message and explicit scope, renders text safely', async () => {
it('submits only message without scope tabs, renders text safely', async () => {
const fetcher=vi.spyOn(globalThis,'fetch').mockResolvedValue({ok:true,json:async()=>({answer:'<script>bad</script>'})} as Response);
render(<SupportChat/>); fireEvent.click(screen.getByRole('button',{name:/گفتگو با پشتیبان/}));
fireEvent.change(screen.getByLabelText('پیام شما'),{target:{value:'مکمل سگ'}}); fireEvent.click(screen.getByRole('button',{name:'ارسال'}));
await waitFor(()=>expect(screen.getByText('<script>bad</script>')).toBeTruthy());
expect(JSON.parse(fetcher.mock.calls[0][1]!.body as string)).toEqual({message:'مکمل سگ',scope:'public'});
expect(JSON.parse(fetcher.mock.calls[0][1]!.body as string)).toEqual({message:'مکمل سگ'});
expect(document.querySelector('script')).toBeNull();
for (const label of ['محصولات و عمومی','سفارش‌های من','کیف پول']) expect(screen.queryByRole('button',{name:label})).toBeNull();
});
it('does not expose upstream errors', async()=> {
vi.spyOn(globalThis,'fetch').mockResolvedValue({ok:false,status:503,json:async()=>({message:'secret-provider'})} as Response);