mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* navtree.go: update Data sources title and subtitle * DataSourceList: move add button to header * DataSourcesList: add buttons to items The action buttons are added inside `<Card.Tags>` so that they end up at the right end of the card, as it was designed. The "Build a Dashboard" button's functionality is not defined yet. * DataSourcesListHeader: add sort picker * fix css * tests: look for the updated "Add new data source" text * tests: use an async test method to verify component updates are wrapped in an act() * update e2e selector for add data source button * fix DataSourceList{,Page} tests * add comment for en dash character * simplify sorting * add link to Build a Dashboard button * fix test * test build a dashboard and explore buttons * test sorting data source elements * DataSourceAddButton: hide button when user has no permission * PageActionBar: remove unneeded '?' * DataSourcesList: hide explore button if user has no permission * DataSourcesListPage.test: make setup prop explicit * DataSourcesList: use theme.spacing * datasources: assure explore url includes appSubUrl * fix tests and add test case for missing permissions Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
105 lines
4.1 KiB
TypeScript
105 lines
4.1 KiB
TypeScript
import { render, RenderResult, screen } from '@testing-library/react';
|
||
import React from 'react';
|
||
import { Provider } from 'react-redux';
|
||
import { Router } from 'react-router-dom';
|
||
|
||
import { locationService } from '@grafana/runtime';
|
||
import { contextSrv } from 'app/core/services/context_srv';
|
||
import { getMockDataSources } from 'app/features/datasources/__mocks__';
|
||
import * as api from 'app/features/datasources/api';
|
||
import { configureStore } from 'app/store/configureStore';
|
||
|
||
import { getPluginsStateMock } from '../plugins/admin/__mocks__';
|
||
|
||
import Connections from './Connections';
|
||
import { navIndex } from './__mocks__/store.navIndex.mock';
|
||
import { ROUTE_BASE_ID, ROUTES } from './constants';
|
||
|
||
jest.mock('app/core/services/context_srv');
|
||
jest.mock('app/features/datasources/api');
|
||
|
||
const renderPage = (
|
||
path = `/${ROUTE_BASE_ID}`,
|
||
store = configureStore({ navIndex, plugins: getPluginsStateMock([]) })
|
||
): RenderResult => {
|
||
locationService.push(path);
|
||
|
||
return render(
|
||
<Provider store={store}>
|
||
<Router history={locationService.getHistory()}>
|
||
<Connections />
|
||
</Router>
|
||
</Provider>
|
||
);
|
||
};
|
||
|
||
describe('Connections', () => {
|
||
const mockDatasources = getMockDataSources(3);
|
||
|
||
beforeEach(() => {
|
||
(api.getDataSources as jest.Mock) = jest.fn().mockResolvedValue(mockDatasources);
|
||
(contextSrv.hasPermission as jest.Mock) = jest.fn().mockReturnValue(true);
|
||
});
|
||
|
||
test('shows the "Data sources" page by default', async () => {
|
||
renderPage();
|
||
|
||
expect(await screen.findByText('Datasources')).toBeVisible();
|
||
expect(await screen.findByText('Manage your existing datasource connections')).toBeVisible();
|
||
expect(await screen.findByText('Sort by A–Z')).toBeVisible();
|
||
expect(await screen.findByRole('link', { name: /add new data source/i })).toBeVisible();
|
||
expect(await screen.findByText(mockDatasources[0].name)).toBeVisible();
|
||
});
|
||
|
||
test('renders the correct tab even if accessing it with a "sub-url"', async () => {
|
||
renderPage(ROUTES.ConnectData);
|
||
|
||
expect(await screen.findByText('Connect data')).toBeVisible();
|
||
expect(await screen.findByText('Browse and create new connections')).toBeVisible();
|
||
|
||
// Should not render the "Your datasources" page
|
||
expect(screen.queryByText('Manage your existing datasource connections')).not.toBeInTheDocument();
|
||
});
|
||
|
||
test('renders the core "Connect data" page in case there is no standalone plugin page override for it', async () => {
|
||
renderPage(ROUTES.ConnectData);
|
||
|
||
// We expect to see no results and "Data sources" as a header (we only have data sources in OSS Grafana at this point)
|
||
expect(await screen.findByText('Data sources')).toBeVisible();
|
||
expect(await screen.findByText('No results matching your query were found.')).toBeVisible();
|
||
});
|
||
|
||
test('does not render anything for the "Connect data" page in case it is displayed by a standalone plugin page', async () => {
|
||
// We are overriding the navIndex to have the "Connect data" page registered by a plugin
|
||
const standalonePluginPage = {
|
||
id: 'standalone-plugin-page-/connections/connect-data',
|
||
text: 'Connect data',
|
||
subTitle: 'Browse and create new connections',
|
||
url: '/connections/connect-data',
|
||
pluginId: 'grafana-easystart-app',
|
||
};
|
||
const connections = {
|
||
...navIndex.connections,
|
||
children: navIndex.connections.children?.map((child) => {
|
||
if (child.id === 'connections-connect-data') {
|
||
return standalonePluginPage;
|
||
}
|
||
|
||
return child;
|
||
}),
|
||
};
|
||
const store = configureStore({
|
||
navIndex: { ...navIndex, connections, [standalonePluginPage.id]: standalonePluginPage },
|
||
plugins: getPluginsStateMock([]),
|
||
});
|
||
|
||
renderPage(ROUTES.ConnectData, store);
|
||
|
||
// We expect not to see the text that would be rendered by the core "Connect data" page
|
||
// (Instead we expect to see the default route "Datasources")
|
||
expect(await screen.findByText('Datasources')).toBeVisible();
|
||
expect(await screen.findByText('Manage your existing datasource connections')).toBeVisible();
|
||
expect(screen.queryByText('No results matching your query were found.')).not.toBeInTheDocument();
|
||
});
|
||
});
|