test.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // @flow
  15. import React from 'react'
  16. import { shallow } from 'enzyme'
  17. import TW from '../../../utils/TestWrapper'
  18. import type { Project } from '../../../types/Project'
  19. import type { User } from '../../../types/User'
  20. import UserDetailsContent from '.'
  21. type Props = {
  22. user: ?User,
  23. loading: boolean,
  24. projects: Project[],
  25. userProjects: Project[],
  26. isLoggedUser: boolean,
  27. }
  28. const wrap = (props: Props) => new TW(shallow(
  29. <UserDetailsContent
  30. onEditClick={() => { }}
  31. onUpdatePasswordClick={() => { }}
  32. onDeleteConfirmation={() => { }}
  33. onDeleteClick={() => { }}
  34. {...props}
  35. />
  36. ), 'udContent')
  37. const projects: Project[] = [
  38. { id: 'project-1', name: 'Project 1' },
  39. { id: 'project-2', name: 'Project 2' },
  40. ]
  41. const user: User = { id: 'user-1', name: 'User 1', email: 'email1', project: projects[0] }
  42. describe('UserDetailsContent Component', () => {
  43. it('renders info', () => {
  44. let wrapper = wrap({
  45. user,
  46. projects,
  47. userProjects: projects,
  48. loading: false,
  49. isLoggedUser: false,
  50. })
  51. expect(wrapper.find('name').prop('value')).toBe('User 1')
  52. expect(wrapper.find('id').prop('value')).toBe('user-1')
  53. expect(wrapper.find('project-', true).at(0).text(true)).toBe('Project 1')
  54. expect(wrapper.find('project-', true).at(1).text(true)).toBe('Project 2')
  55. })
  56. })