diff --git a/packages/scenes/src/components/SceneApp/SceneApp.test.tsx b/packages/scenes/src/components/SceneApp/SceneApp.test.tsx index 9f7f234bb..5235af1c2 100644 --- a/packages/scenes/src/components/SceneApp/SceneApp.test.tsx +++ b/packages/scenes/src/components/SceneApp/SceneApp.test.tsx @@ -1,8 +1,8 @@ import { NavModelItem } from '@grafana/data'; -import { locationService, PluginPage } from '@grafana/runtime'; +import { locationService, PluginPage, PluginPageProps } from '@grafana/runtime'; import { screen, render } from '@testing-library/react'; import React from 'react'; -import { renderAppInsideRouterWithStartingUrl } from '../../../utils/test/utils'; +import { renderAppInsideRouterWithStartingUrl } from '../../../utils/test/renderAppInsideRoutingWithStartingUrl'; import { SceneObject } from '../../core/types'; import { EmbeddedScene } from '../EmbeddedScene'; import { SceneFlexItem, SceneFlexLayout } from '../layout/SceneFlexLayout'; @@ -12,8 +12,12 @@ import { SceneAppPage } from './SceneAppPage'; import { SceneRouteMatch } from './types'; import { SceneReactObject } from '../SceneReactObject'; -// Mock lives in ./__mocks__/@grafana/runtime.js -jest.mock('@grafana/runtime'); +jest.mock('@grafana/runtime', () => ({ + ...jest.requireActual('@grafana/runtime'), + PluginPage: jest.fn().mockImplementation((props: PluginPageProps) => { + return
{props.children}
; + }), +})); jest.mock('../../utils/utils', () => ({ ...jest.requireActual('../../utils/utils'), useLocationServiceSafe: () => locationService, diff --git a/packages/scenes/src/components/SceneApp/__mocks__/@grafana/runtime.js b/packages/scenes/src/components/SceneApp/__mocks__/@grafana/runtime.js deleted file mode 100644 index 8e5f47ea9..000000000 --- a/packages/scenes/src/components/SceneApp/__mocks__/@grafana/runtime.js +++ /dev/null @@ -1,12 +0,0 @@ -const React = require('react'); -const runtime = jest.requireActual('@grafana/runtime'); - -runtime.PluginPage = jest.fn().mockImplementation((props) => { - return React.createElement('div', null, props.children); -}); - -runtime.getPluginImportUtils = () => ({ - getPanelPluginFromCache: jest.fn(() => pluginToLoad), -}); - -module.exports = runtime; diff --git a/packages/scenes/utils/setupTestsAfterEnv.ts b/packages/scenes/utils/setupTestsAfterEnv.ts index 0bfeaf407..84bcca27b 100644 --- a/packages/scenes/utils/setupTestsAfterEnv.ts +++ b/packages/scenes/utils/setupTestsAfterEnv.ts @@ -1,5 +1,9 @@ import '@testing-library/jest-dom'; -import { matchers } from './test'; +import { toEmitValues } from './test/toEmitValues'; +import { toEmitValuesWith } from './test/toEmitValuesWith'; -expect.extend(matchers); +expect.extend({ + toEmitValues, + toEmitValuesWith, +}); diff --git a/packages/scenes/utils/test/TestContextProvider.tsx b/packages/scenes/utils/test/TestContextProvider.tsx index f6340dd2a..cdb6b364d 100644 --- a/packages/scenes/utils/test/TestContextProvider.tsx +++ b/packages/scenes/utils/test/TestContextProvider.tsx @@ -1,7 +1,8 @@ import { locationService, LocationServiceProvider } from '@grafana/runtime'; import React, { useEffect, useState } from 'react'; import { Router } from 'react-router-dom'; -import { SceneObject, UrlSyncContextProvider } from '../../src'; +import { SceneObject } from '../../src/core/types'; +import { UrlSyncContextProvider } from '../../src/services/UrlSyncContextProvider'; const history = locationService.getHistory(); diff --git a/packages/scenes/utils/test/index.ts b/packages/scenes/utils/test/index.ts deleted file mode 100644 index 4f429aa53..000000000 --- a/packages/scenes/utils/test/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { toEmitValues } from './toEmitValues'; -import { toEmitValuesWith } from './toEmitValuesWith'; - -export const matchers = { - toEmitValues, - toEmitValuesWith, -}; diff --git a/packages/scenes/utils/test/renderAppInsideRoutingWithStartingUrl.tsx b/packages/scenes/utils/test/renderAppInsideRoutingWithStartingUrl.tsx new file mode 100644 index 000000000..17036d358 --- /dev/null +++ b/packages/scenes/utils/test/renderAppInsideRoutingWithStartingUrl.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import { locationService } from '@grafana/runtime'; +import { render } from '@testing-library/react'; +import { SceneApp } from '../../src/components/SceneApp/SceneApp'; +import { TestContextProviderBase } from './TestContextProvider'; + +export function renderAppInsideRouterWithStartingUrl(app: SceneApp, startingUrl: string) { + locationService.push(startingUrl); + + return render( + + + + ); +} diff --git a/packages/scenes/utils/test/updateUrlStateAndSyncState.tsx b/packages/scenes/utils/test/updateUrlStateAndSyncState.tsx index 411510d95..745151df5 100644 --- a/packages/scenes/utils/test/updateUrlStateAndSyncState.tsx +++ b/packages/scenes/utils/test/updateUrlStateAndSyncState.tsx @@ -1,6 +1,6 @@ import { UrlQueryMap } from '@grafana/data'; import { locationService } from '@grafana/runtime'; -import { UrlSyncManager } from '../../src'; +import { UrlSyncManager } from '../../src/services/UrlSyncManager'; export function updateUrlStateAndSyncState(searchParams: UrlQueryMap, urlManager: UrlSyncManager) { locationService.partial(searchParams); diff --git a/packages/scenes/utils/test/utils.tsx b/packages/scenes/utils/test/utils.tsx index f963c17cf..27dcab652 100644 --- a/packages/scenes/utils/test/utils.tsx +++ b/packages/scenes/utils/test/utils.tsx @@ -1,11 +1,6 @@ -import React from 'react'; -import { locationService } from '@grafana/runtime'; import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils'; import { asapScheduler, Subscription, timer, isObservable } from 'rxjs'; -import { render } from '@testing-library/react'; -import { SceneApp } from '../../src/components/SceneApp/SceneApp'; -import { SceneObject, SceneObjectState } from '../../src'; -import { TestContextProviderBase } from './TestContextProvider'; +import { SceneObject, SceneObjectState } from '../../src/core/types'; export const OBSERVABLE_TEST_TIMEOUT_IN_MS = 1000; @@ -68,16 +63,6 @@ export function expectObservable(received: unknown): jest.CustomMatcherResult | return null; } -export function renderAppInsideRouterWithStartingUrl(app: SceneApp, startingUrl: string) { - locationService.push(startingUrl); - - return render( - - - - ); -} - export function subscribeToStateUpdates(obj: SceneObject): T[] { const stateUpdates: T[] = []; obj.subscribeToState((state) => stateUpdates.push(state));