mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
Routing: Update core tests (#92582)
* Update MegaMenu.test.tsx * Update GrafanaRoute.test.tsx * Remove unused file * Update SignupInvited.test.tsx * Remove usage of match * Update betterer
This commit is contained in:
parent
acab4c9438
commit
6abf50b0c9
@ -1283,14 +1283,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"]
|
||||
],
|
||||
"public/app/core/navigation/testRoutes.tsx:5381": [
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "2"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "3"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "4"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "5"]
|
||||
],
|
||||
"public/app/core/navigation/types.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { Router } from 'react-router-dom';
|
||||
import { TestProvider } from 'test/helpers/TestProvider';
|
||||
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
||||
import { render } from 'test/test-utils';
|
||||
|
||||
import { NavModelItem } from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
|
||||
import { MegaMenu } from './MegaMenu';
|
||||
|
||||
@ -33,16 +31,8 @@ const setup = () => {
|
||||
},
|
||||
];
|
||||
|
||||
const grafanaContext = getGrafanaContextMock();
|
||||
grafanaContext.chrome.setMegaMenuOpen(true);
|
||||
|
||||
return render(
|
||||
<TestProvider storeState={{ navBarTree }} grafanaContext={grafanaContext}>
|
||||
<Router history={locationService.getHistory()}>
|
||||
<MegaMenu onClose={() => {}} />
|
||||
</Router>
|
||||
</TestProvider>
|
||||
);
|
||||
const store = configureStore({ navBarTree });
|
||||
return render(<MegaMenu onClose={() => {}} />, { store });
|
||||
};
|
||||
|
||||
describe('MegaMenu', () => {
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { History, Location } from 'history';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { lazy, ComponentType } from 'react';
|
||||
import { match } from 'react-router-dom';
|
||||
import { TestProvider } from 'test/helpers/TestProvider';
|
||||
import { render } from 'test/test-utils';
|
||||
|
||||
import { setEchoSrv } from '@grafana/runtime';
|
||||
|
||||
@ -11,11 +9,34 @@ import { Echo } from '../services/echo/Echo';
|
||||
import { GrafanaRoute, Props } from './GrafanaRoute';
|
||||
import { GrafanaRouteComponentProps } from './types';
|
||||
|
||||
const mockLocation = {
|
||||
search: '?query=hello&test=asd',
|
||||
pathname: '',
|
||||
state: undefined,
|
||||
hash: '',
|
||||
};
|
||||
function setup(overrides: Partial<Props>) {
|
||||
const props: Props = {
|
||||
location: { search: '?query=hello&test=asd' } as Location,
|
||||
history: {} as History,
|
||||
match: {} as match,
|
||||
location: mockLocation,
|
||||
history: {
|
||||
length: 0,
|
||||
action: 'PUSH',
|
||||
location: mockLocation,
|
||||
push: jest.fn(),
|
||||
replace: jest.fn(),
|
||||
go: jest.fn(),
|
||||
goBack: jest.fn(),
|
||||
goForward: jest.fn(),
|
||||
block: jest.fn(),
|
||||
listen: jest.fn(),
|
||||
createHref: jest.fn(),
|
||||
},
|
||||
match: {
|
||||
params: {},
|
||||
isExact: false,
|
||||
path: '',
|
||||
url: '',
|
||||
},
|
||||
route: {
|
||||
path: '/',
|
||||
component: () => <div />,
|
||||
@ -23,11 +44,7 @@ function setup(overrides: Partial<Props>) {
|
||||
...overrides,
|
||||
};
|
||||
|
||||
render(
|
||||
<TestProvider>
|
||||
<GrafanaRoute {...props} />
|
||||
</TestProvider>
|
||||
);
|
||||
render(<GrafanaRoute {...props} />);
|
||||
}
|
||||
|
||||
describe('GrafanaRoute', () => {
|
||||
|
@ -1,31 +0,0 @@
|
||||
import { Link, NavLink } from 'react-router-dom';
|
||||
|
||||
import { RouterDebugger } from './RouterDebugger';
|
||||
import { RouteDescriptor } from './types';
|
||||
|
||||
export const testRoutes: RouteDescriptor[] = [
|
||||
{
|
||||
path: '/test1',
|
||||
component: () => (
|
||||
<>
|
||||
<h1>Test1</h1>
|
||||
<Link to={'/test2'}>Test2 link</Link>
|
||||
<NavLink to={'/test2'}>Test2 navlink</NavLink>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/test2',
|
||||
component: () => (
|
||||
<>
|
||||
<h1>Test2 </h1>
|
||||
<Link to={'/test1'}>Test1 link</Link>
|
||||
<NavLink to={'/test1'}>Test1 navlink</NavLink>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/router-debug',
|
||||
component: RouterDebugger,
|
||||
},
|
||||
];
|
@ -1,7 +1,6 @@
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import { KBarProvider } from 'kbar';
|
||||
import { Component } from 'react';
|
||||
import { match } from 'react-router-dom';
|
||||
import { useEffectOnce } from 'react-use';
|
||||
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
|
||||
import { render } from 'test/test-utils';
|
||||
@ -101,7 +100,7 @@ function setup(propOverrides?: Partial<Props>) {
|
||||
|
||||
const props: Props = {
|
||||
...getRouteComponentProps({
|
||||
match: { params: { slug: 'my-dash', uid: '11' } } as unknown as match,
|
||||
match: { params: { slug: 'my-dash', uid: '11' }, isExact: false, path: '', url: '' },
|
||||
route: { routeName: DashboardRoutes.Normal } as RouteDescriptor,
|
||||
}),
|
||||
navIndex: {
|
||||
@ -271,7 +270,7 @@ describe('DashboardPage', () => {
|
||||
const { rerender } = setup();
|
||||
rerender({ dashboard: getTestDashboard() });
|
||||
rerender({
|
||||
match: { params: { uid: 'new-uid' } } as unknown as match,
|
||||
match: { params: { uid: 'new-uid' }, isExact: false, path: '', url: '' },
|
||||
dashboard: getTestDashboard({ title: 'Another dashboard' }),
|
||||
});
|
||||
await waitFor(() => {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Component } from 'react';
|
||||
import { match } from 'react-router-dom';
|
||||
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
||||
|
||||
import { Dashboard } from '@grafana/schema';
|
||||
@ -75,7 +74,10 @@ function soloPanelPageScenario(description: string, scenarioFn: (ctx: ScenarioCo
|
||||
...getRouteComponentProps({
|
||||
match: {
|
||||
params: { slug: 'my-dash', uid: '11' },
|
||||
} as unknown as match,
|
||||
isExact: false,
|
||||
path: '',
|
||||
url: '',
|
||||
},
|
||||
queryParams: {
|
||||
panelId: '1',
|
||||
},
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { render, screen, waitFor, within } from '@testing-library/react';
|
||||
import { screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { match } from 'react-router-dom';
|
||||
import { TestProvider } from 'test/helpers/TestProvider';
|
||||
import { render } from 'test/test-utils';
|
||||
|
||||
import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
|
||||
|
||||
@ -40,15 +39,14 @@ async function setupTestContext({ get = defaultGet }: { get?: typeof defaultGet
|
||||
...getRouteComponentProps({
|
||||
match: {
|
||||
params: { code: 'some code' },
|
||||
} as unknown as match,
|
||||
isExact: false,
|
||||
path: '',
|
||||
url: '',
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
render(
|
||||
<TestProvider>
|
||||
<SignupInvitedPage {...props} />
|
||||
</TestProvider>
|
||||
);
|
||||
render(<SignupInvitedPage {...props} />);
|
||||
|
||||
await waitFor(() => expect(getSpy).toHaveBeenCalled());
|
||||
expect(getSpy).toHaveBeenCalledTimes(1);
|
||||
|
Loading…
Reference in New Issue
Block a user