From 051ee2688dbd2d1250e8910468b84dc350169e3d Mon Sep 17 00:00:00 2001 From: zeshanziya Date: Tue, 5 Mar 2024 07:27:52 +0530 Subject: [PATCH] fix failing test cases Signed-off-by: zeshanziya --- .../components/VisitList/VisitList.test.tsx | 110 +++++++++--------- .../src/components/VisitList/VisitList.tsx | 3 + 2 files changed, 59 insertions(+), 54 deletions(-) diff --git a/plugins/home/src/components/VisitList/VisitList.test.tsx b/plugins/home/src/components/VisitList/VisitList.test.tsx index 990f2ef387..c82088c7b7 100644 --- a/plugins/home/src/components/VisitList/VisitList.test.tsx +++ b/plugins/home/src/components/VisitList/VisitList.test.tsx @@ -19,9 +19,16 @@ import { VisitList } from './VisitList'; import { renderInTestApp } from '@backstage/test-utils'; describe('', () => { + it('renders with mandatory parameters', async () => { + const { getByText } = await renderInTestApp( + , + ); + expect(getByText('My title')).toBeInTheDocument(); + }); + it('renders skeleton when loading is true', async () => { - const { container } = await render( - , + const { container } = await renderInTestApp( + , ); expect(container.querySelectorAll('li')).toHaveLength(8); expect(container.querySelectorAll('.MuiSkeleton-root')).toHaveLength(16); @@ -30,6 +37,7 @@ describe('', () => { it('renders specified amount of items', async () => { const { container } = await renderInTestApp( ', () => { it('renders some items hidden', async () => { const { container } = await renderInTestApp( ', () => { it('renders all items when not collapsed', async () => { const { container } = await renderInTestApp( ', () => { }); it('renders visit with time-ago', async () => { - const { container, getByText } = await render( - - - , - , + const { container, getByText } = await renderInTestApp( + , ); expect(container.querySelectorAll('li')).toHaveLength(1); expect(getByText('Explore Backstage')).toBeInTheDocument(); @@ -90,22 +98,20 @@ describe('', () => { }); it('renders visit with hits', async () => { - const { container, getByText } = await render( - - - , - , + const { container, getByText } = await renderInTestApp( + , ); expect(container.querySelectorAll('li')).toHaveLength(1); expect(getByText('Explore Backstage')).toBeInTheDocument(); @@ -113,22 +119,20 @@ describe('', () => { }); it('renders text warning about few items', async () => { - const { getByText } = await render( - - - , - , + const { getByText } = await renderInTestApp( + , ); expect( getByText('The more pages you visit, the more pages will appear here.'), @@ -136,10 +140,8 @@ describe('', () => { }); it('renders text warning about no items', async () => { - const { getByText } = await render( - - , - , + const { getByText } = await renderInTestApp( + , ); expect(getByText('There are no visits to show yet.')).toBeInTheDocument(); }); diff --git a/plugins/home/src/components/VisitList/VisitList.tsx b/plugins/home/src/components/VisitList/VisitList.tsx index 179be8fe48..7e79d5439f 100644 --- a/plugins/home/src/components/VisitList/VisitList.tsx +++ b/plugins/home/src/components/VisitList/VisitList.tsx @@ -30,6 +30,7 @@ export const VisitList = ({ numVisitsTotal = 8, collapsed = true, loading = false, + title = '', }: { detailType: ItemDetailType; visits?: Visit[]; @@ -37,6 +38,7 @@ export const VisitList = ({ numVisitsTotal?: number; collapsed?: boolean; loading?: boolean; + title?: string; }) => { let listBody: React.ReactElement = <>; if (loading) { @@ -81,6 +83,7 @@ export const VisitList = ({ return ( <> + {title &&
{title}
} {listBody}