fix(web): pipeline batch test template

This commit is contained in:
JzoNg 2026-04-29 20:36:07 +08:00
parent ad58895b25
commit 24b482893d
3 changed files with 34 additions and 3 deletions

View File

@ -622,6 +622,33 @@ describe('Evaluation', () => {
expect(screen.getByRole('button', { name: 'evaluation.pipeline.uploadAndRun' })).toBeEnabled()
})
it('should download the fixed pipeline template columns', () => {
const createElement = document.createElement.bind(document)
let downloadLink: HTMLAnchorElement | undefined
const createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tagName, options) => {
const element = createElement(tagName, options)
if (tagName === 'a') {
downloadLink = element as HTMLAnchorElement
vi.spyOn(downloadLink, 'click').mockImplementation(() => {})
}
return element
})
renderWithQueryClient(<Evaluation resourceType="datasets" resourceId="dataset-template" />)
fireEvent.click(screen.getByRole('button', { name: 'select-model' }))
fireEvent.click(screen.getByRole('button', { name: /Context Precision/i }))
fireEvent.click(screen.getByRole('button', { name: 'evaluation.batch.downloadTemplate' }))
expect(downloadLink?.download).toBe('pipeline-evaluation-template.csv')
expect(decodeURIComponent(downloadLink?.href ?? '')).toContain('query,expect_results\n')
expect(decodeURIComponent(downloadLink?.href ?? '')).not.toContain('expected_output')
createElementSpy.mockRestore()
})
it('should upload and start a pipeline evaluation run', async () => {
const startRun = vi.fn()
mockUseStartEvaluationRunMutation.mockReturnValue({
@ -640,14 +667,14 @@ describe('Evaluation', () => {
fireEvent.click(screen.getByRole('button', { name: 'evaluation.pipeline.uploadAndRun' }))
expect(screen.getAllByText('query').length).toBeGreaterThan(0)
expect(screen.getAllByText('Expect Results').length).toBeGreaterThan(0)
expect(screen.getAllByText('expect_results').length).toBeGreaterThan(0)
const fileInput = document.querySelector<HTMLInputElement>('input[type="file"][accept=".csv"]')
expect(fileInput).toBeInTheDocument()
fireEvent.change(fileInput!, {
target: {
files: [new File(['query,Expect Results'], 'pipeline-evaluation.csv', { type: 'text/csv' })],
files: [new File(['query,expect_results'], 'pipeline-evaluation.csv', { type: 'text/csv' })],
},
})

View File

@ -21,6 +21,7 @@ type UseInputFieldsActionsParams = EvaluationResourceProps & {
isInputFieldsLoading: boolean
isPanelReady: boolean
isRunnable: boolean
templateContent?: string
templateFileName: string
}
@ -31,6 +32,7 @@ export const useInputFieldsActions = ({
isInputFieldsLoading,
isPanelReady,
isRunnable,
templateContent,
templateFileName,
}: UseInputFieldsActionsParams) => {
const { t } = useTranslation('evaluation')
@ -79,7 +81,7 @@ export const useInputFieldsActions = ({
return
}
const content = buildTemplateCsvContent(inputFields)
const content = templateContent ?? buildTemplateCsvContent(inputFields)
const link = document.createElement('a')
link.href = `data:text/csv;charset=utf-8,${encodeURIComponent(content)}`
link.download = templateFileName

View File

@ -13,6 +13,7 @@ const PIPELINE_INPUT_FIELDS: InputField[] = [
{ name: 'query', type: 'string' },
{ name: 'expect_results', type: 'string' },
]
const PIPELINE_TEMPLATE_CONTENT = 'query,expect_results\n'
const PipelineBatchActions = ({
resourceType,
@ -29,6 +30,7 @@ const PipelineBatchActions = ({
isInputFieldsLoading: false,
isPanelReady: isConfigReady,
isRunnable,
templateContent: PIPELINE_TEMPLATE_CONTENT,
templateFileName: EVALUATION_TEMPLATE_FILE_NAMES[resourceType],
})