DashboardSettings.test.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { render, screen } from '@testing-library/react';
  2. import userEvent from '@testing-library/user-event';
  3. import React from 'react';
  4. import { Provider } from 'react-redux';
  5. import { BrowserRouter } from 'react-router-dom';
  6. import { locationService, setBackendSrv } from '@grafana/runtime';
  7. import { configureStore } from 'app/store/configureStore';
  8. import { DashboardModel } from '../../state';
  9. import { DashboardSettings } from './DashboardSettings';
  10. jest.mock('@grafana/runtime', () => ({
  11. ...jest.requireActual('@grafana/runtime'),
  12. locationService: {
  13. partial: jest.fn(),
  14. },
  15. }));
  16. setBackendSrv({
  17. get: jest.fn().mockResolvedValue([]),
  18. } as any);
  19. describe('DashboardSettings', () => {
  20. it('pressing escape navigates away correctly', async () => {
  21. jest.spyOn(locationService, 'partial');
  22. const dashboard = new DashboardModel(
  23. {
  24. title: 'Foo',
  25. },
  26. {
  27. folderId: 1,
  28. }
  29. );
  30. const store = configureStore();
  31. render(
  32. <Provider store={store}>
  33. <BrowserRouter>
  34. <DashboardSettings editview="settings" dashboard={dashboard} />
  35. </BrowserRouter>
  36. </Provider>
  37. );
  38. expect(screen.getByText('Foo / Settings')).toBeInTheDocument();
  39. await userEvent.keyboard('{Escape}');
  40. expect(locationService.partial).toHaveBeenCalledWith({ editview: null });
  41. });
  42. });