test.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 type { MainItem } from '../../../types/MainItem'
  18. import type { Instance } from '../../../types/Instance'
  19. import TW from '../../../utils/TestWrapper'
  20. import Component, { TEST_ID } from '.'
  21. import type { Props } from '.'
  22. const defaultInstance: Instance = {
  23. id: 'instance1id',
  24. name: 'instance1name',
  25. flavor_name: 'instance1flavorname',
  26. instance_name: 'instance1instancename',
  27. num_cpu: 2,
  28. memory_mb: 2048,
  29. os_type: 'windows',
  30. devices: {
  31. nics: [{
  32. id: 'instance1nic1',
  33. network_name: 'network1',
  34. mac_address: 'instance1macaddress',
  35. network_id: 'network1',
  36. }],
  37. disks: [{
  38. id: 'instance1disk1',
  39. name: 'instance1disk1name',
  40. storage_backend_identifier: 'asdaf',
  41. }],
  42. },
  43. }
  44. const defaultItem: MainItem = {
  45. id: 'id',
  46. executions: [],
  47. name: 'name',
  48. notes: 'notes',
  49. status: 'COMPLETED',
  50. tasks: [],
  51. created_at: new Date(2019, 2, 18, 13, 19, 10),
  52. updated_at: new Date(2019, 2, 19, 14, 18, 55),
  53. origin_endpoint_id: 'origin',
  54. destination_endpoint_id: 'destination',
  55. instances: ['instance1'],
  56. type: 'replica',
  57. info: {
  58. instance1: {
  59. export_info: { devices: { nics: [{ network_name: 'network1' }, { network_name: 'network2' }] } },
  60. },
  61. },
  62. destination_environment: { option1: 'value1' },
  63. source_environment: { option1: 'value1' },
  64. transfer_result: {
  65. instance1: defaultInstance,
  66. },
  67. storage_mappings: {
  68. backend_mappings: [{
  69. destination: 'asdaf',
  70. source: 'asdaf1',
  71. }],
  72. default: 'asdaf',
  73. disk_mappings: [{
  74. destination: 'asdaf',
  75. disk_id: 'instance1disk1',
  76. }],
  77. },
  78. network_map: {
  79. network1: 'network2',
  80. },
  81. }
  82. const defaultProps: Props = {
  83. item: defaultItem,
  84. instancesDetails: [defaultInstance],
  85. }
  86. const wrap = (props: Props) => new TW(shallow(<Component {...props} />), TEST_ID)
  87. describe('MainDetailsTable Component', () => {
  88. it('renders basic info', () => {
  89. let wrapper = wrap(defaultProps)
  90. defaultProps.instancesDetails.forEach(i => {
  91. expect(wrapper.findText(`instanceName-${i.name}`)).toBe(i.name)
  92. })
  93. expect(wrapper.findText('source-instance')).toBe('instance1')
  94. expect(wrapper.findText('destination-instance')).toBe('instance1')
  95. expect(wrapper.findText('source-network')).toBe('instance1macaddress')
  96. expect(wrapper.findText('destination-network')).toBe('network2')
  97. expect(wrapper.findText('source-storage')).toBe('instance1disk1')
  98. expect(wrapper.findText('destination-storage')).toBe('instance1disk1name')
  99. })
  100. })