test.jsx 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 WizardNetworks from '.'
  19. const wrap = props => new TW(shallow(
  20. // $FlowIgnore
  21. <WizardNetworks {...props} />
  22. ), 'wNetworks')
  23. let networks = [
  24. { name: 'network 1', value: 'n-1' },
  25. { name: 'network 2', value: 'n-2' },
  26. ]
  27. let instancesDetails = [
  28. {
  29. devices: { nics: [{ network_name: 'network 1', id: 'n-1' }] },
  30. instance_name: 'Instance name 1',
  31. },
  32. {
  33. devices: { nics: [{ network_name: 'network 2', id: 'n-2' }] },
  34. instance_name: 'Instance name 2',
  35. },
  36. {
  37. devices: { nics: [{ network_name: 'network 3', id: 'n-3' }] },
  38. instance_name: 'Instance name 3',
  39. },
  40. ]
  41. let selectedNetworks = [
  42. {
  43. sourceNic: { id: 'n-2', network_name: 'network 2' },
  44. targetNetwork: { name: 'network 1' },
  45. },
  46. ]
  47. describe('WizardNetworks Component', () => {
  48. it('renders correct number of instance details', () => {
  49. let wrapper = wrap({ networks, instancesDetails })
  50. expect(wrapper.findPartialId('dropdown-').length).toBe(instancesDetails.length)
  51. })
  52. it('renders correct info for instance details', () => {
  53. let wrapper = wrap({ networks, instancesDetails })
  54. expect(wrapper.findText('connectedTo-n-1')).toBe('Connected to Instance name 1')
  55. expect(wrapper.findText('connectedTo-n-2')).toBe('Connected to Instance name 2')
  56. expect(wrapper.findText('connectedTo-n-3')).toBe('Connected to Instance name 3')
  57. expect(wrapper.findText('networkName-n-1')).toBe('network 1')
  58. expect(wrapper.findText('networkName-n-2')).toBe('network 2')
  59. expect(wrapper.findText('networkName-n-3')).toBe('network 3')
  60. })
  61. it('has dropdown with correct number of networks', () => {
  62. let wrapper = wrap({ networks, instancesDetails })
  63. expect(wrapper.find('dropdown-n-1').prop('items').length).toBe(networks.length)
  64. expect(wrapper.find('dropdown-n-2').prop('items').length).toBe(networks.length)
  65. expect(wrapper.find('dropdown-n-3').prop('items').length).toBe(networks.length)
  66. })
  67. it('has dropdown with correct networks info', () => {
  68. let wrapper = wrap({ networks, instancesDetails })
  69. expect(wrapper.find('dropdown-n-1').prop('items')[0].name).toBe('network 1')
  70. expect(wrapper.find('dropdown-n-2').prop('items')[1].name).toBe('network 2')
  71. })
  72. it('renders selected networks', () => {
  73. let wrapper = wrap({ networks, instancesDetails, selectedNetworks })
  74. expect(wrapper.find('dropdown-n-1').prop('selectedItem')).toBeFalsy()
  75. expect(wrapper.find('dropdown-n-2').prop('selectedItem').name).toBe('network 1')
  76. expect(wrapper.find('dropdown-n-3').prop('selectedItem')).toBeFalsy()
  77. expect(wrapper.find('noNics').length).toBe(0)
  78. })
  79. it('renders no nics message', () => {
  80. let wrapper = wrap({ networks, instancesDetails: [{ ...instancesDetails[0], devices: { nics: [] } }] })
  81. expect(wrapper.find('noNics').length).toBe(1)
  82. })
  83. })