From 89e2944e1f8578f221e87908184b5daf0eea7b9b Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 3 Jun 2021 11:03:20 +0200 Subject: [PATCH] chore: fixing tests and making the thing nice Signed-off-by: blam --- .../src/components/RadarComponent.test.tsx | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/plugins/tech-radar/src/components/RadarComponent.test.tsx b/plugins/tech-radar/src/components/RadarComponent.test.tsx index 59cababbc9..4b740597b5 100644 --- a/plugins/tech-radar/src/components/RadarComponent.test.tsx +++ b/plugins/tech-radar/src/components/RadarComponent.test.tsx @@ -24,6 +24,7 @@ import { withLogCollector } from '@backstage/test-utils'; import GetBBoxPolyfill from '../utils/polyfills/getBBox'; import RadarComponent from './RadarComponent'; +import { TechRadarLoaderResponse, techRadarApiRef, TechRadarApi } from '../api'; describe('RadarComponent', () => { beforeAll(() => { @@ -34,13 +35,30 @@ describe('RadarComponent', () => { GetBBoxPolyfill.remove(); }); + class MockClient implements TechRadarApi { + async load(): Promise { + return { + entries: [], + quadrants: [], + rings: [], + }; + } + } + + const mockClient = new MockClient(); + it('should render a progress bar', async () => { jest.useFakeTimers(); const errorApi = { post: () => {} }; const { getByTestId, queryByTestId } = render( - + { it('should call the errorApi if load fails', async () => { const errorApi = { post: jest.fn() }; - const techRadarLoadFail = () => - Promise.reject(new Error('404 Page Not Found')); + jest + .spyOn(mockClient, 'load') + .mockRejectedValue(new Error('404 Page Not Found')); const { queryByTestId } = render( - +