test.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 WizardOptions from './WizardOptions'
  17. const wrap = props => shallow(<WizardOptions {...props} />)
  18. let fields = [
  19. {
  20. name: 'string_field',
  21. type: 'string',
  22. },
  23. {
  24. name: 'string_field_with_default',
  25. type: 'string',
  26. default: 'default',
  27. },
  28. {
  29. required: true,
  30. name: 'required_string_field',
  31. type: 'string',
  32. },
  33. {
  34. name: 'enum_field',
  35. type: 'string',
  36. enum: ['enum 1', 'enum 2', 'enum 3'],
  37. },
  38. {
  39. name: 'boolean_field',
  40. type: 'boolean',
  41. },
  42. {
  43. name: 'strict_boolean_field',
  44. type: 'strict-boolean',
  45. },
  46. ]
  47. it('has description and required field in simple tab', () => {
  48. let wrapper = wrap({ fields, selectedInstances: [] })
  49. let optionsFields = wrapper.find('Styled(WizardOptionsField)')
  50. expect(optionsFields.length).toBe(2)
  51. expect(optionsFields.at(0).prop('name')).toBe('description')
  52. expect(optionsFields.at(1).prop('name')).toBe('required_string_field')
  53. })
  54. it('renders execute now for replica', () => {
  55. let wrapper = wrap({ fields, selectedInstances: [], wizardType: 'replica' })
  56. expect(wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === 'execute_now').length).toBe(1)
  57. expect(wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === 'execute_now_options').length).toBe(1)
  58. })
  59. it('renders skip os morphing for migration', () => {
  60. let wrapper = wrap({ fields, selectedInstances: [], wizardType: 'migration' })
  61. expect(wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === 'skip_os_morphing').length).toBe(1)
  62. })
  63. it('renders separate / vm if multiple instances are selected', () => {
  64. let wrapper = wrap({ fields, selectedInstances: [{}, {}] })
  65. expect(wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === 'separate_vm').length).toBe(1)
  66. })
  67. it('renders correct number of fields in advanced tab', () => {
  68. let wrapper = wrap({ fields, selectedInstances: [], useAdvancedOptions: true })
  69. let optionsFields = wrapper.find('Styled(WizardOptionsField)')
  70. expect(optionsFields.length).toBe(fields.length + 1)
  71. })
  72. it('renders correct field info', () => {
  73. let wrapper = wrap({ fields, selectedInstances: [], useAdvancedOptions: true })
  74. let findField = name => {
  75. let field = wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === name)
  76. expect(field.length).toBe(1)
  77. return field
  78. }
  79. expect(findField('description').prop('type')).toBe('string')
  80. expect(findField('required_string_field').prop('required')).toBe(true)
  81. expect(findField('string_field').prop('type')).toBe('string')
  82. expect(findField('string_field_with_default').prop('value')).toBe('default')
  83. expect(findField('enum_field').prop('enum')[0]).toBe('enum 1')
  84. expect(findField('enum_field').prop('enum')[1]).toBe('enum 2')
  85. expect(findField('boolean_field').prop('type')).toBe('boolean')
  86. expect(findField('strict_boolean_field').prop('type')).toBe('strict-boolean')
  87. })
  88. it('renders data into field', () => {
  89. let wrapper = wrap({ fields, selectedInstances: [], useAdvancedOptions: true, data: { string_field: 'new data' } })
  90. expect(wrapper.findWhere(w => w.name() === 'Styled(WizardOptionsField)' && w.prop('name') === 'string_field').prop('value')).toBe('new data')
  91. })