test.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ReplicaExecutionOptions from '.'
  19. import { executionOptions } from '@src/constants'
  20. const wrap = props => new TW(shallow(<ReplicaExecutionOptions {...props} />), 'reOptions')
  21. describe('ReplicaExecutionOptions Component', () => {
  22. it('renders executionOptions from config', () => {
  23. let wrapper = wrap()
  24. executionOptions.forEach(option => {
  25. expect(wrapper.find(`option-${option.name}`).prop('name')).toBe(option.name)
  26. })
  27. })
  28. it('renders executionOptions with default values', () => {
  29. let wrapper = wrap()
  30. executionOptions.forEach(option => {
  31. expect(wrapper.find(`option-${option.name}`).prop('value')).toBe(option.defaultValue || undefined)
  32. })
  33. })
  34. it('renders executionOptions with given values', () => {
  35. let wrapper = wrap({ options: { shutdown_instances: true } })
  36. expect(wrapper.find('option-shutdown_instances').prop('value')).toBe(true)
  37. })
  38. it('dispaches cancel click', () => {
  39. let onCancelClick = sinon.spy()
  40. let wrapper = wrap({ onCancelClick })
  41. wrapper.find('cancelButton').click()
  42. expect(onCancelClick.calledOnce).toBe(true)
  43. })
  44. it('renders custom execution button label', () => {
  45. let wrapper = wrap({ executionLabel: 'custom_exec' })
  46. expect(wrapper.find('execButton').shallow.dive().dive().text()).toBe('custom_exec')
  47. })
  48. it('dispaches execution click', () => {
  49. let onExecuteClick = sinon.spy()
  50. let wrapper = wrap({ onExecuteClick })
  51. wrapper.find('execButton').click()
  52. expect(onExecuteClick.args[0][0][0].name).toBe(executionOptions[0].name)
  53. })
  54. })