Skip to content

Commit

Permalink
fixed basis test CT-1843 🐰
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-fintlabs committed Jan 9, 2025
1 parent 24fbf5d commit a3ef850
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 94 deletions.
85 changes: 41 additions & 44 deletions app/routes/basistest/CacheStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { BodyShort, Label, Table, Tooltip } from '@navikt/ds-react';
import { BodyShort, Table, Tooltip } from '@navikt/ds-react';
import { CheckmarkCircleIcon, XMarkOctagonIcon } from '@navikt/aksel-icons';
import { formatDate } from '~/utils/dateUtils';
import { formatTimeOnly } from '~/utils/dateUtils';
import { IResourceResult } from '~/types/BasicTest';

interface TestResultsTableProps {
Expand All @@ -18,49 +18,46 @@ function CacheStatusTable({ logResults }: TestResultsTableProps) {
}

return (
<>
<Label>Cache status</Label>
<Table size="small">
<Table.Header>
<Table.Row>
<Table.HeaderCell scope="col">Status</Table.HeaderCell>
<Table.HeaderCell scope="col">Ressurs</Table.HeaderCell>
<Table.HeaderCell scope="col">Sist oppdatert</Table.HeaderCell>
<Table.HeaderCell scope="col">Cache størrelse</Table.HeaderCell>
<Table.HeaderCell scope="col">Melding</Table.HeaderCell>
<Table size="small">
<Table.Header>
<Table.Row>
<Table.HeaderCell scope="col">Status</Table.HeaderCell>
<Table.HeaderCell scope="col">Ressurs</Table.HeaderCell>
<Table.HeaderCell scope="col">Sist oppdatert</Table.HeaderCell>
<Table.HeaderCell scope="col">Cache størrelse</Table.HeaderCell>
<Table.HeaderCell scope="col">Melding</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{logResults.map((result, index) => (
<Table.Row key={index}>
<Table.DataCell>
<Tooltip content={result.status}>
{result.status === 'OK' ? (
<CheckmarkCircleIcon
title="OK"
fontSize="1.5rem"
className="text-green-600"
/>
) : (
<XMarkOctagonIcon
title="Error"
fontSize="1.5rem"
className="navds-error-message"
/>
)}
</Tooltip>
</Table.DataCell>
<Table.DataCell>{result.resource}</Table.DataCell>
<Table.DataCell>
{result.lastUpdated <= 0 ? '' : formatTimeOnly(result.lastUpdated)}
</Table.DataCell>
<Table.DataCell>{result.size <= 0 ? '' : result.size}</Table.DataCell>
<Table.DataCell>{result.message || 'Ingen melding'}</Table.DataCell>
</Table.Row>
</Table.Header>
<Table.Body>
{logResults.map((result, index) => (
<Table.Row key={index}>
<Table.DataCell>
<Tooltip content={result.status}>
{result.status === 'OK' ? (
<CheckmarkCircleIcon
title="OK"
fontSize="1.5rem"
className="text-green-600"
/>
) : (
<XMarkOctagonIcon
title="Error"
fontSize="1.5rem"
className="navds-error-message"
/>
)}
</Tooltip>
</Table.DataCell>
<Table.DataCell>{result.resource}</Table.DataCell>
<Table.DataCell>
{result.lastUpdated <= 0 ? '' : formatDate(result.lastUpdated)}
</Table.DataCell>
<Table.DataCell>{result.size <= 0 ? '' : result.size}</Table.DataCell>
<Table.DataCell>{result.message || 'Ingen melding'}</Table.DataCell>
</Table.Row>
))}
</Table.Body>
</Table>
</>
))}
</Table.Body>
</Table>
);
}

Expand Down
16 changes: 13 additions & 3 deletions app/routes/basistest/HealthTestResultsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react';
import { Table } from '@navikt/ds-react';
import { formatDate } from '~/utils/dateUtils';
import { formatTimeOnly } from '~/utils/dateUtils';
import { IHealthData } from '~/types/BasicTest';

interface TestResultsTableProps {
logResults: IHealthData[] | null;
}

// Translation mapping
const statusTranslations: { [key: string]: string } = {
SENT_FROM_CONSUMER_TO_PROVIDER: 'Sendt fra konsumer til provider',
RECEIVED_IN_PROVIDER_FROM_CONSUMER: 'Mottatt i provider fra konsumer',
APPLICATION_HEALTHY: 'Adapter er ok',
RECEIVED_IN_CONSUMER_FROM_PROVIDER: 'Mottatt i consumer fra provider',
};

function HealthTestResultsTable({ logResults }: TestResultsTableProps) {
return (
<Table size="small">
Expand All @@ -20,9 +28,11 @@ function HealthTestResultsTable({ logResults }: TestResultsTableProps) {
<Table.Body>
{logResults?.map((result, index) => (
<Table.Row key={index}>
<Table.DataCell>{result.status}</Table.DataCell>
<Table.DataCell>
{statusTranslations[result.status] || result.status}
</Table.DataCell>
<Table.DataCell>{result.component}</Table.DataCell>
<Table.DataCell>{formatDate(result.timestamp)}</Table.DataCell>
<Table.DataCell>{formatTimeOnly(result.timestamp)}</Table.DataCell>
</Table.Row>
))}
</Table.Body>
Expand Down
106 changes: 59 additions & 47 deletions app/routes/basistest/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ActionFunctionArgs, LoaderFunction, MetaFunction } from '@remix-ru
import Breadcrumbs from '~/components/shared/breadcrumbs';
import InternalPageHeader from '~/components/shared/InternalPageHeader';
import { TerminalIcon } from '@navikt/aksel-icons';
import { Alert, Box, Loader, VStack } from '@navikt/ds-react';
import { Alert, BodyShort, Box, Heading, Loader, VStack } from '@navikt/ds-react';
import { getSelectedOrganization } from '~/utils/selectedOrganization';
import ComponentApi from '~/api/ComponentApi';
import { useFetcher, useLoaderData } from '@remix-run/react';
Expand All @@ -15,6 +15,7 @@ import HealthTestResultsTable from '~/routes/basistest/HealthTestResultsTable';
import CacheStatusTable from '~/routes/basistest/CacheStatusTable';
import logger from '~/utils/logger';
import { IFetcherResponseData } from '~/types/FetcherResponseData';
import React from 'react';

export const meta: MetaFunction = () => {
return [{ title: 'Basis Test' }, { name: 'description', content: 'Run Basis Test' }];
Expand All @@ -37,10 +38,15 @@ export const loader: LoaderFunction = async ({ request }) => {
);
};

type ExtendedFetcherResponseData = IFetcherResponseData & {
clientName: string;
testUrl: string;
};

export default function Index() {
const breadcrumbs = [{ name: 'Basistest', link: '/basistest' }];
const fetcher = useFetcher();
const actionData = fetcher.data as IFetcherResponseData;
const actionData = fetcher.data as ExtendedFetcherResponseData;

const { components, clients } = useLoaderData<{
components: IComponent[];
Expand All @@ -60,63 +66,63 @@ export default function Index() {
<Breadcrumbs breadcrumbs={breadcrumbs} />
<InternalPageHeader title={'Basistest'} icon={TerminalIcon} helpText="basistest" />
<VStack gap={'6'}>
<Alert variant="warning">
Advarsel: Passordet til klienten du kjører testen på, vil bli nullstilt under
testkjøringen. Det anbefales derfor å bruke en dedikert klient for testing.
</Alert>
{fetcher.state !== 'submitting' && !actionData && (
<Alert variant="warning">
Advarsel: Passordet til klienten du kjører testen på, vil bli nullstilt
under testkjøringen. Det anbefales derfor å bruke en dedikert klient for
testing.
</Alert>
)}
<Box className="w-full" padding="6" borderRadius="large" shadow="small">
<BasicTestAddForm
components={components}
clients={clients}
onSearchSubmit={handleSearchSubmit}
/>
</Box>
{fetcher.state === 'submitting' && (
<Box className="w-full" padding="6" borderRadius="large" shadow="small">

<Box className="w-full" padding="6" borderRadius="large" shadow="small">
{fetcher.state === 'submitting' && (
<Loader size="large" title="Laster inn data..." />
</Box>
)}
{fetcher.state !== 'submitting' && (
<>
{actionData && (
<>
{actionData.message && (
<Box
className="w-full"
padding="6"
borderRadius="large"
shadow="small">
<Alert variant="info">{actionData.message}</Alert>
</Box>
)}

{actionData.data.healthData.healthData && (
<Box
className="w-full"
padding="6"
borderRadius="large"
shadow="small">
)}

{fetcher.state !== 'submitting' && (
<>
{actionData && (
<>
{actionData.message && (
<Box className={'pb-10'}>
<Alert variant="info">
<BodyShort>
{actionData.message}: {actionData.testUrl}
</BodyShort>
<BodyShort>
Bruker: {actionData.clientName}
</BodyShort>
</Alert>
</Box>
)}

<Heading size={'medium'}>Resultat av helsetest: </Heading>
{actionData.data.healthData.healthData && (
<HealthTestResultsTable
logResults={actionData.data.healthData.healthData}
/>
</Box>
)}

{actionData.data.cacheData.resourceResults && (
<Box
className="w-full"
padding="6"
borderRadius="large"
shadow="small">
)}

<Heading size={'medium'} className={'pt-5'}>
Cache status:{' '}
</Heading>
{actionData.data.cacheData.resourceResults && (
<CacheStatusTable
logResults={actionData.data.cacheData.resourceResults}
/>
</Box>
)}
</>
)}
</>
)}
)}
</>
)}
</>
)}
</Box>
</VStack>
</>
);
Expand All @@ -128,9 +134,13 @@ export async function action({ request }: ActionFunctionArgs) {
const endpoint = formData.get('endpoint') as string;
const clientName = formData.get('clientName') as string;
const orgName = await getSelectedOrganization(request);
const message = 'Testet med: ' + baseUrl + endpoint + ' ' + clientName + ' ' + orgName;

logger.debug(`BASIS TEST baseurl/endpoint clientName orgname: ${message}`);
const message = 'Testet av: ';

//Test av: https://beta.felleskomponent.no/utdanning/elev
// Bruker: basistest@client.fintlabs.no

logger.debug(`BASIS TEST baseurl/endpoint clientName orgname: ${baseUrl}`);
const cacheData = await BasicTestApi.runTest(orgName, baseUrl, endpoint, clientName);
const healthData = await BasicTestApi.runHealthTest(orgName, baseUrl, endpoint, clientName);

Expand All @@ -139,6 +149,8 @@ export async function action({ request }: ActionFunctionArgs) {

return {
message: message,
clientName: clientName,
testUrl: baseUrl + endpoint,
variant: 'info',
data: {
healthData: healthData.data || [],
Expand Down
6 changes: 6 additions & 0 deletions app/utils/dateUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ export const formatDate = (timestamp: number): string => {
const time = date.toLocaleTimeString('no-NO');
return `${d}.${m}.${y} ${time}`;
};

export const formatTimeOnly = (timestamp: number): string => {
const date = new Date(timestamp);
const time = date.toLocaleTimeString('no-NO');
return `${time}`;
};

0 comments on commit a3ef850

Please sign in to comment.