From 5d98a4263eb94a316d0ed956baaad8ea6e254865 Mon Sep 17 00:00:00 2001 From: Karan Shah Date: Wed, 2 Mar 2022 00:15:26 +0000 Subject: [PATCH] Added working tests, one of which fails because of a bug in the code that needs to be fixed Signed-off-by: Karan Shah --- plugins/airbrake/src/api/ProductionApi.test.ts | 7 +++++++ .../EntityAirbrakeWidget.test.tsx | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/airbrake/src/api/ProductionApi.test.ts b/plugins/airbrake/src/api/ProductionApi.test.ts index f09127b4c2..41aef38a27 100644 --- a/plugins/airbrake/src/api/ProductionApi.test.ts +++ b/plugins/airbrake/src/api/ProductionApi.test.ts @@ -20,6 +20,7 @@ import mockGroupsData from './mock/airbrakeGroupsApiMock.json'; import { setupServer } from 'msw/node'; import { setupRequestMockHandlers } from '@backstage/test-utils'; import { localDiscoveryApi } from './mock'; +import { NoProjectIdError } from './AirbrakeApi'; describe('The production Airbrake API', () => { const productionApi = new ProductionAirbrakeApi(localDiscoveryApi); @@ -53,4 +54,10 @@ describe('The production Airbrake API', () => { await expect(productionApi.fetchGroups('123456')).rejects.toThrow(); }); + + it('throws if project ID is empty', async () => { + await expect(productionApi.fetchGroups('')).rejects.toThrowError( + NoProjectIdError, + ); + }); }); diff --git a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx index ee14a17f9a..6211500b10 100644 --- a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx +++ b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx @@ -23,9 +23,9 @@ import { setupRequestMockHandlers, TestApiProvider, } from '@backstage/test-utils'; -import { createEntity } from '../../api'; import { airbrakeApiRef, + createEntity, localDiscoveryApi, MockAirbrakeApi, ProductionAirbrakeApi, @@ -52,15 +52,23 @@ describe('EntityAirbrakeContent', () => { } }); - it('states that the annotation is missing if no project ID annotation is provided', async () => { + it('states that the annotation is missing if no project ID annotation is provided but does not error', async () => { + const mockErrorApi = new MockErrorApi({ collect: true }); + const widget = await renderInTestApp( - + , ); await expect( widget.findByText('Missing Annotation'), ).resolves.toBeInTheDocument(); + expect(mockErrorApi.getErrors().length).toBe(0); }); it('states that an error occurred if the API call fails', async () => {