Skip to content

Commit

Permalink
test for traffic splitting and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesis09 committed Mar 24, 2020
1 parent 91a7ad1 commit a4bb1a5
Showing 1 changed file with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { MultiColumnField } from '@console/shared';
import { ModalBody, ModalSubmitFooter } from '@console/internal/components/factory/modal';
import TrafficSplittingModal from '../TrafficSplittingModal';
import {
mockTrafficData,
mockRevisionItems,
} from '../../../utils/__mocks__/traffic-splitting-utils-mock';

const formProps = {
errors: {},
touched: {},
isSubmitting: true,
isValidating: true,
status: { error: 'error' },
submitCount: 0,
dirty: false,
handleReset: jest.fn(),
handleSubmit: jest.fn(),
getFieldProps: jest.fn(),
handleBlur: jest.fn(),
handleChange: jest.fn(),
initialValues: [{ percent: 100, revisionName: 'overlayimage-fdqsf' }],
initialErrors: {},
initialStatus: {},
initialTouched: {},
isValid: true,
resetForm: jest.fn(),
setErrors: jest.fn(),
setFieldError: jest.fn(),
setFieldTouched: jest.fn(),
setFieldValue: jest.fn(),
setFormikState: jest.fn(),
setStatus: jest.fn(),
setSubmitting: jest.fn(),
setTouched: jest.fn(),
setValues: jest.fn(),
submitForm: jest.fn(),
registerField: jest.fn(),
unregisterField: jest.fn(),
validateField: jest.fn(),
validateForm: jest.fn(),
getFieldMeta: jest.fn(),
validateOnBlur: true,
validateOnChange: true,
};

describe('TrafficSplittingModal', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(
<TrafficSplittingModal
revisionItems={mockRevisionItems}
values={{ trafficSplitting: mockTrafficData }}
{...formProps}
/>,
);
});

it('should disable add row for one value', () => {
wrapper = shallow(
<TrafficSplittingModal
revisionItems={[{ 'overlayimage-fdqsf': 'overlayimage-fdqsf' }]}
values={{ trafficSplitting: [{ percent: 100, revisionName: 'overlayimage-fdqsf' }] }}
{...formProps}
/>,
);
expect(
wrapper
.find(ModalBody)
.dive()
.find(MultiColumnField)
.first()
.props().disableDeleteRow,
).toBe(true);
});

it('should not disable add row for more than one values', () => {
expect(
wrapper
.find(ModalBody)
.dive()
.find(MultiColumnField)
.first()
.props().disableDeleteRow,
).toBe(false);
});

it('should should render modal footer with proper values', () => {
wrapper.find('form').simulate('submit', {
preventDefault: () => {},
});
expect(
wrapper
.find(ModalSubmitFooter)
.first()
.props().inProgress,
).toBe(true);
expect(
wrapper
.find(ModalSubmitFooter)
.first()
.props().errorMessage,
).toEqual('error');
});
});

0 comments on commit a4bb1a5

Please sign in to comment.