Skip to content

Commit

Permalink
Rename component to HostSummary, fix typos and rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Oct 24, 2023
1 parent 98b7594 commit 0e1da3f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 81 deletions.
65 changes: 0 additions & 65 deletions assets/js/components/HostDetails/HostClusterAgentIpSummary.jsx

This file was deleted.

4 changes: 2 additions & 2 deletions assets/js/components/HostDetails/HostDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import CheckResultsOverview from '@components/CheckResultsOverview';
import StatusPill from './StatusPill';
import ProviderDetails from './ProviderDetails';
import SaptuneSummary from './SaptuneSummary';
import HostClusterAgentIpSummary from './HostClusterAgentIpSummary';
import HostSummary from './HostSummary';

import {
subscriptionsTableConfiguration,
Expand Down Expand Up @@ -158,7 +158,7 @@ function HostDetails({
<WarningBanner>{versionWarningMessage}</WarningBanner>
)}
<div className="flex xl:flex-row flex-col">
<HostClusterAgentIpSummary
<HostSummary
agentVersion={agentVersion}
cluster={cluster}
ipAddresses={ipAddresses}
Expand Down
67 changes: 67 additions & 0 deletions assets/js/components/HostDetails/HostSummary.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import ListView from '@components/ListView';
import HealthIcon from '@components/Health/HealthIcon';
import Tooltip from '@components/Tooltip';
import ClusterLink from '@components/ClusterLink';

import { chunk } from 'lodash';

const prepareTooltipContent = (ipAddresses) => {
const formattedIpList = chunk(ipAddresses, 2);
const preparedTooltipContent = formattedIpList.map((ipPair) => {
const key = ipPair.length < 2 ? ipPair[0] : `${ipPair[0]}_${ipPair[1]}`;
return (
<div key={key} className="flex items-center justify-center">
<span>{ipPair[0]}</span>
{ipPair[1] && <span>, {ipPair[1]}</span>}
</div>
);
});
return preparedTooltipContent;
};

const renderIpAddresses = (ipAddresses) => {
const joinedIpAddresses = ipAddresses.join(', ');
if (ipAddresses.length < 3) {
return <span>{joinedIpAddresses}</span>;
}

return (
<div className="flex flex-row">
<Tooltip
className="grid grid-flow-row grid-cols-1 grid-rows-1"
content={prepareTooltipContent(ipAddresses)}
>
<HealthIcon health="absent" />
</Tooltip>
<span className="truncate">{joinedIpAddresses}</span>
</div>
);
};

function HostSummary({ agentVersion, cluster, ipAddresses }) {
return (
<div className="mt-4 bg-white shadow rounded-lg py-4 px-8 xl:w-2/5 mr-4">
<ListView
className="grid-rows-3"
orientation="vertical"
titleClassName=""
contentClassName="overflow-hidden overflow-ellipsis"
data={[
{
title: 'Cluster',
content: <ClusterLink cluster={cluster} />,
},
{ title: 'Agent Version', content: agentVersion },
{
title: 'IP addresses',
render: renderIpAddresses,
content: ipAddresses,
},
]}
/>
</div>
);
}

export default HostSummary;
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { faker } from '@faker-js/faker';
import { clusterFactory } from '@lib/test-utils/factories';
import HostClusterAgentIpSummary from './HostClusterAgentIpSummary';
import HostSummary from './HostSummary';

describe('HostClusterAgentIpSummary', () => {
it('should render correct cluster name, agent version, ip addresses and a tooltip', async () => {
const clusterName = faker.animal.cat();
const cluster = clusterFactory.build({ name: clusterName });
describe('HostSummary', () => {
it('should render the content correctly', async () => {
const cluster = clusterFactory.build();
const { name: clusterName } = cluster;
const agentVersion = faker.system.semver();
const ipAddresses = [
faker.internet.ipv4(),
faker.internet.ipv4(),
faker.internet.ipv4(),
];
const expextedIpAdresses = ipAddresses.join(', ');
const expextedIpAddresses = ipAddresses.join(', ');

renderWithRouter(
<HostClusterAgentIpSummary
<HostSummary
agentVersion={agentVersion}
cluster={cluster}
ipAddresses={ipAddresses}
Expand All @@ -34,7 +34,7 @@ describe('HostClusterAgentIpSummary', () => {
agentVersion
);
expect(screen.getByText('IP addresses').nextSibling.textContent).toBe(
expextedIpAdresses
expextedIpAddresses
);

const tooltipIcon = screen.getByTestId('eos-svg-component');
Expand All @@ -49,15 +49,15 @@ describe('HostClusterAgentIpSummary', () => {
);
});

it('should render summary without a tooltip icon as there are fewer than four IPs', async () => {
const clusterName = faker.animal.cat();
const cluster = clusterFactory.build({ name: clusterName });
it('should render an icon if there are more than 3 ip addresses', () => {
const cluster = clusterFactory.build();
const { name: clusterName } = cluster;
const agentVersion = faker.system.semver();
const ipAddresses = [faker.internet.ipv4(), faker.internet.ipv4()];
const expextedIpAdresses = ipAddresses.join(', ');
const expextedIpAddresses = ipAddresses.join(', ');

renderWithRouter(
<HostClusterAgentIpSummary
<HostSummary
agentVersion={agentVersion}
cluster={cluster}
ipAddresses={ipAddresses}
Expand All @@ -71,7 +71,7 @@ describe('HostClusterAgentIpSummary', () => {
agentVersion
);
expect(screen.getByText('IP addresses').nextSibling.textContent).toBe(
expextedIpAdresses
expextedIpAddresses
);

const tooltipIcon = screen.queryByTestId('eos-svg-component');
Expand Down

0 comments on commit 0e1da3f

Please sign in to comment.