fix(ui):test connection should be disabled is airflow is not present (#10862)

This commit is contained in:
Sachin Chaurasiya 2023-04-04 19:02:46 +05:30 committed by GitHub
parent 608bf51b6a
commit 73947ab207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import {
StatusType,
WorkflowStatus,
} from 'generated/api/automations/createWorkflow';
import { useAirflowStatus } from 'hooks/useAirflowStatus';
import { ConfigData } from 'interface/service.interface';
import React from 'react';
import {
@ -72,6 +73,12 @@ jest.mock('rest/workflowAPI', () => ({
.mockImplementation(() => Promise.resolve(WORKFLOW_DETAILS)),
}));
jest.mock('hooks/useAirflowStatus', () => ({
useAirflowStatus: jest
.fn()
.mockImplementation(() => ({ isAirflowAvailable: true })),
}));
describe('Test Connection Component', () => {
it('Should render the child component', async () => {
await act(async () => {
@ -301,4 +308,30 @@ describe('Test Connection Component', () => {
screen.getByText('message.test-connection-taking-too-long')
).toBeInTheDocument();
});
it('Test connection button should be disabled is airflow is not available', async () => {
(useAirflowStatus as jest.Mock).mockImplementationOnce(() => ({
isAirflowAvailable: false,
}));
await act(async () => {
render(<TestConnection {...mockProps} />);
});
const testConnectionButton = screen.getByTestId('test-connection-btn');
expect(testConnectionButton).toBeDisabled();
});
it('Test connection button with showDetails false should be disabled is airflow is not available', async () => {
(useAirflowStatus as jest.Mock).mockImplementationOnce(() => ({
isAirflowAvailable: false,
}));
await act(async () => {
render(<TestConnection {...mockProps} showDetails={false} />);
});
const testConnectionButton = screen.getByTestId('test-connection-button');
expect(testConnectionButton).toBeDisabled();
});
});

View File

@ -51,6 +51,7 @@ import {
FETCH_INTERVAL,
WORKFLOW_COMPLETE_STATUS,
} from 'constants/Services.constant';
import { useAirflowStatus } from 'hooks/useAirflowStatus';
import './test-connection.style.less';
const TestConnection: FC<TestConnectionProps> = ({
@ -62,6 +63,7 @@ const TestConnection: FC<TestConnectionProps> = ({
showDetails = true,
}) => {
const { t } = useTranslation();
const { isAirflowAvailable } = useAirflowStatus();
const initialMessage = t(
'message.test-your-connection-before-creating-service'
@ -114,7 +116,10 @@ const TestConnection: FC<TestConnectionProps> = ({
}, [connectionType]);
const isTestConnectionDisabled =
isTestingConnection || isTestingDisabled || !allowTestConn;
isTestingConnection ||
isTestingDisabled ||
!allowTestConn ||
!isAirflowAvailable;
// data fetch handlers