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