AddPanelPanel.test.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react';
  2. import { AddPanelPanel } from './../dashgrid/AddPanelPanel';
  3. import { PanelModel } from '../panel_model';
  4. import { shallow } from 'enzyme';
  5. import config from '../../../core/config';
  6. import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks';
  7. jest.mock('app/core/store', () => ({
  8. get: key => {
  9. return null;
  10. },
  11. delete: key => {
  12. return null;
  13. },
  14. }));
  15. describe('AddPanelPanel', () => {
  16. let wrapper, dashboardMock, panel;
  17. beforeEach(() => {
  18. config.panels = [
  19. getPanelPlugin({ id: 'singlestat', sort: 2 }),
  20. getPanelPlugin({ id: 'hidden', sort: 100, hideFromList: true }),
  21. getPanelPlugin({ id: 'graph', sort: 1 }),
  22. getPanelPlugin({ id: 'alexander_zabbix', sort: 100 }),
  23. getPanelPlugin({ id: 'piechart', sort: 100 }),
  24. ];
  25. dashboardMock = { toggleRow: jest.fn() };
  26. panel = new PanelModel({ collapsed: false });
  27. wrapper = shallow(<AddPanelPanel panel={panel} dashboard={dashboardMock} />);
  28. });
  29. it('should fetch all panels sorted with core plugins first', () => {
  30. expect(wrapper.find('.add-panel__item').get(1).props.title).toBe('singlestat');
  31. expect(wrapper.find('.add-panel__item').get(4).props.title).toBe('piechart');
  32. });
  33. it('should filter', () => {
  34. wrapper.find('input').simulate('change', { target: { value: 'p' } });
  35. expect(wrapper.find('.add-panel__item').get(1).props.title).toBe('piechart');
  36. expect(wrapper.find('.add-panel__item').get(0).props.title).toBe('graph');
  37. });
  38. });