mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-25 17:37:57 +00:00
Minor: added loading state, and error notification in testSuite. (#19350)
* Minor: added loading state, and error notification in testSuite. * added the unit test
This commit is contained in:
parent
7bea4f957f
commit
05f68ec776
@ -186,11 +186,14 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
const ingestion = await addIngestionPipeline(ingestionPayload);
|
const ingestion = await addIngestionPipeline(ingestionPayload);
|
||||||
|
|
||||||
setIngestionData(ingestion);
|
setIngestionData(ingestion);
|
||||||
handleIngestionDeploy(ingestion.id);
|
handleIngestionDeploy(ingestion.id);
|
||||||
|
} catch (error) {
|
||||||
|
showErrorToast(error as AxiosError);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUpdateIngestionPipeline = async (
|
const onUpdateIngestionPipeline = async (
|
||||||
|
@ -10,7 +10,14 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import {
|
||||||
|
act,
|
||||||
|
fireEvent,
|
||||||
|
queryByAttribute,
|
||||||
|
render,
|
||||||
|
screen,
|
||||||
|
waitFor,
|
||||||
|
} from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { EntityReference } from '../../../generated/tests/testCase';
|
import { EntityReference } from '../../../generated/tests/testCase';
|
||||||
import { AddTestCaseList } from './AddTestCaseList.component';
|
import { AddTestCaseList } from './AddTestCaseList.component';
|
||||||
@ -102,11 +109,20 @@ describe('AddTestCaseList', () => {
|
|||||||
await act(async () => {
|
await act(async () => {
|
||||||
render(<AddTestCaseList {...mockProps} />);
|
render(<AddTestCaseList {...mockProps} />);
|
||||||
});
|
});
|
||||||
|
const submitBtn = screen.getByTestId('submit');
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
await fireEvent.click(screen.getByTestId('submit'));
|
fireEvent.click(submitBtn);
|
||||||
|
await waitFor(() => {
|
||||||
|
const loader = queryByAttribute('aria-label', submitBtn, 'loading');
|
||||||
|
|
||||||
|
expect(loader).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockProps.onSubmit).toHaveBeenCalledWith([]);
|
expect(mockProps.onSubmit).toHaveBeenCalledWith([]);
|
||||||
|
expect(
|
||||||
|
queryByAttribute('aria-label', submitBtn, 'loading')
|
||||||
|
).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not render submit and cancel buttons when showButton is false', async () => {
|
it('does not render submit and cancel buttons when showButton is false', async () => {
|
||||||
|
@ -110,7 +110,7 @@ export const AddTestCaseList = ({
|
|||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const testCaseIds = [...(selectedItems?.values() ?? [])];
|
const testCaseIds = [...(selectedItems?.values() ?? [])];
|
||||||
onSubmit?.(testCaseIds);
|
await onSubmit?.(testCaseIds);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import { ListTestCaseParamsBySearch } from '../../../rest/testAPI';
|
|||||||
|
|
||||||
export interface AddTestCaseModalProps {
|
export interface AddTestCaseModalProps {
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
onSubmit?: (testCases: TestCase[]) => void;
|
onSubmit?: (testCases: TestCase[]) => void | Promise<void>;
|
||||||
onChange?: (testCases: TestCase[]) => void;
|
onChange?: (testCases: TestCase[]) => void;
|
||||||
existingTest?: EntityReference[];
|
existingTest?: EntityReference[];
|
||||||
cancelText?: string;
|
cancelText?: string;
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
fireEvent,
|
fireEvent,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
|
waitFor,
|
||||||
} from '@testing-library/react';
|
} from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MOCK_TEST_CASE } from '../../../../mocks/TestSuite.mock';
|
import { MOCK_TEST_CASE } from '../../../../mocks/TestSuite.mock';
|
||||||
@ -68,7 +69,7 @@ jest.mock('../../../common/DeleteWidget/DeleteWidgetModal', () => {
|
|||||||
return (
|
return (
|
||||||
visible && (
|
visible && (
|
||||||
<div>
|
<div>
|
||||||
DeleteWidgetModal
|
<p>DeleteWidgetModal</p>
|
||||||
<button onClick={onCancel}>cancel</button>
|
<button onClick={onCancel}>cancel</button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@ -80,7 +81,7 @@ jest.mock('../../../DataQuality/AddDataQualityTest/EditTestCaseModal', () => {
|
|||||||
return (
|
return (
|
||||||
visible && (
|
visible && (
|
||||||
<div>
|
<div>
|
||||||
EditTestCaseModal
|
<p>EditTestCaseModal</p>
|
||||||
<button onClick={onCancel}>cancel</button>
|
<button onClick={onCancel}>cancel</button>
|
||||||
<button onClick={onUpdate}>submit</button>
|
<button onClick={onUpdate}>submit</button>
|
||||||
</div>
|
</div>
|
||||||
@ -88,6 +89,28 @@ jest.mock('../../../DataQuality/AddDataQualityTest/EditTestCaseModal', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
jest.mock('../../../Modals/ConfirmationModal/ConfirmationModal', () => {
|
||||||
|
return jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(({ visible, onCancel, onConfirm, isLoading }) => {
|
||||||
|
return (
|
||||||
|
visible && (
|
||||||
|
<div>
|
||||||
|
<p>ConfirmationModal</p>
|
||||||
|
<button onClick={onCancel}>cancel</button>
|
||||||
|
<button onClick={onConfirm}>
|
||||||
|
{isLoading ? (
|
||||||
|
<span data-testid="submit-btn-loading">Loading</span>
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)}
|
||||||
|
submit
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('DataQualityTab test', () => {
|
describe('DataQualityTab test', () => {
|
||||||
it('Component should render', async () => {
|
it('Component should render', async () => {
|
||||||
@ -216,6 +239,53 @@ describe('DataQualityTab test', () => {
|
|||||||
expect(deleteButton).toBeInTheDocument();
|
expect(deleteButton).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Remove functionality', async () => {
|
||||||
|
const firstRowData = MOCK_TEST_CASE[0];
|
||||||
|
await act(async () => {
|
||||||
|
render(
|
||||||
|
<DataQualityTab
|
||||||
|
removeFromTestSuite={{
|
||||||
|
testSuite: {
|
||||||
|
id: 'testSuiteId',
|
||||||
|
name: 'testSuiteName',
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
{...mockProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const tableRows = await screen.findAllByRole('row');
|
||||||
|
const firstRow = tableRows[1];
|
||||||
|
const closeRemoveModel = screen.queryByText('ConfirmationModal');
|
||||||
|
const removeButton = await findByTestId(
|
||||||
|
firstRow,
|
||||||
|
`remove-${firstRowData.name}`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(removeButton).toBeInTheDocument();
|
||||||
|
expect(closeRemoveModel).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(removeButton);
|
||||||
|
});
|
||||||
|
const openRemoveModel = await screen.findByText('ConfirmationModal');
|
||||||
|
const submitBtn = await screen.findByText('submit');
|
||||||
|
|
||||||
|
expect(openRemoveModel).toBeInTheDocument();
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.click(submitBtn);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
const loader = screen.getByTestId('submit-btn-loading');
|
||||||
|
|
||||||
|
expect(loader).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(closeRemoveModel).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it('Edit functionality', async () => {
|
it('Edit functionality', async () => {
|
||||||
const firstRowData = MOCK_TEST_CASE[0];
|
const firstRowData = MOCK_TEST_CASE[0];
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -88,6 +88,8 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
|
|||||||
const [testCaseStatus, setTestCaseStatus] = useState<
|
const [testCaseStatus, setTestCaseStatus] = useState<
|
||||||
TestCaseResolutionStatus[]
|
TestCaseResolutionStatus[]
|
||||||
>([]);
|
>([]);
|
||||||
|
const [isTestCaseRemovalLoading, setIsTestCaseRemovalLoading] =
|
||||||
|
useState(false);
|
||||||
const isApiSortingEnabled = useRef(false);
|
const isApiSortingEnabled = useRef(false);
|
||||||
|
|
||||||
const testCaseEditPermission = useMemo(() => {
|
const testCaseEditPermission = useMemo(() => {
|
||||||
@ -131,6 +133,7 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmClick = async () => {
|
const handleConfirmClick = async () => {
|
||||||
|
setIsTestCaseRemovalLoading(true);
|
||||||
if (isUndefined(removeFromTestSuite)) {
|
if (isUndefined(removeFromTestSuite)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,6 +146,8 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
|
|||||||
setSelectedTestCase(undefined);
|
setSelectedTestCase(undefined);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showErrorToast(error as AxiosError);
|
showErrorToast(error as AxiosError);
|
||||||
|
} finally {
|
||||||
|
setIsTestCaseRemovalLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -514,6 +519,7 @@ const DataQualityTab: React.FC<DataQualityTabProps> = ({
|
|||||||
cancelText={t('label.cancel')}
|
cancelText={t('label.cancel')}
|
||||||
confirmText={t('label.remove')}
|
confirmText={t('label.remove')}
|
||||||
header={t('label.remove-entity', { entity: t('label.test-case') })}
|
header={t('label.remove-entity', { entity: t('label.test-case') })}
|
||||||
|
isLoading={isTestCaseRemovalLoading}
|
||||||
visible={selectedTestCase?.action === 'DELETE'}
|
visible={selectedTestCase?.action === 'DELETE'}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
onConfirm={handleConfirmClick}
|
onConfirm={handleConfirmClick}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user