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