refactor: Upgrade to React 17 (#31961)

This commit is contained in:
Kamil Gabryjelski
2025-01-28 16:44:42 +01:00
committed by GitHub
parent aa74ba3da2
commit 7e2b7941f3
101 changed files with 18988 additions and 61350 deletions

View File

@@ -25,36 +25,6 @@ import userEvent from '@testing-library/user-event';
import { waitFor } from '@testing-library/react';
import { UploadFile } from 'antd/lib/upload/interface';
fetchMock.post('glob:*api/v1/database/1/upload/', {});
fetchMock.get(
'glob:*api/v1/database/?q=(filters:!((col:allow_file_upload,opr:eq,value:!t)),page:0,page_size:100)',
{
result: [
{
id: 1,
database_name: 'database1',
},
{
id: 2,
database_name: 'database2',
},
],
},
);
fetchMock.get('glob:*api/v1/database/*/catalogs/', {
result: [],
});
fetchMock.get('glob:*api/v1/database/1/schemas/', {
result: ['information_schema', 'public'],
});
fetchMock.get('glob:*api/v1/database/2/schemas/', {
result: ['schema1', 'schema2'],
});
const csvProps = {
show: true,
onHide: () => {},
@@ -76,6 +46,48 @@ const columnarProps = {
type: 'columnar',
};
beforeEach(() => {
fetchMock.post('glob:*api/v1/database/1/upload/', {});
// 4 mocks below are not necessary
fetchMock.post('glob:*api/v1/database/csv_metadata/', {});
fetchMock.post('glob:*api/v1/database/excel_metadata/', {});
fetchMock.post('glob:*api/v1/database/columnar_metadata/', {});
fetchMock.post('glob:*api/v1/database/upload_metadata/', {});
fetchMock.get(
'glob:*api/v1/database/?q=(filters:!((col:allow_file_upload,opr:eq,value:!t)),page:0,page_size:100)',
{
result: [
{
id: 1,
database_name: 'database1',
},
{
id: 2,
database_name: 'database2',
},
],
},
);
fetchMock.get('glob:*api/v1/database/*/catalogs/', {
result: [],
});
fetchMock.get('glob:*api/v1/database/1/schemas/', {
result: ['information_schema', 'public'],
});
fetchMock.get('glob:*api/v1/database/2/schemas/', {
result: ['schema1', 'schema2'],
});
});
afterEach(() => {
fetchMock.restore();
});
test('CSV, renders the general information elements correctly', () => {
render(<UploadDataModal {...csvProps} />, {
useRedux: true,
@@ -598,7 +610,7 @@ test('form without required fields', async () => {
await waitFor(() => screen.getByText('Table name is required'));
});
test('CSV, form post', async () => {
test('CSV form post', async () => {
render(<UploadDataModal {...csvProps} />, {
useRedux: true,
});
@@ -620,15 +632,15 @@ test('CSV, form post', async () => {
name: /select a database/i,
});
userEvent.click(selectDatabase);
await waitFor(() => screen.getByText('database1'));
await waitFor(() => screen.getByText('database2'));
await screen.findByText('database1');
await screen.findByText('database2');
screen.getByText('database1').click();
const selectSchema = screen.getByRole('combobox', {
name: /schema/i,
});
userEvent.click(selectSchema);
await waitFor(() => screen.getAllByText('public'));
await screen.findAllByText('public');
screen.getAllByText('public')[1].click();
// Fill out form fields
@@ -646,7 +658,7 @@ test('CSV, form post', async () => {
// Get the matching fetch calls made
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
expect(matchingCalls).toHaveLength(1);
const [_, options] = matchingCalls[0];
const [, options] = matchingCalls[0];
const formData = options?.body as FormData;
expect(formData.get('type')).toBe('csv');
expect(formData.get('table_name')).toBe('table1');
@@ -654,11 +666,9 @@ test('CSV, form post', async () => {
expect(formData.get('table_name')).toBe('table1');
const fileData = formData.get('file') as File;
expect(fileData.name).toBe('test.csv');
// Avoid leaking fetchMock calls
fetchMock.resetHistory();
});
}, 10000); // longer timeout to decrease flakiness
test('Excel, form post', async () => {
test('Excel form post', async () => {
render(<UploadDataModal {...excelProps} />, {
useRedux: true,
});
@@ -680,15 +690,15 @@ test('Excel, form post', async () => {
name: /select a database/i,
});
userEvent.click(selectDatabase);
await waitFor(() => screen.getByText('database1'));
await waitFor(() => screen.getByText('database2'));
await screen.findByText('database1');
await screen.findByText('database2');
screen.getByText('database1').click();
const selectSchema = screen.getByRole('combobox', {
name: /schema/i,
});
userEvent.click(selectSchema);
await waitFor(() => screen.getAllByText('public'));
await screen.findAllByText('public');
screen.getAllByText('public')[1].click();
// Fill out form fields
@@ -706,7 +716,7 @@ test('Excel, form post', async () => {
// Get the matching fetch calls made
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
expect(matchingCalls).toHaveLength(1);
const [_, options] = matchingCalls[0];
const [, options] = matchingCalls[0];
const formData = options?.body as FormData;
expect(formData.get('type')).toBe('excel');
expect(formData.get('table_name')).toBe('table1');
@@ -714,11 +724,9 @@ test('Excel, form post', async () => {
expect(formData.get('table_name')).toBe('table1');
const fileData = formData.get('file') as File;
expect(fileData.name).toBe('test.xls');
// Avoid leaking fetchMock calls
fetchMock.resetHistory();
});
}, 10000); // longer timeout to decrease flakiness
test('Columnar, form post', async () => {
test('Columnar form post', async () => {
render(<UploadDataModal {...columnarProps} />, {
useRedux: true,
});
@@ -740,15 +748,15 @@ test('Columnar, form post', async () => {
name: /select a database/i,
});
userEvent.click(selectDatabase);
await waitFor(() => screen.getByText('database1'));
await waitFor(() => screen.getByText('database2'));
await screen.findByText('database1');
await screen.findByText('database2');
screen.getByText('database1').click();
const selectSchema = screen.getByRole('combobox', {
name: /schema/i,
});
userEvent.click(selectSchema);
await waitFor(() => screen.getAllByText('public'));
await screen.findAllByText('public');
screen.getAllByText('public')[1].click();
// Fill out form fields
@@ -766,7 +774,7 @@ test('Columnar, form post', async () => {
// Get the matching fetch calls made
const matchingCalls = fetchMock.calls('glob:*api/v1/database/1/upload/');
expect(matchingCalls).toHaveLength(1);
const [_, options] = matchingCalls[0];
const [, options] = matchingCalls[0];
const formData = options?.body as FormData;
expect(formData.get('type')).toBe('columnar');
expect(formData.get('table_name')).toBe('table1');
@@ -774,9 +782,7 @@ test('Columnar, form post', async () => {
expect(formData.get('table_name')).toBe('table1');
const fileData = formData.get('file') as File;
expect(fileData.name).toBe('test.parquet');
// Avoid leaking fetchMock calls
fetchMock.resetHistory();
});
}, 10000); // longer timeout to decrease flakiness
test('CSV, validate file extension returns false', () => {
const invalidFileNames = ['out', 'out.exe', 'out.csv.exe', '.csv', 'out.xls'];