test.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 TW from '@src/utils/TestWrapper'
  18. import Executions from '.'
  19. const wrap = props => new TW(shallow(
  20. <Executions {...props} />
  21. ), 'executions')
  22. let item = {
  23. executions: [
  24. { id: 'execution-1', number: 1, status: 'ERROR', created_at: new Date() },
  25. { id: 'execution-2', number: 2, status: 'COMPLETED', created_at: new Date() },
  26. { id: 'execution-3', number: 3, status: 'CANCELED', created_at: new Date() },
  27. { id: 'execution-4', number: 4, status: 'RUNNING', created_at: new Date() },
  28. ],
  29. }
  30. describe('Executions Component', () => {
  31. it('selects last execution by default', () => {
  32. let wrapper = wrap({ item })
  33. expect(wrapper.findText('number')).toBe('Execution #4')
  34. })
  35. it('selects previous execution on previous click', () => {
  36. let wrapper = wrap({ item })
  37. wrapper.find('timeline').simulate('previousClick')
  38. expect(wrapper.findText('number')).toBe('Execution #3')
  39. wrapper.find('timeline').simulate('previousClick')
  40. expect(wrapper.findText('number')).toBe('Execution #2')
  41. })
  42. it('selects next execution on next click', () => {
  43. let wrapper = wrap({ item })
  44. wrapper.find('timeline').simulate('previousClick')
  45. wrapper.find('timeline').simulate('previousClick')
  46. wrapper.find('timeline').simulate('nextClick')
  47. expect(wrapper.findText('number')).toBe('Execution #3')
  48. })
  49. it('doesn\'t select next execution on next click if not possible', () => {
  50. let wrapper = wrap({ item })
  51. wrapper.find('timeline').simulate('nextClick')
  52. expect(wrapper.findText('number')).toBe('Execution #4')
  53. })
  54. it('shows cancel button on running executions', () => {
  55. let wrapper = wrap({ item })
  56. expect(wrapper.find('cancelButton').length).toBe(1)
  57. expect(wrapper.find('deleteButton').length).toBe(0)
  58. })
  59. it('shows delete button on non-running executions', () => {
  60. let wrapper = wrap({ item })
  61. wrapper.find('timeline').simulate('previousClick')
  62. expect(wrapper.find('cancelButton').length).toBe(0)
  63. expect(wrapper.find('deleteButton').length).toBe(1)
  64. })
  65. it('dispatches cancel click', () => {
  66. let onCancelExecutionClick = sinon.spy()
  67. let wrapper = wrap({ item, onCancelExecutionClick })
  68. wrapper.find('cancelButton').simulate('click')
  69. expect(onCancelExecutionClick.calledOnce).toBe(true)
  70. })
  71. it('dispatches delete click', () => {
  72. let onDeleteExecutionClick = sinon.spy()
  73. let wrapper = wrap({ item, onDeleteExecutionClick })
  74. wrapper.find('timeline').simulate('previousClick')
  75. wrapper.find('deleteButton').simulate('click')
  76. expect(onDeleteExecutionClick.calledOnce).toBe(true)
  77. })
  78. it('renders no executions', () => {
  79. let wrapper = wrap({ item: {} })
  80. expect(wrapper.findText('noExTitle')).toBe('It looks like there are no executions in this replica.')
  81. })
  82. it('dispatches execute click', () => {
  83. let onExecuteClick = sinon.spy()
  84. let wrapper = wrap({ item: {}, onExecuteClick })
  85. wrapper.find('executeButton').simulate('click')
  86. expect(onExecuteClick.calledOnce).toBe(true)
  87. })
  88. })