DashboardRow.test.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. meta: {
  11. canEdit: true,
  12. },
  13. };
  14. panel = new PanelModel({ collapsed: false });
  15. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  16. });
  17. it('Should not have collapsed class when collaped is false', () => {
  18. expect(wrapper.find('.dashboard-row')).toHaveLength(1);
  19. expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(0);
  20. });
  21. it('Should collapse after clicking title', () => {
  22. wrapper.find('.dashboard-row__title').simulate('click');
  23. expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(1);
  24. expect(dashboardMock.toggleRow.mock.calls).toHaveLength(1);
  25. });
  26. it('should have two actions as admin', () => {
  27. expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(2);
  28. });
  29. it('should not show row drag handle when cannot edit', () => {
  30. dashboardMock.meta.canEdit = false;
  31. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  32. expect(wrapper.find('.dashboard-row__drag')).toHaveLength(0);
  33. });
  34. it('should have zero actions when cannot edit', () => {
  35. dashboardMock.meta.canEdit = false;
  36. panel = new PanelModel({ collapsed: false });
  37. wrapper = shallow(<DashboardRow panel={panel} dashboard={dashboardMock} />);
  38. expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(0);
  39. });
  40. });