-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for traffic splitting and refactor
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
.../knative-plugin/src/components/traffic-splitting/__tests__/TrafficSplittingModal.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,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'); | ||
}); | ||
}); |