grafana/public/app/features/dashboard/components/DashboardSettings/DashboardSettings.test.tsx
Ashley Harrison a861c10f1b
Navigation: Integrate search into topnav (#54925)
* behaviour mostly there

* slight performance improvement

* slightly nicer...

* refactor search and add it to the store

* add comments about removing old component

* remove unneeded logic

* small design tweak

* More small tweaks

* Restore top margin

* add onCloseSearch/onSelectSearchItem to useSearchQuery

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2022-09-09 11:01:31 +01:00

57 lines
1.7 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
import { NavModel, NavModelItem } from '@grafana/data';
import { setBackendSrv } from '@grafana/runtime';
import { GrafanaContext } from 'app/core/context/GrafanaContext';
import { configureStore } from 'app/store/configureStore';
import { DashboardModel } from '../../state';
import { DashboardSettings } from './DashboardSettings';
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
locationService: {
getSearchObject: jest.fn().mockResolvedValue({}),
partial: jest.fn(),
},
}));
setBackendSrv({
get: jest.fn().mockResolvedValue([]),
} as any);
describe('DashboardSettings', () => {
it('pressing escape navigates away correctly', async () => {
const dashboard = new DashboardModel(
{
title: 'Foo',
},
{
folderId: 1,
}
);
const store = configureStore();
const context = getGrafanaContextMock();
const sectionNav: NavModel = { main: { text: 'Dashboards' }, node: { text: 'Dashboards' } };
const pageNav: NavModelItem = { text: 'My cool dashboard' };
render(
<GrafanaContext.Provider value={context}>
<Provider store={store}>
<BrowserRouter>
<DashboardSettings editview="settings" dashboard={dashboard} sectionNav={sectionNav} pageNav={pageNav} />
</BrowserRouter>
</Provider>
</GrafanaContext.Provider>
);
expect(await screen.findByRole('heading', { name: 'Settings' })).toBeInTheDocument();
});
});