DashboardRow.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { DashboardRow } from './DashboardRow';
  4. import { PanelModel } from '../../state/PanelModel';
  5. describe('DashboardRow', () => {
  6. let wrapper, panel, dashboardMock;
  7. beforeEach(() => {
  8. dashboardMock = {
  9. toggleRow: jest.fn(),
  10. on: jest.fn(),
  11. meta: {
  12. canEdit: true,
  13. },
  14. };
  15. panel = new PanelModel({ collapsed: false });
  16. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  17. });
  18. it('Should not have collapsed class when collaped is false', () => {
  19. expect(wrapper.find('.dashboard-row')).toHaveLength(1);
  20. expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(0);
  21. });
  22. it('Should collapse after clicking title', () => {
  23. wrapper.find('.dashboard-row__title').simulate('click');
  24. expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(1);
  25. expect(dashboardMock.toggleRow.mock.calls).toHaveLength(1);
  26. });
  27. it('should have two actions as admin', () => {
  28. expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(2);
  29. });
  30. it('should not show row drag handle when cannot edit', () => {
  31. dashboardMock.meta.canEdit = false;
  32. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  33. expect(wrapper.find('.dashboard-row__drag')).toHaveLength(0);
  34. });
  35. it('should have zero actions when cannot edit', () => {
  36. dashboardMock.meta.canEdit = false;
  37. panel = new PanelModel({ collapsed: false });
  38. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  39. expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(0);
  40. });
  41. });