Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Fix Pipleine creation without namespace issue
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik committed Dec 11, 2020
1 parent 17cb2b6 commit 9d1a187
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const PipelineBuilderPage: React.FC<PipelineBuilderPageProps> = (props) => {
if (values.editorType === EditorType.YAML) {
try {
pipeline = safeLoad(values.yamlData);
if (!pipeline.metadata?.namespace) {
pipeline.metadata.namespace = ns;
}
} catch (err) {
actions.setStatus({ submitError: `Invalid YAML - ${err}` });
return null;
Expand Down
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);
});
});

0 comments on commit 9d1a187

Please sign in to comment.