chore(ui): Show error message if test definition API fails (#10885)

* chore(ui): Show error message if test definition API fails

* test: add unit test

---------

Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com>
This commit is contained in:
Sachin Chaurasiya 2023-04-05 11:03:19 +05:30 committed by GitHub
parent d5a072d83b
commit 31a5464090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 4 deletions

View File

@ -54,7 +54,9 @@ jest.mock('utils/ServiceUtils', () => ({
jest.mock('./TestConnectionModal/TestConnectionModal', () => jest.mock('./TestConnectionModal/TestConnectionModal', () =>
jest jest
.fn() .fn()
.mockReturnValue(<div data-testid="test-connection-modal">Modal</div>) .mockImplementation(({ isOpen }) =>
isOpen ? <div data-testid="test-connection-modal">Modal</div> : null
)
); );
jest.mock('rest/workflowAPI', () => ({ jest.mock('rest/workflowAPI', () => ({
@ -309,10 +311,36 @@ describe('Test Connection Component', () => {
).toBeInTheDocument(); ).toBeInTheDocument();
}); });
it('Should not show the connection status modal if test connection definition API fails', async () => {
(getTestConnectionDefinitionByName as jest.Mock).mockImplementationOnce(
() => Promise.reject()
);
await act(async () => {
render(<TestConnection {...mockProps} />);
});
const testConnectionButton = screen.getByTestId('test-connection-btn');
await act(async () => {
userEvent.click(testConnectionButton);
});
expect(getTestConnectionDefinitionByName).toHaveBeenCalledWith('Mysql');
expect(
screen.queryByTestId('test-connection-modal')
).not.toBeInTheDocument();
// add workflow API should not get called
expect(addWorkflow).not.toHaveBeenCalled();
});
it('Test connection button should be disabled is airflow is not available', async () => { it('Test connection button should be disabled is airflow is not available', async () => {
(useAirflowStatus as jest.Mock).mockImplementationOnce(() => ({ (useAirflowStatus as jest.Mock).mockImplementationOnce(() => ({
isAirflowAvailable: false, isAirflowAvailable: false,
})); }));
await act(async () => { await act(async () => {
render(<TestConnection {...mockProps} />); render(<TestConnection {...mockProps} />);
}); });

View File

@ -52,6 +52,7 @@ import {
WORKFLOW_COMPLETE_STATUS, WORKFLOW_COMPLETE_STATUS,
} from 'constants/Services.constant'; } from 'constants/Services.constant';
import { useAirflowStatus } from 'hooks/useAirflowStatus'; import { useAirflowStatus } from 'hooks/useAirflowStatus';
import { showErrorToast } from 'utils/ToastUtils';
import './test-connection.style.less'; import './test-connection.style.less';
const TestConnection: FC<TestConnectionProps> = ({ const TestConnection: FC<TestConnectionProps> = ({
@ -128,8 +129,9 @@ const TestConnection: FC<TestConnectionProps> = ({
const response = await getTestConnectionDefinitionByName(connectionType); const response = await getTestConnectionDefinitionByName(connectionType);
setTestConnectionStep(response.steps); setTestConnectionStep(response.steps);
setDialogOpen(true);
} catch (error) { } catch (error) {
// we will not throw error for this API throw t('message.test-connection-cannot-be-triggered');
} }
}; };
@ -188,8 +190,6 @@ const TestConnection: FC<TestConnectionProps> = ({
// fetch the connection steps for current connectionType // fetch the connection steps for current connectionType
await fetchConnectionDefinition(); await fetchConnectionDefinition();
setDialogOpen(true);
// create the workflow // create the workflow
const response = await addWorkflow(createWorkflowData); const response = await addWorkflow(createWorkflowData);
@ -268,6 +268,7 @@ const TestConnection: FC<TestConnectionProps> = ({
setIsTestingConnection(false); setIsTestingConnection(false);
setMessage(failureMessage); setMessage(failureMessage);
setTestStatus(StatusType.Failed); setTestStatus(StatusType.Failed);
showErrorToast(error as AxiosError);
} }
}; };

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "Youve successfully completed the tour.", "successfully-completed-the-tour": "Youve successfully completed the tour.",
"team-moved-success": "Team moved successfully!", "team-moved-success": "Team moved successfully!",
"team-no-asset": "Your team does not have any assets.", "team-no-asset": "Your team does not have any assets.",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "Test your connections before creating the service", "test-your-connection-before-creating-service": "Test your connections before creating the service",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "Youve successfully completed the tour.", "successfully-completed-the-tour": "Youve successfully completed the tour.",
"team-moved-success": "Team moved successfully!", "team-moved-success": "Team moved successfully!",
"team-no-asset": "Your team does not have any assets.", "team-no-asset": "Your team does not have any assets.",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "Test your connections before creating the service", "test-your-connection-before-creating-service": "Test your connections before creating the service",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "Vous avez fini la visite avec succès.", "successfully-completed-the-tour": "Vous avez fini la visite avec succès.",
"team-moved-success": "Team moved successfully!", "team-moved-success": "Team moved successfully!",
"team-no-asset": "Votre equipe n'a pas de resources de données", "team-no-asset": "Votre equipe n'a pas de resources de données",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "Test your connections before creating the service", "test-your-connection-before-creating-service": "Test your connections before creating the service",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "あなたは無事ツアーを終了しました。", "successfully-completed-the-tour": "あなたは無事ツアーを終了しました。",
"team-moved-success": "チームの移動が成功しました!", "team-moved-success": "チームの移動が成功しました!",
"team-no-asset": "あなたのチームはアセットを持っていません。", "team-no-asset": "あなたのチームはアセットを持っていません。",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "サービスを作成する前に接続テストをしてください。", "test-your-connection-before-creating-service": "サービスを作成する前に接続テストをしてください。",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "Você concluiu o tour com sucesso.", "successfully-completed-the-tour": "Você concluiu o tour com sucesso.",
"team-moved-success": "Time movido com sucesso!", "team-moved-success": "Time movido com sucesso!",
"team-no-asset": "Seu time não possui nenhum ativo.", "team-no-asset": "Seu time não possui nenhum ativo.",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "Teste suas conexões antes de criar o serviço", "test-your-connection-before-creating-service": "Teste suas conexões antes de criar o serviço",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",

View File

@ -1172,6 +1172,7 @@
"successfully-completed-the-tour": "Youve successfully completed the tour.", "successfully-completed-the-tour": "Youve successfully completed the tour.",
"team-moved-success": "Team moved successfully", "team-moved-success": "Team moved successfully",
"team-no-asset": "Your team does not have any assets", "team-no-asset": "Your team does not have any assets",
"test-connection-cannot-be-triggered": "Test connection cannot be triggered.",
"test-connection-taking-too-long": "The test connection is taking too long. Please try again.", "test-connection-taking-too-long": "The test connection is taking too long. Please try again.",
"test-your-connection-before-creating-service": "Test your connections before creating the service", "test-your-connection-before-creating-service": "Test your connections before creating the service",
"testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes", "testing-your-connection-may-take-two-minutes": "Testing your connections may take up-to 2 minutes",