test.jsx 2.2 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 sinon from 'sinon'
  18. import TW from '../../../utils/TestWrapper'
  19. import Panel, { TEST_ID } from '.'
  20. import type { Props, NavigationItem } from '.'
  21. const navigationItems: NavigationItem[] = [
  22. { label: 'Navigation1', value: 'navigation1' },
  23. { label: 'Navigation2', value: 'navigation2' },
  24. ]
  25. const content = 'Content'
  26. const wrap = (props: Props) => new TW(shallow(
  27. <Panel {...props} />
  28. ), TEST_ID)
  29. describe('Panel Component', () => {
  30. it('renders navigation items', () => {
  31. let wrapper = wrap({ navigationItems, content, onChange: () => { }, selectedValue: 'navigation2' })
  32. navigationItems.forEach(i => {
  33. expect(wrapper.findText(`navItem-${i.value}`)).toBe(i.label)
  34. })
  35. })
  36. it('selects the selected value', () => {
  37. let wrapper = wrap({ navigationItems, content, onChange: () => { }, selectedValue: 'navigation2' })
  38. expect(wrapper.find('navItem-navigation1').prop('selected')).toBeFalsy()
  39. expect(wrapper.find('navItem-navigation2').prop('selected')).toBe(true)
  40. })
  41. it('dispatches onChange', () => {
  42. let onChange = sinon.spy()
  43. let wrapper = wrap({ navigationItems, content, onChange, selectedValue: 'navigation2' })
  44. wrapper.find('navItem-navigation1').simulate('click')
  45. expect(onChange.called).toBe(true)
  46. })
  47. it('renders content', () => {
  48. let wrapper = wrap({ navigationItems, content, onChange: () => { }, selectedValue: 'navigation2' })
  49. expect(wrapper.findText('content')).toBe(content)
  50. })
  51. })