Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
import SearchAnswerPanel, { type SearchAnswerPanelProps } from './SearchAnswerPanel';
|
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
const defaultProps: SearchAnswerPanelProps = {
|
|
isLoading: false,
|
|
disabled: false,
|
|
emptyReason: 'No sources are available.',
|
|
onGenerate: jest.fn(),
|
|
};
|
|
|
|
const renderPanel = (props: Partial<SearchAnswerPanelProps> = {}) =>
|
|
render(<SearchAnswerPanel {...defaultProps} {...props} />, {
|
|
wrapper: mockAppRoot()
|
|
.withTranslations('en', 'core', {
|
|
Search_AI_answer: 'AI answer',
|
|
Search_AI_answer_ready: 'Generate an answer from these sources.',
|
|
Search_AI_answer_provider: 'Generated by {{provider}} using {{model}}',
|
|
Search_AI_answer_error: 'The answer could not be generated.',
|
|
Generate: 'Generate',
|
|
Regenerate: 'Regenerate',
|
|
Loading: 'Loading',
|
|
})
|
|
.build(),
|
|
});
|
|
|
|
describe('SearchAnswerPanel', () => {
|
|
it('offers to generate an answer when sources are available', async () => {
|
|
const user = userEvent.setup();
|
|
const onGenerate = jest.fn();
|
|
renderPanel({ onGenerate });
|
|
|
|
expect(screen.getByText('Generate an answer from these sources.')).toBeInTheDocument();
|
|
await user.click(screen.getByRole('button', { name: 'Generate' }));
|
|
expect(onGenerate).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('renders the disabled reason when an answer cannot be generated', () => {
|
|
renderPanel({ disabled: true, emptyReason: 'No related messages were found.' });
|
|
|
|
expect(screen.getByText('No related messages were found.')).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: 'Generate' })).toBeDisabled();
|
|
});
|
|
|
|
it('renders a loading state and disables generation', () => {
|
|
renderPanel({ isLoading: true });
|
|
|
|
expect(screen.getByLabelText('Loading')).toHaveAttribute('aria-busy', 'true');
|
|
expect(screen.getByRole('button', { name: 'Loading' })).toBeDisabled();
|
|
});
|
|
|
|
it('renders markdown and provider metadata for a generated answer', () => {
|
|
renderPanel({
|
|
answer: '**Deployment** completed successfully.',
|
|
provider: { name: 'OpenAI compatible', model: 'example-model' },
|
|
});
|
|
|
|
expect(screen.getByText('Deployment').tagName).toBe('STRONG');
|
|
expect(screen.getByText('Generated by OpenAI compatible using example-model')).toBeInTheDocument();
|
|
expect(screen.getByRole('button', { name: 'Regenerate' })).toBeEnabled();
|
|
});
|
|
|
|
it('renders a generation error instead of the answer content', () => {
|
|
renderPanel({ error: new Error('request failed') });
|
|
|
|
expect(screen.getByText('The answer could not be generated.')).toBeInTheDocument();
|
|
expect(screen.queryByText('Generate an answer from these sources.')).not.toBeInTheDocument();
|
|
});
|
|
});
|