import React from 'react' ; import { render } from '@testing-library/react' ; import { configApiRef , githubAuthApiRef } from '@backstage/core-plugin-api' ; import { ApiRegistry , ApiProvider } from '@backstage/core-app-api' ; import { rest } from 'msw' ; import { setupRequestMockHandlers } from '@backstage/test-utils' ; import { setupServer } from 'msw/node' ; import { githubPullRequestsApiRef } from '../..' ; import { GithubPullRequestsClient } from '../../api' ; import { closedPullsRequestMock , entityMock } from '../../mocks/mocks' ; import PullRequestsStatsCard from './PullRequestsStatsCard' ; import { EntityProvider } from '@backstage/plugin-catalog-react' ; const mockGithubAuth = { getAccessToken : async ( _ ) => 'test-token' , } ; const config = { getOptionalConfigArray : ( _ ) => [ { getOptionalString : ( _s ) => undefined } , ] , } ; const apis = ApiRegistry . from ( [ [ configApiRef , config ] , [ githubAuthApiRef , mockGithubAuth ] , [ githubPullRequestsApiRef , new GithubPullRequestsClient ( ) ] , ] ) ; describe ( 'PullRequestsCard' , ( ) => { const worker = setupServer ( ) ; setupRequestMockHandlers ( worker ) ; beforeEach ( ( ) => { worker . use ( rest . get ( 'https://api.github.com/repos/RoadieHQ/backstage-plugin-argo-cd/pulls?state=closed&per_page=20&page=1' , ( _ , res , ctx ) => res ( ctx . json ( closedPullsRequestMock ) ) ) ) ; } ) ; it ( 'should display an ovreview card with the data from the requests' , async ( ) => { const rendered = render ( < ApiProvider apis = { apis } > < EntityProvider entity = { entityMock } > < PullRequestsStatsCard /> < /EntityProvider> < /ApiProvider>); expect ( await rendered . findByText ( '17 hours' ) ) . toBeInTheDocument ( ) ; expect ( await rendered . findByText ( '100%' ) ) . toBeInTheDocument ( ) ; } ) ; } ) ;