import React from 'react' ; import { render } from '@testing-library/react' ; import { githubAuthApiRef } from '@backstage/core-plugin-api' ; import { ApiProvider , ApiRegistry , ConfigReader } from '@backstage/core-app-api' ; import { rest } from 'msw' ; import { setupRequestMockHandlers , wrapInTestApp } from '@backstage/test-utils' ; import { setupServer } from 'msw/node' ; import { contributorsResponseMock , entityMock } from '../../../mocks/mocks' ; import { ThemeProvider } from '@material-ui/core' ; import { lightTheme } from '@backstage/theme' ; import { ContributorsCard } from '..' ; import { EntityProvider } from '@backstage/plugin-catalog-react' ; import { scmIntegrationsApiRef , ScmIntegrationsApi } from '@backstage/integration-react' ; import { defaultIntegrationsConfig , } from '../../../mocks/scmIntegrationsApiMock' ; const mockGithubAuth = { getAccessToken : async ( _ ) => 'test-token' , } ; const apis = ApiRegistry . from ( [ [ githubAuthApiRef , mockGithubAuth ] , [ scmIntegrationsApiRef , ScmIntegrationsApi . fromConfig ( ConfigReader . fromConfigs ( [ { context : 'unit-test' , data : defaultIntegrationsConfig , } , ] ) ) , ] , ] ) ; describe ( 'ContributorsCard' , ( ) => { const worker = setupServer ( ) ; setupRequestMockHandlers ( worker ) ; beforeEach ( ( ) => { worker . use ( rest . get ( 'https://api.github.com/repos/mcalus3/backstage/contributors?per_page=10' , ( _ , res , ctx ) => res ( ctx . json ( contributorsResponseMock ) ) ) ) ; } ) ; it ( 'should display a card with the data from the requests' , async ( ) => { const rendered = render ( wrapInTestApp ( < ApiProvider apis = { apis } > < ThemeProvider theme = { lightTheme } > < EntityProvider entity = { entityMock } > < ContributorsCard /> < /EntityProvider> < /ThemeProvider> < /ApiProvider>)); expect ( await rendered . findByText ( 'People' ) ) . toBeInTheDocument ( ) ; expect ( await rendered . getByAltText ( 'Rugvip' ) ) . toBeInTheDocument ( ) ; } ) ; } ) ;