This is an automated email from the ASF dual-hosted git repository. enzomartellucci pushed a commit to branch enxdev/refactor/antd5/create-wrappers in repository https://gitbox.apache.org/repos/asf/superset.git
commit 09b8f8bc60353624224fa4eca542e79e91c49fee Author: Enzo Martellucci <[email protected]> AuthorDate: Sun Mar 30 01:07:49 2025 +0100 fix RTL tests for Upload and Timer components --- superset-frontend/src/components/Timer/Timer.test.tsx | 11 ++++++++--- .../databases/UploadDataModel/UploadDataModal.test.tsx | 18 ++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/components/Timer/Timer.test.tsx b/superset-frontend/src/components/Timer/Timer.test.tsx index 41f45a70cb..10553472e7 100644 --- a/superset-frontend/src/components/Timer/Timer.test.tsx +++ b/superset-frontend/src/components/Timer/Timer.test.tsx @@ -27,6 +27,11 @@ function parseTime(text?: string | null) { return !!text && Number(text.replace(/:/g, '')); } +// Removes the decimal part (after the dot) +function formatTime(time: string) { + return time.replace(/\.\d+$/, ''); +} + describe('Timer', () => { const mockProps: TimerProps = { startTime: now(), @@ -53,17 +58,17 @@ describe('Timer', () => { screen.rerender(<Timer {...mockProps} isRunning={false} />); // the same node should still be in DOM and the content should not change expect(screen.getByRole('timer')).toBe(node); - expect(node).toHaveTextContent(text); + expect(formatTime(node.textContent || '')).toBe(formatTime(text)); // the timestamp should not change even after while await sleep(100); expect(screen.getByRole('timer')).toBe(node); - expect(node).toHaveTextContent(text); + expect(formatTime(node.textContent || '')).toBe(formatTime(text)); // should continue and start from stopped time screen.rerender(<Timer {...mockProps} isRunning />); expect(screen.getByRole('timer')).toBe(node); - expect(node).toHaveTextContent(text); + expect(formatTime(node.textContent || '')).toBe(formatTime(text)); await waitFor(() => { expect(screen.getByRole('timer')).toBe(node); diff --git a/superset-frontend/src/features/databases/UploadDataModel/UploadDataModal.test.tsx b/superset-frontend/src/features/databases/UploadDataModel/UploadDataModal.test.tsx index e70646bd72..b71fee2b8f 100644 --- a/superset-frontend/src/features/databases/UploadDataModel/UploadDataModal.test.tsx +++ b/superset-frontend/src/features/databases/UploadDataModel/UploadDataModal.test.tsx @@ -25,6 +25,7 @@ import { screen, waitFor, userEvent, + fireEvent, } from 'spec/helpers/testing-library'; import { UploadFile } from 'src/components/Upload'; @@ -625,12 +626,11 @@ test('CSV form post', async () => { userEvent.click(selectButton); // Select a file from the file dialog - const file = new File(['test'], 'test.csv', { type: 'text' }); + const file = new File(['test'], 'test.csv', { type: 'text/csv' }); const inputElement = screen.getByTestId('model-file-input'); - if (inputElement) { - userEvent.upload(inputElement as HTMLElement, file); - } + expect(inputElement).toBeInTheDocument(); + fireEvent.change(inputElement, { target: { files: [file] } }); const selectDatabase = screen.getByRole('combobox', { name: /select a database/i, @@ -686,9 +686,8 @@ test('Excel form post', async () => { const file = new File(['test'], 'test.xls', { type: 'text' }); const inputElement = screen.getByTestId('model-file-input'); - if (inputElement) { - userEvent.upload(inputElement as HTMLElement, file); - } + expect(inputElement).toBeInTheDocument(); + fireEvent.change(inputElement, { target: { files: [file] } }); const selectDatabase = screen.getByRole('combobox', { name: /select a database/i, @@ -744,9 +743,8 @@ test('Columnar form post', async () => { const file = new File(['test'], 'test.parquet', { type: 'text' }); const inputElement = screen.getByTestId('model-file-input'); - if (inputElement) { - userEvent.upload(inputElement as HTMLElement, file); - } + expect(inputElement).toBeInTheDocument(); + fireEvent.change(inputElement, { target: { files: [file] } }); const selectDatabase = screen.getByRole('combobox', { name: /select a database/i,
