Enhance test definition creation and editing with description support

• Add description to test definition interface
• Include description in create/update params
• Update UI to handle description field
• Refactor types for better consistency
• Add data-test-id for E2E testing
This commit is contained in:
Oleg Ivaniv 2024-11-13 16:05:01 +01:00
parent cdd3d84484
commit 9b5be7a691
No known key found for this signature in database
4 changed files with 21 additions and 22 deletions

View file

@ -10,20 +10,17 @@ export interface ITestDefinitionBase {
annotationTagId?: string; annotationTagId?: string;
} }
// Complete test definition with ID
export interface ITestDefinition extends ITestDefinitionBase { export interface ITestDefinition extends ITestDefinitionBase {
id: number; id: number;
} }
// Create params - requires name and workflowId, optional evaluationWorkflowId export type CreateTestDefinitionParams = Pick<
export type CreateTestDefinitionParams = Pick<ITestDefinitionBase, 'name' | 'workflowId'> & ITestDefinitionBase,
Partial<Pick<ITestDefinitionBase, 'evaluationWorkflowId'>>; 'name' | 'workflowId' | 'description' | 'evaluationWorkflowId'
// All fields optional except ID
export type UpdateTestDefinitionParams = Partial<
Pick<ITestDefinitionBase, 'name' | 'evaluationWorkflowId' | 'annotationTagId'>
>; >;
export type UpdateTestDefinitionParams = Partial<ITestDefinitionBase>;
// Query options type // Query options type
export interface ITestDefinitionsQueryOptions { export interface ITestDefinitionsQueryOptions {
includeScopes?: boolean; includeScopes?: boolean;
@ -58,18 +55,15 @@ export function createTestDefinitionsApi(): ITestDefinitionsApi {
getTestDefinitions: async ( getTestDefinitions: async (
context: IRestApiContext, context: IRestApiContext,
options?: ITestDefinitionsQueryOptions, options?: ITestDefinitionsQueryOptions,
): Promise<ITestDefinition[]> => { ) => {
return await makeRestApiRequest(context, 'GET', endpoint, options); return await makeRestApiRequest(context, 'GET', endpoint, options);
}, },
getTestDefinition: async (context: IRestApiContext, id: number): Promise<ITestDefinition> => { getTestDefinition: async (context: IRestApiContext, id: number) => {
return await makeRestApiRequest(context, 'GET', `${endpoint}/${id}`); return await makeRestApiRequest(context, 'GET', `${endpoint}/${id}`);
}, },
createTestDefinition: async ( createTestDefinition: async (context: IRestApiContext, params: CreateTestDefinitionParams) => {
context: IRestApiContext,
params: CreateTestDefinitionParams,
): Promise<ITestDefinition> => {
return await makeRestApiRequest(context, 'POST', endpoint, params); return await makeRestApiRequest(context, 'POST', endpoint, params);
}, },
@ -77,14 +71,11 @@ export function createTestDefinitionsApi(): ITestDefinitionsApi {
context: IRestApiContext, context: IRestApiContext,
id: number, id: number,
params: UpdateTestDefinitionParams, params: UpdateTestDefinitionParams,
): Promise<ITestDefinition> => { ) => {
return await makeRestApiRequest(context, 'PATCH', `${endpoint}/${id}`, params); return await makeRestApiRequest(context, 'PATCH', `${endpoint}/${id}`, params);
}, },
deleteTestDefinition: async ( deleteTestDefinition: async (context: IRestApiContext, id: number) => {
context: IRestApiContext,
id: number,
): Promise<{ success: boolean }> => {
return await makeRestApiRequest(context, 'DELETE', `${endpoint}/${id}`); return await makeRestApiRequest(context, 'DELETE', `${endpoint}/${id}`);
}, },
}; };

View file

@ -42,13 +42,18 @@ function updateTags(tags: string[]) {
</script> </script>
<template> <template>
<div :class="$style.formGroup"> <div :class="$style.formGroup" data-test-id="workflow-tags-field">
<n8n-input-label label="Tag name" :bold="false" size="small"> <n8n-input-label label="Tag name" :bold="false" size="small">
<div v-if="!modelValue.isEditing" :class="$style.tagsRead" @click="startEditing('tags')"> <div v-if="!modelValue.isEditing" :class="$style.tagsRead" @click="startEditing('tags')">
<n8n-text v-if="modelValue.appliedTagIds.length === 0" size="small"> <n8n-text v-if="modelValue.appliedTagIds.length === 0" size="small">
{{ locale.baseText('workflowEvaluation.edit.selectTag') }} {{ locale.baseText('workflowEvaluation.edit.selectTag') }}
</n8n-text> </n8n-text>
<n8n-tag v-for="tagId in modelValue.appliedTagIds" :key="tagId" :text="getTagName(tagId)" /> <n8n-tag
v-for="tagId in modelValue.appliedTagIds"
:key="tagId"
:text="getTagName(tagId)"
data-test-id="evaluation-tag-field"
/>
<n8n-icon-button <n8n-icon-button
:class="$style.editInputButton" :class="$style.editInputButton"
icon="pen" icon="pen"

View file

@ -69,7 +69,7 @@ export function useEvaluationForm() {
if (testDefinition) { if (testDefinition) {
state.value = { state.value = {
description: '', description: testDefinition.description ?? '',
name: { name: {
value: testDefinition.name, value: testDefinition.name,
isEditing: false, isEditing: false,
@ -113,6 +113,7 @@ export function useEvaluationForm() {
// Prepare the base parameters for creating or updating a test // Prepare the base parameters for creating or updating a test
const params: Record<string, string> = { const params: Record<string, string> = {
name: state.value.name.value, name: state.value.name.value,
description: state.value.description,
}; };
// Add annotation tag ID only for PATH requests // Add annotation tag ID only for PATH requests

View file

@ -95,6 +95,7 @@ export const useEvaluationsStore = defineStore(
name: string; name: string;
workflowId: string; workflowId: string;
evaluationWorkflowId?: string; evaluationWorkflowId?: string;
description?: string;
}) => { }) => {
const createdDefinition = await testDefinitionsApi.createTestDefinition( const createdDefinition = await testDefinitionsApi.createTestDefinition(
rootStore.restApiContext, rootStore.restApiContext,
@ -107,6 +108,7 @@ export const useEvaluationsStore = defineStore(
const update = async (params: { const update = async (params: {
id: number; id: number;
name?: string; name?: string;
description?: string;
evaluationWorkflowId?: string; evaluationWorkflowId?: string;
annotationTagId?: string; annotationTagId?: string;
}) => { }) => {