From 84801666dc94ac7a7866a6adafb924240c069b2e Mon Sep 17 00:00:00 2001 From: Adhitya Mamallan Date: Mon, 30 Dec 2024 15:18:14 +0000 Subject: [PATCH] Fix and update unit tests --- .../__tests__/domain-page-content.test.tsx | 1 + .../__tests__/domain-page-tabs-error.test.tsx | 3 + .../domain-workflows-archival.test.tsx | 86 +++++++++++++++++++ .../domain-workflows-archival.tsx | 5 +- 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/views/domain-workflows-archival/__tests__/domain-workflows-archival.test.tsx diff --git a/src/views/domain-page/domain-page-content/__tests__/domain-page-content.test.tsx b/src/views/domain-page/domain-page-content/__tests__/domain-page-content.test.tsx index 8ec9269ad..b1120e748 100644 --- a/src/views/domain-page/domain-page-content/__tests__/domain-page-content.test.tsx +++ b/src/views/domain-page/domain-page-content/__tests__/domain-page-content.test.tsx @@ -32,6 +32,7 @@ jest.mock( workflows: (props) => , metadata: (props) => , settings: (props) => , + archival: (props) => , }) as const satisfies DomainPageTabsContentConfig ); diff --git a/src/views/domain-page/domain-page-tabs-error/__tests__/domain-page-tabs-error.test.tsx b/src/views/domain-page/domain-page-tabs-error/__tests__/domain-page-tabs-error.test.tsx index 3f60efb55..8ad24c75f 100644 --- a/src/views/domain-page/domain-page-tabs-error/__tests__/domain-page-tabs-error.test.tsx +++ b/src/views/domain-page/domain-page-tabs-error/__tests__/domain-page-tabs-error.test.tsx @@ -33,6 +33,9 @@ jest.mock( settings: () => ({ message: 'settings error', }), + archival: () => ({ + message: 'archival error', + }), }) as const satisfies DomainPageTabsErrorConfig ); diff --git a/src/views/domain-workflows-archival/__tests__/domain-workflows-archival.test.tsx b/src/views/domain-workflows-archival/__tests__/domain-workflows-archival.test.tsx new file mode 100644 index 000000000..7ad8e46d0 --- /dev/null +++ b/src/views/domain-workflows-archival/__tests__/domain-workflows-archival.test.tsx @@ -0,0 +1,86 @@ +import { Suspense } from 'react'; + +import { HttpResponse } from 'msw'; + +import { render, screen, act } from '@/test-utils/rtl'; + +import { type DescribeDomainResponse } from '@/route-handlers/describe-domain/describe-domain.types'; +import { mockDomainInfo } from '@/views/domain-page/__fixtures__/domain-info'; + +import DomainWorkflowsArchival from '../domain-workflows-archival'; + +jest.mock( + '../domain-workflows-archival-header/domain-workflows-archival-header', + () => jest.fn(() =>
Mock archival header
) +); + +describe(DomainWorkflowsArchival.name, () => { + it('renders without error and shows archival disabled page', async () => { + await setup({}); + + expect(await screen.findByText('Archival disabled')).toBeInTheDocument(); + }); + + it('renders without error and shows archival content', async () => { + await setup({ isArchivalEnabled: true }); + + expect(await screen.findByText('Mock archival header')).toBeInTheDocument(); + }); + + it('does not render if the initial call fails', async () => { + let renderErrorMessage; + try { + await act(async () => { + await setup({ isError: true }); + }); + } catch (error) { + if (error instanceof Error) { + renderErrorMessage = error.message; + } + } + + expect(renderErrorMessage).toEqual('Failed to fetch domain information'); + }); +}); + +async function setup({ + isArchivalEnabled, + isError, +}: { + isArchivalEnabled?: boolean; + isError?: boolean; +}) { + render( + + + , + { + endpointsMocks: [ + { + path: '/api/domains/:domain/:cluster', + httpMethod: 'GET', + ...(isError + ? { + httpResolver: () => { + return HttpResponse.json( + { message: 'Failed to fetch domain information' }, + { status: 500 } + ); + }, + } + : { + jsonResponse: { + ...mockDomainInfo, + ...(isArchivalEnabled + ? { + historyArchivalStatus: 'ARCHIVAL_STATUS_ENABLED', + visibilityArchivalStatus: 'ARCHIVAL_STATUS_ENABLED', + } + : {}), + } satisfies DescribeDomainResponse, + }), + }, + ], + } + ); +} diff --git a/src/views/domain-workflows-archival/domain-workflows-archival.tsx b/src/views/domain-workflows-archival/domain-workflows-archival.tsx index 1f6c00961..14be71981 100644 --- a/src/views/domain-workflows-archival/domain-workflows-archival.tsx +++ b/src/views/domain-workflows-archival/domain-workflows-archival.tsx @@ -22,7 +22,10 @@ export default function DomainWorkflowsArchival( ), }); - if (!historyArchivalStatus || !visibilityArchivalStatus) { + if ( + historyArchivalStatus !== 'ARCHIVAL_STATUS_ENABLED' || + visibilityArchivalStatus !== 'ARCHIVAL_STATUS_ENABLED' + ) { // TODO: archival landing page return
Archival disabled
; }