import React from 'react' ; import { render } from '@testing-library/react' ; import { configApiRef , errorApiRef , identityApiRef , } from '@backstage/core-plugin-api' ; import { ApiRegistry , ApiProvider } from '@backstage/core-app-api' ; import { rest } from 'msw' ; import { setupRequestMockHandlers } from '@backstage/test-utils' ; import { EntityProvider } from '@backstage/plugin-catalog-react' ; import { setupServer } from 'msw/node' ; import { credentialsResponseMock , entityMock , lambdaResponseMock , } from '../../mocks/mocks' ; import { awsLambdaApiRef , AWSLambdaOverviewWidget } from '../..' ; import { AwsLambdaClient } from '../../api' ; const errorApiMock = { post : jest . fn ( ) , error$ : jest . fn ( ) } ; const identityApiMock = { getIdToken : jest . fn ( ) , error$ : jest . fn ( ) } ; const config = { getString : ( _ ) => 'https://test-url' , } ; const apis = ApiRegistry . from ( [ [ errorApiRef , errorApiMock ] , [ configApiRef , config ] , [ awsLambdaApiRef , new AwsLambdaClient ( ) ] , [ identityApiRef , identityApiMock ] , ] ) ; describe ( 'AWSLambdaCard' , ( ) => { const worker = setupServer ( ) ; setupRequestMockHandlers ( worker ) ; beforeEach ( ( ) => { worker . use ( rest . get ( 'https://test-url/api/aws/credentials' , ( _ , res , ctx ) => res ( ctx . json ( credentialsResponseMock ) ) ) , rest . get ( 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/openfraksl-dev-graphql' , ( _ , res , ctx ) => res ( ctx . json ( lambdaResponseMock ) ) ) ) ; } ) ; it ( 'should display an ovreview card with the data from the requests' , async ( ) => { const rendered = render ( < ApiProvider apis = { apis } > < EntityProvider entity = { entityMock } > < AWSLambdaOverviewWidget /> < /EntityProvider> < /ApiProvider>); expect ( await rendered . findByText ( lambdaResponseMock . Configuration . FunctionName ) ) . toBeInTheDocument ( ) ; expect ( await rendered . findByText ( lambdaResponseMock . Configuration . State ) ) . toBeInTheDocument ( ) ; expect ( await rendered . findByText ( lambdaResponseMock . Configuration . LastUpdateStatus ) ) . toBeInTheDocument ( ) ; } ) ; } ) ;