chore: tests for goto anything (#29831)
This commit is contained in:
58
web/app/components/goto-anything/context.spec.tsx
Normal file
58
web/app/components/goto-anything/context.spec.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import React from 'react'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import { GotoAnythingProvider, useGotoAnythingContext } from './context'
|
||||
|
||||
let pathnameMock = '/'
|
||||
jest.mock('next/navigation', () => ({
|
||||
usePathname: () => pathnameMock,
|
||||
}))
|
||||
|
||||
let isWorkflowPageMock = false
|
||||
jest.mock('../workflow/constants', () => ({
|
||||
isInWorkflowPage: () => isWorkflowPageMock,
|
||||
}))
|
||||
|
||||
const ContextConsumer = () => {
|
||||
const { isWorkflowPage, isRagPipelinePage } = useGotoAnythingContext()
|
||||
return (
|
||||
<div data-testid="status">
|
||||
{String(isWorkflowPage)}|{String(isRagPipelinePage)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
describe('GotoAnythingProvider', () => {
|
||||
beforeEach(() => {
|
||||
isWorkflowPageMock = false
|
||||
pathnameMock = '/'
|
||||
})
|
||||
|
||||
test('should set workflow page flag when workflow path detected', async () => {
|
||||
isWorkflowPageMock = true
|
||||
pathnameMock = '/app/123/workflow'
|
||||
|
||||
render(
|
||||
<GotoAnythingProvider>
|
||||
<ContextConsumer />
|
||||
</GotoAnythingProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('status')).toHaveTextContent('true|false')
|
||||
})
|
||||
})
|
||||
|
||||
test('should detect RAG pipeline path based on pathname', async () => {
|
||||
pathnameMock = '/datasets/abc/pipeline'
|
||||
|
||||
render(
|
||||
<GotoAnythingProvider>
|
||||
<ContextConsumer />
|
||||
</GotoAnythingProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('status')).toHaveTextContent('false|true')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user