test.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 sinon from 'sinon'
  18. import TW from '../../../utils/TestWrapper'
  19. import ProjectListItem from '.'
  20. import type { Project } from '../../../types/Project'
  21. type Props = {
  22. item: Project,
  23. onClick: () => void,
  24. getMembers: (projectId: string) => number,
  25. isCurrentProject: (projectId: string) => boolean,
  26. onSwitchProjectClick: (projectId: string) => void,
  27. }
  28. const wrap = (props: Props) => new TW(shallow(
  29. <ProjectListItem {...props} />
  30. ), 'plItem')
  31. const item: Project = {
  32. id: 'p_id',
  33. name: 'p_name',
  34. description: 'p_description',
  35. enabled: true,
  36. }
  37. describe('ProjectListItem Component', () => {
  38. it('renders with correct data', () => {
  39. let wrapper = wrap({
  40. item,
  41. onClick: () => { },
  42. getMembers: () => 3,
  43. isCurrentProject: () => true,
  44. onSwitchProjectClick: () => { },
  45. })
  46. expect(wrapper.findText('name')).toBe(item.name)
  47. expect(wrapper.findText('description')).toBe(item.description)
  48. expect(wrapper.findText('members')).toBe('3')
  49. expect(wrapper.findText('enabled')).toBe('Yes')
  50. expect(wrapper.findText('currentButton', false, true)).toBe('Current')
  51. })
  52. it('dispatches click', () => {
  53. let onClick = sinon.spy()
  54. let wrapper = wrap({
  55. item,
  56. onClick,
  57. getMembers: () => 3,
  58. isCurrentProject: () => true,
  59. onSwitchProjectClick: () => { },
  60. })
  61. wrapper.find('content').click()
  62. expect(onClick.calledOnce).toBe(true)
  63. })
  64. it('dispatches switch project click', () => {
  65. let onSwitchProjectClick = sinon.spy()
  66. let wrapper = wrap({
  67. item,
  68. onClick: () => { },
  69. getMembers: () => 3,
  70. isCurrentProject: () => true,
  71. onSwitchProjectClick,
  72. })
  73. wrapper.find('currentButton').click()
  74. expect(onSwitchProjectClick.calledOnce).toBe(true)
  75. expect(onSwitchProjectClick.args[0][0]).toBe('p_id')
  76. })
  77. })