test.jsx 3.7 KB

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