import React from 'react' ; import { render } from '@testing-library/react' ; import { ApiRegistry , ApiProvider , UrlPatternDiscovery , } from '@backstage/core-app-api' ; import { errorApiRef } from '@backstage/core-plugin-api' ; import { rest } from 'msw' ; import { setupRequestMockHandlers , wrapInTestApp } from '@backstage/test-utils' ; import { setupServer } from 'msw/node' ; import { ErrorsTable } from './ErrorsTable' ; import { ErrorsMock , ProjectsMock , TrendsMock , OrganisationsMock , } from '../../mock/bugsnag-mocks' ; import { bugsnagApiRef } from '../..' ; import { BugsnagClient } from '../../api/BugsnagClient' ; const postMock = jest . fn ( ) ; const errorApiMock = { post : postMock , error$ : jest . fn ( ) } ; const discoveryApi = UrlPatternDiscovery . compile ( 'http://exampleapi.com' ) ; const apis = ApiRegistry . from ( [ [ errorApiRef , errorApiMock ] , [ bugsnagApiRef , new BugsnagClient ( { discoveryApi } ) ] , ] ) ; describe ( 'BugsnagErrorsTable' , ( ) => { const worker = setupServer ( ) ; setupRequestMockHandlers ( worker ) ; beforeEach ( ( ) => jest . resetAllMocks ( ) ) ; it ( 'should render headers in a table' , async ( ) => { worker . use ( rest . get ( 'http://exampleapi.com/bugsnag/api/user/organizations' , ( _ , res , ctx ) => res ( ctx . json ( OrganisationsMock [ 0 ] ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/user/organizations/129876sdfgh/projects' , ( _ , res , ctx ) => res ( ctx . json ( ProjectsMock ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/projects/0987qwert!!/errors' , ( _ , res , ctx ) => res ( ctx . json ( ErrorsMock ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/projects/0987qwert!!/errors/123456qwerty!!/trend' , ( _ , res , ctx ) => res ( ctx . json ( TrendsMock ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/projects/0987qwert!!/errors/123456qwerty2!!/trend' , ( _ , res , ctx ) => res ( ctx . json ( TrendsMock ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/projects/0987qwert!!/errors/123456qwerty3!!/trend' , ( _ , res , ctx ) => res ( ctx . json ( TrendsMock ) ) ) , rest . get ( 'http://exampleapi.com/bugsnag/api/projects/0987qwert!!/errors/123456qwerty4!!/trend' , ( _ , res , ctx ) => res ( ctx . json ( TrendsMock ) ) ) ) ; const rendered = render ( wrapInTestApp ( < ApiProvider apis = { apis } > < ErrorsTable organisationName = { OrganisationsMock [ 0 ] . name } project = { ProjectsMock [ 0 ] } / > < /ApiProvider>)); expect ( await rendered . findByText ( 'Errors overview' ) ) . toBeInTheDocument ( ) ; expect ( await rendered . findByText ( 'SyntaxError' ) ) . toBeInTheDocument ( ) ; } ) ; } ) ;