<commit_before>import React from 'react';
import { AddPanelPanel } from './AddPanelPanel';

describe('AddPanelPanel', () => {});<commit_msg>added test for sorting and filtering<commit_after>import React from 'react';
import { AddPanelPanel } from './AddPanelPanel';
import { PanelModel } from '../panel_model';
import { shallow } from 'enzyme';
import config from '../../../core/config';

jest.mock('app/core/store', () => ({
  get: key => {
    return null;
  },
  delete: key => {
    return null;
  },
}));

describe('AddPanelPanel', () => {
  let wrapper, dashboardMock, getPanelContainer, panel;

  beforeEach(() => {
    config.panels = [
      {
        id: 'singlestat',
        hideFromList: false,
        name: 'Singlestat',
        sort: 2,
        info: {
          logos: {
            small: '',
          },
        },
      },
      {
        id: 'hidden',
        hideFromList: true,
        name: 'Hidden',
        sort: 100,
        info: {
          logos: {
            small: '',
          },
        },
      },
      {
        id: 'graph',
        hideFromList: false,
        name: 'Graph',
        sort: 1,
        info: {
          logos: {
            small: '',
          },
        },
      },
      {
        id: 'alexander_zabbix',
        hideFromList: false,
        name: 'Zabbix',
        sort: 100,
        info: {
          logos: {
            small: '',
          },
        },
      },
      {
        id: 'piechart',
        hideFromList: false,
        name: 'Piechart',
        sort: 100,
        info: {
          logos: {
            small: '',
          },
        },
      },
    ];

    dashboardMock = { toggleRow: jest.fn() };

    getPanelContainer = jest.fn().mockReturnValue({
      getDashboard: jest.fn().mockReturnValue(dashboardMock),
      getPanelLoader: jest.fn(),
    });

    panel = new PanelModel({ collapsed: false });
    wrapper = shallow(<AddPanelPanel panel={panel} getPanelContainer={getPanelContainer} />);
  });

  it('should fetch all panels sorted with core plugins first', () => {
    //console.log(wrapper.debug());
    //console.log(wrapper.find('.add-panel__item').get(0).props.title);
    expect(wrapper.find('.add-panel__item').get(1).props.title).toBe('Singlestat');
    expect(wrapper.find('.add-panel__item').get(4).props.title).toBe('Piechart');
  });

  it('should filter', () => {
    wrapper.find('input').simulate('change', { target: { value: 'p' } });

    expect(wrapper.find('.add-panel__item').get(1).props.title).toBe('Piechart');
    expect(wrapper.find('.add-panel__item').get(0).props.title).toBe('Graph');
  });
});
{'fraction_non_alphanumeric': 0.17674062739097168, 'fraction_numerical': 0.00612088752869166, 'mean_word_length': 2.0057471264367814, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563033', 'n_tokens_mistral': 820, 'n_tokens_neox': 792, 'n_words': 145}