Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore: tests form add annotation (#29770)
Joel5bb1346da857
diff --git a/web/app/components/app/annotation/add-annotation-modal/edit-item/index.spec.tsx b/web/app/components/app/annotation/add-annotation-modal/edit-item/index.spec.tsxnew file mode 100644index 00000000000..356f813afc9--- /dev/null+++ b/web/app/components/app/annotation/add-annotation-modal/edit-item/index.spec.tsx@@ -0,0 +1,53 @@+import React from 'react'+import { fireEvent, render, screen } from '@testing-library/react'+import EditItem, { EditItemType } from './index'++jest.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ }),+}))++describe('AddAnnotationModal/EditItem', () => {+ test('should render query inputs with user avatar and placeholder strings', () => {+ render(+ <EditItem+ type={EditItemType.Query}+ content="Why?"+ onChange={jest.fn()}+ />,+ )++ expect(screen.getByText('appAnnotation.addModal.queryName')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('appAnnotation.addModal.queryPlaceholder')).toBeInTheDocument()+ expect(screen.getByText('Why?')).toBeInTheDocument()+ })++ test('should render answer name and placeholder text', () => {+ render(+ <EditItem+ type={EditItemType.Answer}+ content="Existing answer"+ onChange={jest.fn()}+ />,+ )++ expect(screen.getByText('appAnnotation.addModal.answerName')).toBeInTheDocument()+ expect(screen.getByPlaceholderText('appAnnotation.addModal.answerPlaceholder')).toBeInTheDocument()+ expect(screen.getByDisplayValue('Existing answer')).toBeInTheDocument()+ })++ test('should propagate changes when answer content updates', () => {+ const handleChange = jest.fn()+ render(+ <EditItem+ type={EditItemType.Answer}+ content=""+ onChange={handleChange}+ />,+ )++ fireEvent.change(screen.getByPlaceholderText('appAnnotation.addModal.answerPlaceholder'), { target: { value: 'Because' } })+ expect(handleChange).toHaveBeenCalledWith('Because')+ })+})diff --git a/web/app/components/app/annotation/add-annotation-modal/index.spec.tsx b/web/app/components/app/annotation/add-annotation-modal/index.spec.tsxnew file mode 100644index 00000000000..3103e3c96de--- /dev/null+++ b/web/app/components/app/annotation/add-annotation-modal/index.spec.tsx@@ -0,0 +1,155 @@+import React from 'react'+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'+import AddAnnotationModal from './index'+import { useProviderContext } from '@/context/provider-context'++jest.mock('@/context/provider-context', () => ({+ useProviderContext: jest.fn(),+}))++const mockToastNotify = jest.fn()+jest.mock('@/app/components/base/toast', () => ({+ __esModule: true,+ default: {+ notify: jest.fn(args => mockToastNotify(args)),+ },+}))++jest.mock('@/app/components/billing/annotation-full', () => () => <div data-testid="annotation-full" />)++const mockUseProviderContext = useProviderContext as jest.Mock++const getProviderContext = ({ usage = 0, total = 10, enableBilling = false } = {}) => ({+ plan: {+ usage: { annotatedResponse: usage },+ total: { annotatedResponse: total },+ },+ enableBilling,+})++describe('AddAnnotationModal', () => {+ const baseProps = {+ isShow: true,+ onHide: jest.fn(),+ onAdd: jest.fn(),+ }++ beforeEach(() => {+ jest.clearAllMocks()+ mockUseProviderContext.mockReturnValue(getProviderContext())+ })++ const typeQuestion = (value: string) => {+ fireEvent.change(screen.getByPlaceholderText('appAnnotation.addModal.queryPlaceholder'), {+ target: { value },+ })+ }++ const typeAnswer = (value: string) => {+ fireEvent.change(screen.getByPlaceholderText('appAnnotation.addModal.answerPlaceholder'), {+ target: { value },+ })+ }++ test('should render modal title when drawer is visible', () => {+ render(<AddAnnotationModal {...baseProps} />)++ expect(screen.getByText('appAnnotation.addModal.title')).toBeInTheDocument()+ })++ test('should capture query input text when typing', () => {+ render(<AddAnnotationModal {...baseProps} />)+ typeQuestion('Sample question')+ expect(screen.getByPlaceholderText('appAnnotation.addModal.queryPlaceholder')).toHaveValue('Sample question')+ })++ test('should capture answer input text when typing', () => {+ render(<AddAnnotationModal {...baseProps} />)+ typeAnswer('Sample answer')+ expect(screen.getByPlaceholderText('appAnnotation.addModal.answerPlaceholder')).toHaveValue('Sample answer')+ })++ test('should show annotation full notice and disable submit when quota exceeded', () => {+ mockUseProviderContext.mockReturnValue(getProviderContext({ usage: 10, total: 10, enableBilling: true }))+ render(<AddAnnotationModal {...baseProps} />)++ expect(screen.getByTestId('annotation-full')).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'common.operation.add' })).toBeDisabled()+ })++ test('should call onAdd with form values when create next enabled', async () => {+ const onAdd = jest.fn().mockResolvedValue(undefined)+ render(<AddAnnotationModal {...baseProps} onAdd={onAdd} />)++ typeQuestion('Question value')+ typeAnswer('Answer value')+ fireEvent.click(screen.getByTestId('checkbox-create-next-checkbox'))++ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'common.operation.add' }))+ })++ expect(onAdd).toHaveBeenCalledWith({ question: 'Question value', answer: 'Answer value' })+ })++ test('should reset fields after saving when create next enabled', async () => {+ const onAdd = jest.fn().mockResolvedValue(undefined)+ render(<AddAnnotationModal {...baseProps} onAdd={onAdd} />)++ typeQuestion('Question value')+ typeAnswer('Answer value')+ const createNextToggle = screen.getByText('appAnnotation.addModal.createNext').previousElementSibling as HTMLElement+ fireEvent.click(createNextToggle)++ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'common.operation.add' }))+ })++ await waitFor(() => {+ expect(screen.getByPlaceholderText('appAnnotation.addModal.queryPlaceholder')).toHaveValue('')+ expect(screen.getByPlaceholderText('appAnnotation.addModal.answerPlaceholder')).toHaveValue('')+ })+ })++ test('should show toast when validation fails for missing question', () => {+ render(<AddAnnotationModal {...baseProps} />)++ fireEvent.click(screen.getByRole('button', { name: 'common.operation.add' }))+ expect(mockToastNotify).toHaveBeenCalledWith(expect.objectContaining({+ type: 'error',+ message: 'appAnnotation.errorMessage.queryRequired',+ }))+ })++ test('should show toast when validation fails for missing answer', () => {+ render(<AddAnnotationModal {...baseProps} />)+ typeQuestion('Filled question')+ fireEvent.click(screen.getByRole('button', { name: 'common.operation.add' }))++ expect(mockToastNotify).toHaveBeenCalledWith(expect.objectContaining({+ type: 'error',+ message: 'appAnnotation.errorMessage.answerRequired',+ }))+ })++ test('should close modal when save completes and create next unchecked', async () => {+ const onAdd = jest.fn().mockResolvedValue(undefined)+ render(<AddAnnotationModal {...baseProps} onAdd={onAdd} />)++ typeQuestion('Q')+ typeAnswer('A')++ await act(async () => {+ fireEvent.click(screen.getByRole('button', { name: 'common.operation.add' }))+ })++ expect(baseProps.onHide).toHaveBeenCalled()+ })++ test('should allow cancel button to close the drawer', () => {+ render(<AddAnnotationModal {...baseProps} />)++ fireEvent.click(screen.getByRole('button', { name: 'common.operation.cancel' }))+ expect(baseProps.onHide).toHaveBeenCalled()+ })+})diff --git a/web/app/components/app/annotation/add-annotation-modal/index.tsx b/web/app/components/app/annotation/add-annotation-modal/index.tsxindex 274a57adf1e..0ae44395318 100644--- a/web/app/components/app/annotation/add-annotation-modal/index.tsx+++ b/web/app/components/app/annotation/add-annotation-modal/index.tsx@@ -101,7 +101,7 @@ const AddAnnotationModal: FC<Props> = ({<divclassName='flex items-center space-x-2'>- <Checkbox checked={isCreateNext} onCheck={() => setIsCreateNext(!isCreateNext)} />+ <Checkbox id='create-next-checkbox' checked={isCreateNext} onCheck={() => setIsCreateNext(!isCreateNext)} /><div>{t('appAnnotation.addModal.createNext')}</div></div><div className='mt-2 flex space-x-2'>