-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated multi pipeline ui as per new mock (#17106)
* 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
1 parent
00278ce
commit 8d9ff41
Showing
26 changed files
with
615 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
...ui/src/components/DataQuality/AddDataQualityTest/components/AddTestSuitePipeline.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
Oops, something went wrong.