test.jsx 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 sinon from 'sinon'
  17. import ReplicaDetailsContent from '.'
  18. const wrap = props => shallow(<ReplicaDetailsContent {...props} />)
  19. let endpoints = [
  20. { id: 'endpoint-1', name: 'Endpoint OPS', type: 'openstack' },
  21. { id: 'endpoint-2', name: 'Endpoint AZURE', type: 'azure' },
  22. ]
  23. let item = {
  24. origin_endpoint_id: 'endpoint-1',
  25. destination_endpoint_id: 'endpoint-2',
  26. id: 'item-id',
  27. created_at: new Date(2017, 10, 24, 16, 15),
  28. destination_environment: { description: 'A description' },
  29. type: 'Replica',
  30. executions: [
  31. { id: 'execution-1', status: 'ERROR', created_at: new Date() },
  32. { id: 'execution-2', status: 'COMPLETED', created_at: new Date() },
  33. { id: 'execution-2-1', status: 'CANCELED', created_at: new Date() },
  34. { id: 'execution-3', status: 'RUNNING', created_at: new Date() },
  35. ],
  36. }
  37. it('renders main details page', () => {
  38. let wrapper = wrap({ endpoints, item, page: '' })
  39. expect(wrapper.find('MainDetails').prop('item').id).toBe('item-id')
  40. })
  41. it('renders executions page', () => {
  42. let wrapper = wrap({ endpoints, item, page: 'executions' })
  43. expect(wrapper.find('Executions').prop('item').executions[1].id).toBe('execution-2')
  44. })
  45. it('renders details loading', () => {
  46. let wrapper = wrap({ endpoints, item, page: '', detailsLoading: true })
  47. expect(wrapper.find('MainDetails').prop('loading')).toBe(true)
  48. })
  49. it('renders schedule page', () => {
  50. let wrapper = wrap({ endpoints, item, page: 'schedule', scheduleStore: { schedules: [] } })
  51. expect(wrapper.find('Schedule').prop('schedules').length).toBe(0)
  52. })
  53. it('has `Create migration` button disabled if endpoint is missing', () => {
  54. let wrapper = wrap({ endpoints, item: null, page: '' })
  55. expect(wrapper.find('MainDetails').prop('bottomControls').props.children[0].props.children.props.disabled).toBe(true)
  56. })
  57. it('has `Create migration` button enabled if the last status is completed', () => {
  58. let newItem = {
  59. ...item,
  60. executions: [...item.executions, { id: 'execution-4', status: 'COMPLETED', created_at: new Date() }],
  61. }
  62. let wrapper = wrap({ endpoints, item: newItem, page: '' })
  63. expect(wrapper.find('MainDetails').prop('bottomControls').props.children[0].props.children.props.disabled).toBe(false)
  64. })
  65. it('dispaches create migration click', () => {
  66. let onCreateMigrationClick = sinon.spy()
  67. let wrapper = wrap({ endpoints, item, page: '', onCreateMigrationClick })
  68. wrapper.find('MainDetails').prop('bottomControls').props.children[0].props.children.props.onClick()
  69. expect(onCreateMigrationClick.calledOnce).toBe(true)
  70. })
  71. it('has `Create migration` button disabled if endpoint is missing and last status is completed', () => {
  72. let newItem = {
  73. ...item,
  74. origin_endpoint_id: 'missing',
  75. executions: [...item.executions, { id: 'execution-4', status: 'COMPLETED', created_at: new Date() }],
  76. }
  77. let wrapper = wrap({ endpoints, item: newItem, page: '' })
  78. expect((wrapper.find('MainDetails').prop('bottomControls').props.children[0].props.children.props.disabled)).toBe(true)
  79. })
  80. it('dispatches delete click', () => {
  81. let onDeleteReplicaClick = sinon.spy()
  82. let wrapper = wrap({ endpoints, item, page: '', onDeleteReplicaClick })
  83. wrapper.find('MainDetails').prop('bottomControls').props.children[1].props.children[1].props.onClick()
  84. expect(onDeleteReplicaClick.calledOnce).toBe(true)
  85. })