Skip to content

Commit

Permalink
feat: updated multi pipeline ui as per new mock (#17106)
Browse files Browse the repository at this point in the history
* feat: updated multi pipeline ui as per new mock

* translation sync

* fixed failing unit test

* fixed playwright test

* fixed viewService click issue

* sorted pipeline based on test case length
  • Loading branch information
ShaileshParmar11 committed Jul 22, 2024
1 parent 00278ce commit 8d9ff41
Show file tree
Hide file tree
Showing 26 changed files with 615 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ test('TestSuite multi pipeline support', async ({ page }) => {
await page.getByRole('tab', { name: 'Pipeline' }).click();
await page.getByTestId('add-pipeline-button').click();

await page.fill('#name', pipelineName);
await page.fill('[data-testid="pipeline-name"]', pipelineName);
await page.getByTestId('select-test-case').click();
await page.getByTestId(testCaseName).click();

await expect(page.getByTestId('submit')).toBeVisible();

await page.getByTestId('submit').click();
await page.getByTestId('cron-type').locator('div').click();
await page.getByTitle('Week').click();

Expand Down Expand Up @@ -103,7 +101,6 @@ test('TestSuite multi pipeline support', async ({ page }) => {

await expect(page.getByRole('checkbox').first()).toBeVisible();

await page.getByTestId('submit').click();
await page
.getByTestId('week-segment-day-option-container')
.getByText('W')
Expand Down Expand Up @@ -135,7 +132,7 @@ test('TestSuite multi pipeline support', async ({ page }) => {
await page.getByTestId('confirm-button').click();
await deleteRes;

await page.getByTestId('delete').click();
await page.getByRole('button', { name: 'Delete' }).click();
await page.getByTestId('confirmation-text-input').fill('DELETE');
await page.getByTestId('confirm-button').click();
await deleteRes;
Expand Down Expand Up @@ -192,7 +189,6 @@ test("Edit the pipeline's test case", async ({ page }) => {
page.getByTestId(`checkbox-${testCaseNames[0]}`)
).not.toBeChecked();

await page.getByTestId('submit').click();
await page.getByTestId('deploy-button').click();
await page.waitForSelector('[data-testid="body-text"]', {
state: 'detached',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ export interface TestCaseFormProps {
export interface TestSuiteIngestionProps {
testSuite: TestSuite;
ingestionPipeline?: IngestionPipeline;
onCancel: () => void;
testCaseNames?: string[];
pipelineName?: string;
onCancel?: () => void;
showAddTestCase?: boolean;
onViewServiceClick?: () => void;
}

export type TestSuiteIngestionDataType = {
repeatFrequency: string;
enableDebugLog?: boolean;
testCases?: string[];
name?: string;
selectTestCase?: boolean;
};

export interface TestSuiteSchedulerProps {
Expand All @@ -61,6 +64,15 @@ export interface TestSuiteSchedulerProps {
includePeriodOptions?: string[];
}

export interface AddTestSuitePipelineProps {
initialData?: Partial<TestSuiteIngestionDataType>;
isLoading: boolean;
onSubmit: (data: TestSuiteIngestionDataType) => void;
includePeriodOptions?: string[];
onCancel?: () => void;
showAddTestCase?: boolean;
}

export interface RightPanelProps {
data: {
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const AddDataQualityTestV1: React.FC<AddDataQualityTestProps> = ({
<TestSuiteIngestion
testSuite={testSuiteData as TestSuite}
onCancel={() => setAddIngestion(false)}
onViewServiceClick={handleRedirection}
/>
) : (
<Row className="p-xs" gutter={[16, 16]}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ import {
TestSuiteIngestionDataType,
TestSuiteIngestionProps,
} from './AddDataQualityTest.interface';
import TestSuiteScheduler from './components/TestSuiteScheduler';
import AddTestSuitePipeline from './components/AddTestSuitePipeline';

const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
ingestionPipeline,
testSuite,
onCancel,
testCaseNames,
pipelineName,
showAddTestCase = false,
onViewServiceClick,
}) => {
const { ingestionFQN } = useFqn();
const history = useHistory();
Expand Down Expand Up @@ -109,26 +109,28 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
}
renderElement={<strong />}
values={{
entity: `"${
pipelineName ??
getEntityName(ingestionData) ??
t('label.test-suite')
}"`,
entity: `"${getEntityName(ingestionData) ?? t('label.test-suite')}"`,
entityStatus: ingestionFQN
? t('label.updated-lowercase')
: t('label.created-lowercase'),
}}
/>
);
}, [ingestionData, showDeployButton, pipelineName]);
}, [ingestionData, showDeployButton]);

const initialFormData: TestSuiteIngestionDataType = useMemo(() => {
const testCases = ingestionPipeline?.sourceConfig.config?.testCases;

const initialFormData = useMemo(() => {
return {
repeatFrequency:
ingestionPipeline?.airflowConfig.scheduleInterval ?? config?.enable
ingestionPipeline?.airflowConfig.scheduleInterval ??
(config?.enable
? getWeekCron({ hour: 0, min: 0, dow: 0 })
: getIngestionFrequency(PipelineType.TestSuite),
: getIngestionFrequency(PipelineType.TestSuite)),
enableDebugLog: ingestionPipeline?.loggerLevel === LogLevels.Debug,
testCases,
name: ingestionPipeline?.displayName,
selectTestCase: !isUndefined(testCases),
};
}, [ingestionPipeline]);

Expand Down Expand Up @@ -166,7 +168,7 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
)
);
const updatedName =
pipelineName ?? getIngestionName(tableName, PipelineType.TestSuite);
data.name ?? getIngestionName(tableName, PipelineType.TestSuite);

const ingestionPayload: CreateIngestionPipeline = {
airflowConfig: {
Expand All @@ -187,7 +189,7 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
type: ConfigType.TestSuite,
entityFullyQualifiedName:
testSuite.executableEntityReference?.fullyQualifiedName,
testCases: testCaseNames,
testCases: data?.testCases,
},
},
};
Expand All @@ -207,7 +209,7 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({

const updatedPipelineData = {
...ingestionPipeline,
displayName: pipelineName,
displayName: data.name ?? ingestionPipeline.displayName,
airflowConfig: {
...ingestionPipeline?.airflowConfig,
scheduleInterval: isEmpty(data.repeatFrequency)
Expand All @@ -219,7 +221,7 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
...ingestionPipeline?.sourceConfig,
config: {
...ingestionPipeline?.sourceConfig.config,
testCases: testCaseNames,
testCases: data?.testCases,
},
},
};
Expand All @@ -229,6 +231,7 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
ingestionPipeline?.id ?? '',
jsonPatch
);
setIngestionData(response);
handleIngestionDeploy(response.id);
} catch (error) {
showErrorToast(
Expand Down Expand Up @@ -281,7 +284,9 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
{isIngestionCreated ? (
<SuccessScreen
handleDeployClick={handleDeployClick}
handleViewServiceClick={handleViewTestSuiteClick}
handleViewServiceClick={
onViewServiceClick ?? handleViewTestSuiteClick
}
name={`${testSuite?.name}_${PipelineType.TestSuite}`}
showDeployButton={showDeployButton}
showIngestionButton={false}
Expand All @@ -292,19 +297,19 @@ const TestSuiteIngestion: React.FC<TestSuiteIngestionProps> = ({
})}
/>
) : (
<TestSuiteScheduler
allowEnableDebugLog
<AddTestSuitePipeline
includePeriodOptions={schedulerOptions}
initialData={initialFormData}
isLoading={isLoading}
showAddTestCase={showAddTestCase}
onCancel={onCancel}
onSubmit={handleIngestionSubmit}
/>
)}
</Col>
<DeployIngestionLoaderModal
action={ingestionAction}
ingestionName={pipelineName ?? getEntityName(ingestionData)}
ingestionName={getEntityName(ingestionData)}
isDeployed={isIngestionDeployed}
isIngestionCreated={isIngestionCreated}
progress={ingestionProgress}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { act, fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { AddTestSuitePipelineProps } from '../AddDataQualityTest.interface';
import AddTestSuitePipeline from './AddTestSuitePipeline';
const mockUseHistory = {
goBack: jest.fn(),
};
jest.mock('../../../../hooks/useFqn', () => ({
useFqn: jest.fn().mockReturnValue({ fqn: 'test-suite-fqn' }),
}));
jest.mock('../../AddTestCaseList/AddTestCaseList.component', () => ({
AddTestCaseList: jest
.fn()
.mockImplementation(() => <div>AddTestCaseList.component</div>),
}));
jest.mock('react-router-dom', () => ({
useHistory: jest.fn().mockImplementation(() => mockUseHistory),
}));

const mockProps: AddTestSuitePipelineProps = {
isLoading: false,
onSubmit: jest.fn(),
showAddTestCase: true,
};

describe('AddTestSuitePipeline', () => {
it('renders form fields', () => {
render(<AddTestSuitePipeline {...mockProps} />);

// Assert that the form fields are rendered
expect(screen.getByTestId('pipeline-name')).toBeInTheDocument();
expect(screen.getByTestId('enable-debug-log')).toBeInTheDocument();
expect(screen.getByTestId('cron-container')).toBeInTheDocument();
expect(screen.getByTestId('select-test-case')).toBeInTheDocument();
expect(screen.getByTestId('deploy-button')).toBeInTheDocument();
expect(screen.getByTestId('cancel')).toBeInTheDocument();
});

it('calls onSubmit when submit button is clicked', async () => {
render(<AddTestSuitePipeline {...mockProps} />);

fireEvent.change(screen.getByTestId('pipeline-name'), {
target: { value: 'Test Suite pipeline' },
});
await act(async () => {
await fireEvent.click(screen.getByTestId('enable-debug-log'));
});
await act(async () => {
await fireEvent.click(screen.getByTestId('deploy-button'));
});

// Assert that onSubmit is called with the correct values
expect(mockProps.onSubmit).toHaveBeenCalledWith({
enableDebugLog: true,
name: 'Test Suite pipeline',
period: '',
repeatFrequency: undefined,
selectTestCase: undefined,
testCases: undefined,
});
});

it('calls onCancel when cancel button is clicked and onCancel button is provided', async () => {
const mockOnCancel = jest.fn();
render(<AddTestSuitePipeline {...mockProps} onCancel={mockOnCancel} />);

await act(async () => {
await fireEvent.click(screen.getByTestId('cancel'));
});

expect(mockOnCancel).toHaveBeenCalled();
});

it('calls history.goBack when cancel button is clicked and onCancel button is not provided', async () => {
render(<AddTestSuitePipeline {...mockProps} />);

await act(async () => {
await fireEvent.click(screen.getByTestId('cancel'));
});

expect(mockUseHistory.goBack).toHaveBeenCalled();
});

it('displays AddTestCaseList after clicking on select-test-case switch', async () => {
render(<AddTestSuitePipeline {...mockProps} />);

// Assert that AddTestCaseList.component is not initially visible
expect(screen.queryByText('AddTestCaseList.component')).toBeNull();

// Click on the select-test-case switch
await act(async () => {
await fireEvent.click(screen.getByTestId('select-test-case'));
});

// Assert that AddTestCaseList.component is now visible
expect(screen.getByText('AddTestCaseList.component')).toBeInTheDocument();
});

it('renders with initial data', () => {
const initialData = {
enableDebugLog: true,
name: 'Initial Test Suite',
repeatFrequency: '* 0 0 0',
selectTestCase: true,
testCases: ['test-case-1', 'test-case-2'],
};

render(<AddTestSuitePipeline {...mockProps} initialData={initialData} />);

// Assert that the form fields are rendered with the initial data
expect(screen.getByTestId('pipeline-name')).toHaveValue(initialData.name);
expect(screen.getByTestId('enable-debug-log')).toBeChecked();
expect(screen.getByTestId('select-test-case')).toBeChecked();
expect(screen.getByTestId('deploy-button')).toBeInTheDocument();
expect(screen.getByTestId('cancel')).toBeInTheDocument();
});

it('testCases removal should work', async () => {
const initialData = {
enableDebugLog: true,
name: 'Initial Test Suite',
repeatFrequency: '* 0 0 0',
selectTestCase: true,
testCases: ['test-case-1', 'test-case-2'],
};

render(<AddTestSuitePipeline {...mockProps} initialData={initialData} />);

await act(async () => {
await fireEvent.click(screen.getByTestId('select-test-case'));
});

expect(screen.queryByText('AddTestCaseList.component')).toBeNull();

await act(async () => {
await fireEvent.click(screen.getByTestId('deploy-button'));
});

// Assert that onSubmit is called with the initial data
expect(mockProps.onSubmit).toHaveBeenCalledWith({
...initialData,
period: '',
selectTestCase: false,
testCases: undefined,
});
});

it('does not render add test case container if showAddTestCase is false', () => {
render(<AddTestSuitePipeline {...mockProps} showAddTestCase={false} />);

// Assert that add-test-case-container is not rendered
expect(screen.queryByTestId('add-test-case-container')).toBeNull();
});
});
Loading

0 comments on commit 8d9ff41

Please sign in to comment.