test.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 TW from '@src/utils/TestWrapper'
  17. import EndpointValidation from '.'
  18. const wrap = props => new TW(shallow(
  19. <EndpointValidation {...props} />
  20. ), 'eValidation')
  21. describe('EndpointValidation Component', () => {
  22. it('renders loading', () => {
  23. let wrapper = wrap({ loading: true })
  24. expect(wrapper.find('status').prop('loading')).toBe(true)
  25. expect(wrapper.findText('title')).toBe('Validating Endpoint')
  26. })
  27. it('renders valid', () => {
  28. let wrapper = wrap({ validation: { valid: true } })
  29. expect(wrapper.find('status').prop('status')).toBe('COMPLETED')
  30. expect(wrapper.findText('title')).toBe('Endpoint is Valid')
  31. })
  32. it('renders failed with default message', () => {
  33. let wrapper = wrap({ validation: {} })
  34. expect(wrapper.find('status').prop('status')).toBe('ERROR')
  35. expect(wrapper.findText('title')).toBe('Validation Failed')
  36. expect(wrapper.findText('errorMessage')).toBe('An unexpected error occurred.<CopyButton />')
  37. })
  38. it('renders failed with custom message', () => {
  39. let wrapper = wrap({ validation: { message: 'custom_message' } })
  40. expect(wrapper.find('status').prop('status')).toBe('ERROR')
  41. expect(wrapper.findText('title')).toBe('Validation Failed')
  42. expect(wrapper.findText('errorMessage')).toBe('custom_message<CopyButton />')
  43. })
  44. })