test.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 { User } from '@src/@types/User'
  19. import DetailsPageHeader from '.'
  20. type Props = {
  21. user?: User | null,
  22. }
  23. const wrap = (props: Props) => new TW(shallow(
  24. <DetailsPageHeader
  25. onUserItemClick={() => { }}
  26. testMode
  27. {...props}
  28. />
  29. ), 'dpHeader')
  30. let user = {
  31. name: 'User name',
  32. email: 'email@email.com',
  33. id: 'user',
  34. project: { id: '', name: '' },
  35. }
  36. describe('DetailsPageHeader Component', () => {
  37. it('renders with given user', () => {
  38. let wrapper = wrap({ user })
  39. expect(wrapper.find('userDropdown').prop('user').name).toBe(user.name)
  40. expect(wrapper.find('userDropdown').prop('user').email).toBe(user.email)
  41. })
  42. it('dispatches user item click', () => {
  43. let onUserItemClick = sinon.spy()
  44. let wrapper = wrap({ user, onUserItemClick })
  45. wrapper.find('userDropdown').simulate('itemClick', { value: '', label: '' })
  46. expect(onUserItemClick.called).toBe(true)
  47. })
  48. })