@@ -5,6 +5,7 @@ import { setupServer } from "msw/node";
55import { renderWithProviders } from "../../../test/setup.tsx" ;
66import ConfigurationStep from "../config/ConfigurationStep.tsx" ;
77import { AppConfig , AppConfigGroup , AppConfigItem , AppConfigValues } from "../../../types" ;
8+ import '@testing-library/jest-dom/vitest' ;
89
910// Mock the debounced fetch to remove timing issues in tests
1011vi . mock ( "../../../utils/debouncedFetch" , ( ) => ( {
@@ -1771,12 +1772,13 @@ describe.each([
17711772 // Mock FileReader for new file upload
17721773 const mockFileReader = {
17731774 readAsDataURL : vi . fn ( ) . mockImplementation ( ( ) => {
1775+ // Use setTimeout with a small delay to simulate async file reading
17741776 setTimeout ( ( ) => {
17751777 if ( mockFileReader . onload ) {
17761778 // eslint-disable-next-line @typescript-eslint/no-explicit-any
17771779 mockFileReader . onload ( { target : { result : 'data:text/plain;base64,bmV3IGNvbnRlbnQ=' } } as any ) ;
17781780 }
1779- } , 0 ) ;
1781+ } , 10 ) ;
17801782 } ) ,
17811783 result : 'data:text/plain;base64,bmV3IGNvbnRlbnQ=' ,
17821784 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1791,11 +1793,14 @@ describe.each([
17911793 // Upload new file
17921794 fireEvent . change ( configFileInput , { target : { files : [ newFile ] } } ) ;
17931795
1794- // Wait for the new filename to appear
1796+ // Wait for the new filename to appear and file processing to complete
17951797 await waitFor ( ( ) => {
17961798 expect ( screen . getByText ( "new-config.yml" ) ) . toBeInTheDocument ( ) ;
17971799 } ) ;
17981800
1801+ // Wait a bit more to ensure the file processing is fully complete
1802+ await new Promise ( resolve => setTimeout ( resolve , 20 ) ) ;
1803+
17991804 // Verify the old filename is no longer displayed
18001805 expect ( screen . queryByText ( "config.yaml" ) ) . not . toBeInTheDocument ( ) ;
18011806
@@ -1883,12 +1888,13 @@ describe.each([
18831888 // Mock FileReader
18841889 const mockFileReader = {
18851890 readAsDataURL : vi . fn ( ) . mockImplementation ( ( ) => {
1891+ // Use setTimeout with a small delay to simulate async file reading
18861892 setTimeout ( ( ) => {
18871893 if ( mockFileReader . onload ) {
18881894 // eslint-disable-next-line @typescript-eslint/no-explicit-any
18891895 mockFileReader . onload ( { target : { result : 'data:text/plain;base64,Y29udGVudA==' } } as any ) ;
18901896 }
1891- } , 0 ) ;
1897+ } , 10 ) ;
18921898 } ) ,
18931899 result : 'data:text/plain;base64,Y29udGVudA==' ,
18941900 // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1903,11 +1909,14 @@ describe.each([
19031909 // Upload file
19041910 fireEvent . change ( fileInput , { target : { files : [ newFile ] } } ) ;
19051911
1906- // Wait for the filename to appear
1912+ // Wait for the filename to appear and file processing to complete
19071913 await waitFor ( ( ) => {
19081914 expect ( screen . getByTestId ( "file-input-no_filename_file-filename" ) ) . toBeInTheDocument ( ) ;
19091915 } ) ;
19101916
1917+ // Wait a bit more to ensure the file processing is fully complete
1918+ await new Promise ( resolve => setTimeout ( resolve , 20 ) ) ;
1919+
19111920 expect ( screen . getByText ( "uploaded-file.txt" ) ) . toBeInTheDocument ( ) ;
19121921 } ) ;
19131922 } ) ;
0 commit comments