-
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.
Added unit tests for SyncedEditorField
- Loading branch information
1 parent
bbc11cf
commit a73923b
Showing
2 changed files
with
90 additions
and
5 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
84 changes: 84 additions & 0 deletions
84
...packages/console-shared/src/components/formik-fields/__tests__/SyncedEditorField.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,84 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { shallow } from 'enzyme'; | ||
import { useField } from 'formik'; | ||
import { Alert } from '@patternfly/react-core'; | ||
import SyncedEditorField from '../SyncedEditorField'; | ||
import RadioGroupField from '../RadioGroupField'; | ||
import DynamicFormField from '../DynamicFormField'; | ||
import YAMLEditorField from '../YAMLEditorField'; | ||
|
||
jest.mock('formik', () => ({ | ||
useField: jest.fn(() => [{ value: 'form' }, {}]), | ||
useFormikContext: jest.fn(() => ({ | ||
values: {}, | ||
setFieldValue: jest.fn(), | ||
})), | ||
})); | ||
|
||
const mockEditors = { | ||
form: <DynamicFormField name="formData" schema={{}} />, | ||
yaml: <YAMLEditorField name="yamlData" />, | ||
}; | ||
|
||
const props = { | ||
name: 'editorType', | ||
formContext: { | ||
name: 'formData', | ||
editor: mockEditors.form, | ||
isDisabled: false, | ||
}, | ||
yamlContext: { | ||
name: 'yamlData', | ||
editor: mockEditors.yaml, | ||
isDisabled: false, | ||
}, | ||
}; | ||
describe('DropdownField', () => { | ||
it('should render radio group field inline', () => { | ||
const wrapper = shallow(<SyncedEditorField {...props} />); | ||
expect(wrapper.find(RadioGroupField).exists()).toBe(true); | ||
expect( | ||
wrapper | ||
.find(RadioGroupField) | ||
.first() | ||
.props().inline, | ||
).toBe(true); | ||
}); | ||
|
||
it('should render dynamic form field if initial editor type is form', () => { | ||
const wrapper = shallow(<SyncedEditorField {...props} />); | ||
expect(wrapper.find(DynamicFormField).exists()).toBe(true); | ||
}); | ||
|
||
it('should render dynamic form field if initial editor type is form', () => { | ||
(useField as any).mockImplementation(() => [{ value: 'yaml' }, {}]); | ||
const wrapper = shallow(<SyncedEditorField {...props} />); | ||
expect(wrapper.find(YAMLEditorField).exists()).toBe(true); | ||
}); | ||
|
||
it('should disable corresponding radio button if any editor context is disaled', () => { | ||
const newProps = _.cloneDeep(props); | ||
newProps.yamlContext.isDisabled = true; | ||
const wrapper = shallow(<SyncedEditorField {...newProps} />); | ||
expect( | ||
wrapper | ||
.find(RadioGroupField) | ||
.first() | ||
.props().options[1].isDisabled, | ||
).toBe(true); | ||
}); | ||
|
||
it('should show an alert if form context is disaled', () => { | ||
const newProps = _.cloneDeep(props); | ||
newProps.formContext.isDisabled = true; | ||
const wrapper = shallow(<SyncedEditorField {...newProps} />); | ||
expect(wrapper.find(Alert).exists()).toBe(true); | ||
expect( | ||
wrapper | ||
.find(Alert) | ||
.first() | ||
.props().title, | ||
).toBe('Form view is disabled for this chart because the schema is not available'); | ||
}); | ||
}); |