mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Connections: Show only data source plugins on Connect Data page (#60523)
show only data source plugins on connect data page We intended to show only data source plugins on this page, but this filter was missing until now.
This commit is contained in:
@@ -2,11 +2,11 @@ import { fireEvent, render, RenderResult, screen } from '@testing-library/react'
|
||||
import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { PluginType } from '@grafana/data';
|
||||
import { getCatalogPluginMock, getPluginsStateMock } from 'app/features/plugins/admin/__mocks__';
|
||||
import { CatalogPlugin } from 'app/features/plugins/admin/types';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
|
||||
import { getCatalogPluginMock, getPluginsStateMock } from '../../../plugins/admin/__mocks__';
|
||||
|
||||
import { ConnectData } from './ConnectData';
|
||||
|
||||
jest.mock('app/features/datasources/api');
|
||||
@@ -22,6 +22,12 @@ const renderPage = (plugins: CatalogPlugin[] = []): RenderResult => {
|
||||
);
|
||||
};
|
||||
|
||||
const mockCatalogDataSourcePlugin = getCatalogPluginMock({
|
||||
type: PluginType.datasource,
|
||||
name: 'Sample data source',
|
||||
id: 'sample-data-source',
|
||||
});
|
||||
|
||||
describe('Connect Data', () => {
|
||||
test('renders no results if the plugins list is empty', async () => {
|
||||
renderPage();
|
||||
@@ -29,20 +35,26 @@ describe('Connect Data', () => {
|
||||
expect(screen.queryByText('No results matching your query were found.')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders card if plugins list is populated', async () => {
|
||||
test('renders no results if there is no data source plugin in the list', async () => {
|
||||
renderPage([getCatalogPluginMock()]);
|
||||
|
||||
expect(await screen.findByText('Zabbix')).toBeVisible();
|
||||
expect(screen.queryByText('No results matching your query were found.')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders only data source plugins when list is populated', async () => {
|
||||
renderPage([getCatalogPluginMock(), mockCatalogDataSourcePlugin]);
|
||||
|
||||
expect(await screen.findByText('Sample data source')).toBeVisible();
|
||||
});
|
||||
|
||||
test('renders card if search term matches', async () => {
|
||||
renderPage([getCatalogPluginMock()]);
|
||||
renderPage([getCatalogPluginMock(), mockCatalogDataSourcePlugin]);
|
||||
const searchField = await screen.findByRole('textbox');
|
||||
|
||||
fireEvent.change(searchField, { target: { value: 'abbi' } });
|
||||
expect(await screen.findByText('Zabbix')).toBeVisible();
|
||||
fireEvent.change(searchField, { target: { value: 'ampl' } });
|
||||
expect(await screen.findByText('Sample data source')).toBeVisible();
|
||||
|
||||
fireEvent.change(searchField, { target: { value: 'rabbit' } });
|
||||
fireEvent.change(searchField, { target: { value: 'cramp' } });
|
||||
expect(screen.queryByText('No results matching your query were found.')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { css } from '@emotion/css';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { PluginType } from '@grafana/data';
|
||||
import { useStyles2, LoadingPlaceholder } from '@grafana/ui';
|
||||
import { useGetAllWithFilters } from 'app/features/plugins/admin/state/hooks';
|
||||
|
||||
@@ -25,7 +26,11 @@ export function ConnectData() {
|
||||
setSearchTerm(e.currentTarget.value.toLowerCase());
|
||||
};
|
||||
|
||||
const { isLoading, error, plugins } = useGetAllWithFilters({ query: searchTerm, filterBy: '' });
|
||||
const { isLoading, error, plugins } = useGetAllWithFilters({
|
||||
query: searchTerm,
|
||||
filterBy: '',
|
||||
filterByType: PluginType.datasource,
|
||||
});
|
||||
|
||||
const cardGridItems = useMemo(
|
||||
() =>
|
||||
|
||||
Reference in New Issue
Block a user