utils.test.ts 1.1 KB

1234567891011121314151617181920212223242526
  1. import { PanelPluginMeta, escapeStringForRegex } from '@grafana/data';
  2. import { filterPluginList } from './util';
  3. describe('panel state utils', () => {
  4. it('should include timeseries in a graph query', async () => {
  5. const pluginsList: PanelPluginMeta[] = [
  6. { id: 'graph', name: 'Graph (old)' } as any,
  7. { id: 'timeseries', name: 'Graph (old)' },
  8. { id: 'timeline', name: 'Timeline' },
  9. ];
  10. const found = filterPluginList(pluginsList, escapeStringForRegex('gra'), { id: 'xyz' } as any);
  11. expect(found.map((v) => v.id)).toEqual(['graph', 'timeseries']);
  12. });
  13. it('should handle escaped regex characters in the search query (e.g. -)', async () => {
  14. const pluginsList: PanelPluginMeta[] = [
  15. { id: 'graph', name: 'Graph (old)' } as any,
  16. { id: 'timeseries', name: 'Graph (old)' },
  17. { id: 'timeline', name: 'Timeline' },
  18. { id: 'panelwithdashes', name: 'Panel-With-Dashes' },
  19. ];
  20. const found = filterPluginList(pluginsList, escapeStringForRegex('panel-'), { id: 'xyz' } as any);
  21. expect(found.map((v) => v.id)).toEqual(['panelwithdashes']);
  22. });
  23. });