TabView.test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import TabView from '../components/Tabs/TabView';
  3. import { shallow, mount } from 'enzyme';
  4. import { Tab, TabContent } from '../components/Tabs/style';
  5. describe('<TabView />', () => {
  6. let props;
  7. let mountedTab;
  8. const tabView = () => {
  9. if (!mountedTab) {
  10. return mount(<TabView {...props} />);
  11. }
  12. return mountedTab;
  13. };
  14. beforeEach(() => {
  15. props = {
  16. data: undefined
  17. };
  18. mountedTab = undefined;
  19. });
  20. it('Default active on the first tab and not active on the rest', () => {
  21. const tab = tabView().find(Tab);
  22. expect(tab.at(0).prop('isActive')).toBe(true);
  23. expect(tab.at(1).prop('isActive')).toBe(false);
  24. expect(tabView().find('TabGroup').length).toBe(1);
  25. });
  26. it('Default active content is correct', () => {
  27. const data = {
  28. tabs: ['one', 'two', 'thre'],
  29. content: ['1', '2', '3']
  30. };
  31. props = { data };
  32. const tabContent = tabView().find(TabContent);
  33. expect(tabContent.text()).toBe('1');
  34. });
  35. it('Click on the inactive tab activate the tab', () => {
  36. const data = {
  37. tabs: ['one', 'two', 'thre'],
  38. content: ['1', '2', '3']
  39. };
  40. props = {
  41. data
  42. };
  43. const tabViewWindow = tabView();
  44. const tab1 = tabViewWindow.find(Tab).at(1);
  45. const tab1Activated = tab1.simulate('click');
  46. expect(tab1Activated.prop('isActive')).toBe(true);
  47. const tabContent = tabViewWindow.find(TabContent);
  48. expect(tabContent.render().text()).toBe('2');
  49. });
  50. });