import React from 'react' ; import { act , render , RenderResult , waitFor } from '@testing-library/react' ; import { InsightsPage } from './InsightsPage' ; import { ThemeProvider } from '@material-ui/core' ; import { lightTheme } from '@backstage/theme' ; import { wrapInTestApp } from '@backstage/test-utils' ; import { EntityProvider } from '@backstage/plugin-catalog-react' ; import { githubAuthApiRef } from '@backstage/core-plugin-api' ; import { ApiProvider , ApiRegistry , GithubAuth , OAuthRequestManager , UrlPatternDiscovery , ConfigReader , } from '@backstage/core-app-api' ; import { scmIntegrationsApiRef , ScmIntegrationsApi } from '@backstage/integration-react' ; import { defaultIntegrationsConfig , } from '../../mocks/scmIntegrationsApiMock' ; const oauthRequestApi = new OAuthRequestManager ( ) ; const apis = ApiRegistry . from ( [ [ githubAuthApiRef , GithubAuth . create ( { discoveryApi : UrlPatternDiscovery . compile ( 'http://example.com/{{pluginId}}' ) , oauthRequestApi , } ) , ] , [ scmIntegrationsApiRef , ScmIntegrationsApi . fromConfig ( ConfigReader . fromConfigs ( [ { context : 'unit-test' , data : defaultIntegrationsConfig , } , ] ) ) , ] , ] ) ; describe ( 'Insights Page' , ( ) => { it ( 'should render' , async ( ) => { let renderResult ; await act ( async ( ) => { renderResult = render ( wrapInTestApp ( < ApiProvider apis = { apis } > < ThemeProvider theme = { lightTheme } > < EntityProvider entity = { { apiVersion : '1' , kind : 'a' , metadata : { name : 'Example Service' , annotations : { 'github.com/project-slug' : 'octocat/Hello-World' , 'backstage.io/managed-by-location' : 'url:https://github.com/org/repo/blob/master/catalog-info.yaml' , } , } , } } > < InsightsPage /> < /EntityProvider> < /ThemeProvider> < /ApiProvider>)); } ) ; await waitFor ( ( ) => expect ( renderResult . getByText ( 'GitHub Insights' ) ) . toBeInTheDocument ( ) ) ; } ) ; } ) ;