test.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 type { Project } from '@src/@types/Project'
  19. import EndpointDuplicateOptions from '.'
  20. type Props = {
  21. projects: Project[],
  22. selectedProjectId: string,
  23. duplicating: boolean,
  24. onCancelClick: () => void,
  25. onDuplicateClick: (projectId: string) => void,
  26. }
  27. const wrap = (props: Props) => new TW(shallow(<EndpointDuplicateOptions {...props} />), 'edOptions')
  28. const projects: Project[] = [
  29. { id: 'project-1', name: 'Project 1' },
  30. { id: 'project-2', name: 'Project 2' },
  31. ]
  32. describe('EndpointDuplicateOptions Component', () => {
  33. it('renders projects', () => {
  34. let wrapper = wrap({
  35. projects,
  36. selectedProjectId: 'project-2',
  37. duplicating: false,
  38. onCancelClick: () => { },
  39. onDuplicateClick: () => { },
  40. })
  41. expect(wrapper.find('field-project').prop('enum')[1].name).toBe(projects[1].name)
  42. expect(wrapper.find('field-project').prop('value')).toBe('project-2')
  43. expect(wrapper.find('loading').length).toBe(0)
  44. })
  45. it('dispatches duplicate', () => {
  46. let onDuplicateClick = sinon.spy()
  47. let wrapper = wrap({
  48. projects,
  49. selectedProjectId: 'project-2',
  50. duplicating: false,
  51. onCancelClick: () => { },
  52. onDuplicateClick,
  53. })
  54. wrapper.find('duplicateButton').click()
  55. expect(onDuplicateClick.args[0][0]).toBe('project-2')
  56. })
  57. it('renders loading', () => {
  58. let wrapper = wrap({
  59. projects,
  60. selectedProjectId: 'project-2',
  61. duplicating: true,
  62. onCancelClick: () => { },
  63. onDuplicateClick: () => { },
  64. })
  65. expect(wrapper.find('loading').length).toBe(1)
  66. })
  67. })