@@ -2,8 +2,9 @@ import { describe, it, expect, vi, beforeAll, afterEach, afterAll, beforeEach }
22import { screen , waitFor , fireEvent } from "@testing-library/react" ;
33import { setupServer } from "msw/node" ;
44import { renderWithProviders } from "../../../test/setup.tsx" ;
5- import ConfigurationStep from "../config/ConfigurationStep.tsx" ;
5+ import ConfigurationStep , { getGeneralErrorMsgForSubmission } from "../config/ConfigurationStep.tsx" ;
66import { mockHandlers , type Target , type Mode } from "../../../test/mockHandlers.ts" ;
7+ import { ApiError } from "../../../api/error.ts" ;
78import '@testing-library/jest-dom/vitest' ;
89
910import type { components } from "../../../types/api" ;
@@ -1954,9 +1955,9 @@ describe.each([
19541955 expect ( screen . getByText ( "Required Field is required" ) ) . toBeInTheDocument ( ) ;
19551956 } ) ;
19561957
1957- // Verify the raw server error message at the bottom
1958+ // Verify error component at the bottom exists
19581959 await waitFor ( ( ) => {
1959- expect ( screen . getByText ( "required fields not completed ") ) . toBeInTheDocument ( ) ;
1960+ expect ( screen . getByTestId ( "config-submit-error ") ) . toBeInTheDocument ( ) ;
19601961 } ) ;
19611962
19621963 // Verify onNext was not called due to validation error
@@ -2788,4 +2789,42 @@ describe.each([
27882789 expect ( submittedValues ! . values . db_type ) . toEqual ( { value : 'mysql' } ) ;
27892790 } ) ;
27902791 } ) ;
2792+
2793+ describe ( "getGeneralErrorMsgForSubmission" , ( ) => {
2794+ it ( "returns generic error message when error has field errors" , ( ) => {
2795+ const error = new ApiError ( 400 , "Validation error" ) ;
2796+ error . fieldErrors = [
2797+ { field : "app_name" , message : "This field is required" } ,
2798+ ] ;
2799+
2800+ const result = getGeneralErrorMsgForSubmission ( error ) ;
2801+
2802+ expect ( result ) . toContain ( "Please address the issues above" ) ;
2803+ } ) ;
2804+
2805+ it ( "returns error.details when no field errors but details exist" , ( ) => {
2806+ const error = new ApiError ( 500 , "Generic message" ) ;
2807+ error . details = "Detailed error message" ;
2808+
2809+ const result = getGeneralErrorMsgForSubmission ( error ) ;
2810+
2811+ expect ( result ) . toBe ( "Detailed error message" ) ;
2812+ } ) ;
2813+
2814+ it ( "returns error.message when no field errors or details" , ( ) => {
2815+ const error = new ApiError ( 500 , "Generic error message" ) ;
2816+
2817+ const result = getGeneralErrorMsgForSubmission ( error ) ;
2818+
2819+ expect ( result ) . toBe ( "Generic error message" ) ;
2820+ } ) ;
2821+
2822+ it ( "returns fallback message when error has no field errors, details, or message" , ( ) => {
2823+ const error = new ApiError ( 500 , "" ) ;
2824+
2825+ const result = getGeneralErrorMsgForSubmission ( error ) ;
2826+
2827+ expect ( result ) . toBe ( "Failed to save configuration" ) ;
2828+ } ) ;
2829+ } ) ;
27912830} ) ;
0 commit comments