test.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from 'react'
  15. import { shallow } from 'enzyme'
  16. import EndpointField from './EndpointField'
  17. const wrap = props => shallow(<EndpointField {...props} />)
  18. it('renders boolean field with correct value', () => {
  19. let wrapper = wrap({ type: 'boolean', name: 'label', value: true })
  20. expect(wrapper.childAt(1).name()).toBe('Switch')
  21. expect(wrapper.childAt(1).prop('checked')).toBe(true)
  22. })
  23. it('renders boolean field disabled', () => {
  24. let wrapper = wrap({ type: 'boolean', name: 'label', disabled: true })
  25. expect(wrapper.childAt(1).prop('disabled')).toBe(true)
  26. })
  27. it('renders text input field with correct label and value', () => {
  28. let wrapper = wrap({ type: 'string', name: 'field_label', value: 'text-input' })
  29. expect(wrapper.childAt(0).contains('Field Label')).toBe(true)
  30. expect(wrapper.childAt(1).name()).toBe('TextInput')
  31. expect(wrapper.childAt(1).prop('value')).toBe('text-input')
  32. })
  33. it('renders text input field with password, large, disabled, highlighted and required', () => {
  34. let wrapper = wrap({
  35. type: 'string',
  36. name: 'field-label',
  37. value: 'text-input',
  38. password: true,
  39. large: true,
  40. disabled: true,
  41. highlight: true,
  42. required: true,
  43. })
  44. expect(wrapper.childAt(1).prop('type')).toBe('password')
  45. expect(wrapper.childAt(1).prop('large')).toBe(true)
  46. expect(wrapper.childAt(1).prop('disabled')).toBe(true)
  47. expect(wrapper.childAt(1).prop('highlight')).toBe(true)
  48. expect(wrapper.childAt(1).prop('required')).toBe(true)
  49. })
  50. it('renders integer dropdown field with correct items', () => {
  51. let wrapper = wrap({
  52. type: 'integer',
  53. name: 'field-label',
  54. value: 11,
  55. minimum: 10,
  56. maximum: 15,
  57. })
  58. expect(wrapper.childAt(1).prop('selectedItem')).toBe(11)
  59. expect(wrapper.childAt(1).prop('items')[3].value).toBe(13)
  60. expect(wrapper.childAt(1).prop('items')[5].value).toBe(15)
  61. })
  62. it('renders radio input field with correct value', () => {
  63. let wrapper = wrap({ type: 'radio', name: 'label', value: true })
  64. expect(wrapper.childAt(0).name()).toBe('RadioInput')
  65. expect(wrapper.childAt(0).prop('checked')).toBe(true)
  66. })