|
|
|
@ -9,11 +9,7 @@ import { locationService } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
|
import { GenAIButton, GenAIButtonProps } from './GenAIButton'; |
|
|
|
|
import { useOpenAIStream } from './hooks'; |
|
|
|
|
import { Role, isLLMPluginEnabled } from './utils'; |
|
|
|
|
|
|
|
|
|
jest.mock('./utils', () => ({ |
|
|
|
|
isLLMPluginEnabled: jest.fn(), |
|
|
|
|
})); |
|
|
|
|
import { Role } from './utils'; |
|
|
|
|
|
|
|
|
|
const mockedUseOpenAiStreamState = { |
|
|
|
|
setMessages: jest.fn(), |
|
|
|
@ -40,40 +36,28 @@ describe('GenAIButton', () => { |
|
|
|
|
|
|
|
|
|
describe('when LLM plugin is not configured', () => { |
|
|
|
|
beforeAll(() => { |
|
|
|
|
jest.mocked(isLLMPluginEnabled).mockResolvedValue(false); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should render text ', async () => { |
|
|
|
|
const { getByText } = setup(); |
|
|
|
|
waitFor(() => expect(getByText('Auto-generate')).toBeInTheDocument()); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should disable the button', async () => { |
|
|
|
|
const { getByRole } = setup(); |
|
|
|
|
waitFor(() => expect(getByRole('button')).toBeDisabled()); |
|
|
|
|
jest.mocked(useOpenAIStream).mockReturnValue({ |
|
|
|
|
error: undefined, |
|
|
|
|
isGenerating: false, |
|
|
|
|
reply: 'Some completed genereated text', |
|
|
|
|
setMessages: jest.fn(), |
|
|
|
|
value: { |
|
|
|
|
enabled: false, |
|
|
|
|
stream: new Observable().subscribe(), |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should display an error message when hovering', async () => { |
|
|
|
|
const { getByRole, getByTestId } = setup(); |
|
|
|
|
|
|
|
|
|
// Wait for the check to be completed
|
|
|
|
|
const button = getByRole('button'); |
|
|
|
|
await waitFor(() => expect(button).toBeDisabled()); |
|
|
|
|
await userEvent.hover(button); |
|
|
|
|
|
|
|
|
|
const tooltip = await waitFor(() => getByTestId(selectors.components.Tooltip.container)); |
|
|
|
|
expect(tooltip).toBeVisible(); |
|
|
|
|
it('should not render anything', async () => { |
|
|
|
|
setup(); |
|
|
|
|
|
|
|
|
|
// The tooltip keeps interactive to be able to click the link
|
|
|
|
|
await userEvent.hover(tooltip); |
|
|
|
|
expect(tooltip).toBeVisible(); |
|
|
|
|
waitFor(async () => expect(await screen.findByText('Auto-generate')).not.toBeInTheDocument()); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('when LLM plugin is properly configured, so it is enabled', () => { |
|
|
|
|
const setMessagesMock = jest.fn(); |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.mocked(isLLMPluginEnabled).mockResolvedValue(true); |
|
|
|
|
jest.mocked(useOpenAIStream).mockReturnValue({ |
|
|
|
|
error: undefined, |
|
|
|
|
isGenerating: false, |
|
|
|
@ -125,7 +109,6 @@ describe('GenAIButton', () => { |
|
|
|
|
|
|
|
|
|
describe('when it is generating data', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.mocked(isLLMPluginEnabled).mockResolvedValue(true); |
|
|
|
|
jest.mocked(useOpenAIStream).mockReturnValue({ |
|
|
|
|
error: undefined, |
|
|
|
|
isGenerating: true, |
|
|
|
@ -171,7 +154,6 @@ describe('GenAIButton', () => { |
|
|
|
|
describe('when there is an error generating data', () => { |
|
|
|
|
const setMessagesMock = jest.fn(); |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.mocked(isLLMPluginEnabled).mockResolvedValue(true); |
|
|
|
|
jest.mocked(useOpenAIStream).mockReturnValue({ |
|
|
|
|
error: new Error('Something went wrong'), |
|
|
|
|
isGenerating: false, |
|
|
|
|