Skip to content

Commit

Permalink
Fix and update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adhityamamallan committed Dec 30, 2024
1 parent 83dec8e commit 8480166
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jest.mock(
workflows: (props) => <MockedTabContent {...props} tab="workflows" />,
metadata: (props) => <MockedTabContent {...props} tab="metadata" />,
settings: (props) => <MockedTabContent {...props} tab="settings" />,
archival: (props) => <MockedTabContent {...props} tab="archival" />,
}) as const satisfies DomainPageTabsContentConfig
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jest.mock(
settings: () => ({
message: 'settings error',
}),
archival: () => ({
message: 'archival error',
}),
}) as const satisfies DomainPageTabsErrorConfig
);

Expand Down
Original file line number Diff line number Diff line change
@@ -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(() => <div>Mock archival header</div>)
);

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(
<Suspense>
<DomainWorkflowsArchival domain="mock-domain" cluster="mock-cluster" />
</Suspense>,
{
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,
}),
},
],
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div>Archival disabled</div>;
}
Expand Down

0 comments on commit 8480166

Please sign in to comment.