DashboardRow.test.tsx 1.6 KB

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