test.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // @flow
  15. import React from 'react'
  16. import { shallow } from 'enzyme'
  17. import TestWrapper from '../../../utils/TestWrapper'
  18. import EndpointField from '.'
  19. const wrap = props => new TestWrapper(shallow(<EndpointField {...props} />), 'endpointField')
  20. describe('EndpointField Component', () => {
  21. it('renders label', () => {
  22. const wrapper = wrap({ type: 'boolean', value: true, name: 'the_name' })
  23. expect(wrapper.findText('label')).toBe('The Name')
  24. })
  25. it('renders boolean field with correct value', () => {
  26. let wrapper = wrap({ type: 'boolean', name: 'the_name', value: true })
  27. expect(wrapper.find('switch-the_name').length).toBe(1)
  28. expect(wrapper.find('switch-the_name').prop('checked')).toBe(true)
  29. })
  30. it('renders boolean field disabled', () => {
  31. let wrapper = wrap({ type: 'boolean', name: 'the_name', disabled: true })
  32. expect(wrapper.find('switch-the_name').prop('disabled')).toBe(true)
  33. })
  34. it('renders text input field with correct label and value', () => {
  35. let wrapper = wrap({ type: 'string', name: 'the_name', value: 'the_value' })
  36. expect(wrapper.findText('label')).toBe('The Name')
  37. expect(wrapper.find('textInput-the_name').length).toBe(1)
  38. expect(wrapper.find('textInput-the_name').prop('value')).toBe('the_value')
  39. })
  40. it('renders text input field with password, large, disabled, highlighted and required', () => {
  41. let wrapper = wrap({
  42. type: 'string',
  43. name: 'the_name',
  44. value: 'the_value',
  45. password: true,
  46. large: true,
  47. disabled: true,
  48. highlight: true,
  49. required: true,
  50. })
  51. let textInput = wrapper.find('textInput-the_name')
  52. expect(textInput.prop('type')).toBe('password')
  53. expect(textInput.prop('large')).toBe(true)
  54. expect(textInput.prop('disabled')).toBe(true)
  55. expect(textInput.prop('highlight')).toBe(true)
  56. expect(textInput.prop('required')).toBe(true)
  57. })
  58. it('renders integer dropdown field with correct items', () => {
  59. let wrapper = wrap({
  60. type: 'integer',
  61. name: 'the_name',
  62. value: 11,
  63. minimum: 10,
  64. maximum: 15,
  65. })
  66. let dropdown = wrapper.find('dropdown-the_name')
  67. expect(dropdown.prop('selectedItem')).toBe(11)
  68. expect(dropdown.prop('items')[3].value).toBe(13)
  69. expect(dropdown.prop('items')[5].value).toBe(15)
  70. })
  71. it('renders radio input field with correct value', () => {
  72. let wrapper = wrap({ type: 'radio', name: 'the_name', value: true })
  73. let radioInput = wrapper.find('radioInput-the_name')
  74. expect(radioInput.length).toBe(1)
  75. expect(radioInput.prop('checked')).toBe(true)
  76. })
  77. })