test.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 TW from '../../../utils/TestWrapper'
  18. import WizardOptionsField from '.'
  19. // $FlowIgnore
  20. const wrap = props => new TW(shallow(<WizardOptionsField {...props} />), 'wOptionsField')
  21. describe('WizardOptionsField Component', () => {
  22. it('renders label', () => {
  23. let wrapper = wrap({ name: 'the_name', type: 'string', value: 'the_value' })
  24. expect(wrapper.findText('label')).toBe('The Name')
  25. })
  26. it('renders string input with correct value', () => {
  27. let wrapper = wrap({ name: 'the_name', type: 'string', value: 'the_value' })
  28. expect(wrapper.find('textInput').prop('value')).toBe('the_value')
  29. })
  30. it('renders required field', () => {
  31. let wrapper = wrap({ name: 'the_name', type: 'string', value: 'the_value', required: true })
  32. expect(wrapper.find('required').length).toBe(1)
  33. wrapper = wrap({ name: 'the_name', type: 'string', value: 'the_value', required: false })
  34. expect(wrapper.find('required').length).toBe(0)
  35. })
  36. it('renders strict boolean with correct value', () => {
  37. let wrapper = wrap({ name: 'the_name', type: 'strict-boolean', value: true })
  38. expect(wrapper.find('switch').prop('triState')).toBe(false)
  39. expect(wrapper.find('switch').prop('checked')).toBe(true)
  40. })
  41. it('renders boolean with correct value', () => {
  42. let wrapper = wrap({ name: 'the_name', type: 'boolean', value: true })
  43. expect(wrapper.find('switch').prop('triState')).toBe(true)
  44. expect(wrapper.find('switch').prop('checked')).toBe(true)
  45. })
  46. it('renders enum string', () => {
  47. let wrapper = wrap({
  48. name: 'the_name',
  49. type: 'string',
  50. value: 'reuse_ports',
  51. enum: ['keep_mac', 'reuse_ports', 'replace_mac'],
  52. })
  53. expect(wrapper.find('enumDropdown-the_name').prop('selectedItem').label).toBe('Reuse Existing Ports')
  54. expect(wrapper.find('enumDropdown-the_name').prop('items')[3].value).toBe('replace_mac')
  55. })
  56. it('renders object table', () => {
  57. let wrapper = wrap({
  58. name: 'test',
  59. type: 'object',
  60. properties: [
  61. { type: 'boolean', name: 'prop-1', label: 'Property 1' },
  62. { type: 'boolean', name: 'prop-2', label: 'Property 2' },
  63. ],
  64. valueCallback: prop => prop.name === 'prop-2',
  65. })
  66. expect(wrapper.find('propertiesTable').prop('properties')[1].name).toBe('prop-2')
  67. })
  68. })