This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Pipleine creation without namespace issue
- Loading branch information
karthik
committed
Dec 11, 2020
1 parent
17cb2b6
commit 9d1a187
Showing
2 changed files
with
61 additions
and
0 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
58 changes: 58 additions & 0 deletions
58
...s-plugin/src/components/pipelines/pipeline-builder/__tests__/PipelineBuilderPage.spec.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,58 @@ | ||
import * as React from 'react'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import { Formik } from 'formik'; | ||
import PipelineBuilderPage from '../PipelineBuilderPage'; | ||
import { pipelineTestData, PipelineExampleNames } from '../../../../test-data/pipeline-data'; | ||
|
||
type PipelineBuilderPageProps = React.ComponentProps<typeof PipelineBuilderPage>; | ||
type BuilderProps = React.ComponentProps<typeof Formik>; | ||
|
||
jest.mock('react-i18next', () => { | ||
const reactI18next = require.requireActual('react-i18next'); | ||
return { | ||
...reactI18next, | ||
useTranslation: () => ({ t: (key) => key }), | ||
}; | ||
}); | ||
|
||
const { pipeline } = pipelineTestData[PipelineExampleNames.WORKSPACE_PIPELINE]; | ||
describe('PipelineBuilderPage Form', () => { | ||
let formProps: PipelineBuilderPageProps; | ||
let PipelineBuilderPageWrapper: ShallowWrapper<PipelineBuilderPageProps>; | ||
|
||
beforeEach(() => { | ||
formProps = { | ||
history: null, | ||
location: null, | ||
match: { params: { ns: 'default' }, isExact: true, path: '', url: '' }, | ||
}; | ||
PipelineBuilderPageWrapper = shallow(<PipelineBuilderPage {...formProps} />); | ||
}); | ||
|
||
it('should render a Formik component', () => { | ||
const PipelineBuilderForm = PipelineBuilderPageWrapper.find(Formik); | ||
expect(PipelineBuilderForm).toHaveLength(1); | ||
}); | ||
|
||
it('should have form view as default option and empty default values', () => { | ||
const PipelineBuilderForm = PipelineBuilderPageWrapper.find(Formik); | ||
const builderProps = PipelineBuilderForm.props() as BuilderProps; | ||
|
||
expect(builderProps.initialValues.editorType).toBe('form'); | ||
expect(builderProps.initialValues.formData.params).toHaveLength(0); | ||
expect(builderProps.initialValues.formData.tasks).toHaveLength(0); | ||
expect(builderProps.initialValues.formData.resources).toHaveLength(0); | ||
}); | ||
|
||
it('should contain the given pipeline values in intialValues', () => { | ||
PipelineBuilderPageWrapper = shallow( | ||
<PipelineBuilderPage {...formProps} existingPipeline={pipeline} />, | ||
); | ||
const PipelineBuilderForm = PipelineBuilderPageWrapper.find(Formik); | ||
const builderProps = PipelineBuilderForm.props() as BuilderProps; | ||
const { name, tasks } = builderProps.initialValues.formData; | ||
|
||
expect(name).toBe(pipeline.metadata.name); | ||
expect(tasks).toHaveLength(pipeline.spec.tasks.length); | ||
}); | ||
}); |