Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle linking to unregistered hosts #1560

Merged
merged 13 commits into from
Jul 17, 2023
4 changes: 2 additions & 2 deletions assets/js/components/ClusterDetails/AscsErsClusterDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Table from '@components/Table';
import ListView from '@components/ListView';
import ProviderLabel from '@components/ProviderLabel';
import DottedPagination from '@components/DottedPagination';
import HostLink from '@components/HostLink';
import ClusterNodeLink from '@components/ClusterDetails/ClusterNodeLink';
import SapSystemLink from '@components/SapSystemLink';
import { renderEnsaVersion } from '@components/SapSystemDetails';

Expand All @@ -23,7 +23,7 @@ const nodeDetailsConfig = {
{
title: 'Hostname',
key: '',
render: (_, { id, name }) => <HostLink hostId={id}>{name}</HostLink>,
render: (_, { id, name }) => <ClusterNodeLink name={name} hostId={id} />,
},
{
title: 'Role',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ export const Single = {
),
};

export const WithUnregisteredHost = {
args: {
...Single.args,
hosts: [buildHostsFromAscsErsClusterDetails(details).pop()],
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
},
render: (args) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to at some point move this render to the main export default to avoid not needed repetition.
Could we do it in a next PR?
It would we as simple as moving this exact render up

<ContainerWrapper>
<AscsErsClusterDetails {...args} />
</ContainerWrapper>
),
};

export const MultiSID = {
args: {
...Single.args,
Expand Down
27 changes: 27 additions & 0 deletions assets/js/components/ClusterDetails/AscsErsClusterDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,31 @@ describe('ClusterDetails AscsErsClusterDetails component', () => {
expect(sidContainer).toHaveTextContent(sid);
expect(sidContainer.querySelector('a')).toBeNull();
});

it('should display a host link for registered hosts', () => {
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
const {
name,
cib_last_written: cibLastWritten,
provider,
details,
} = clusterFactory.build({ type: 'ascs_ers' });

const hosts = buildHostsFromAscsErsClusterDetails(details);
renderWithRouter(
<AscsErsClusterDetails
clusterName={name}
hosts={hosts}
cibLastWritten={cibLastWritten}
provider={provider}
sapSystems={[]}
details={details}
/>
);
const registeredHostContainer = screen.getByText(hosts[0].hostname);

expect(registeredHostContainer).toHaveAttribute(
'href',
`/hosts/${hosts[0].id}`
);
});
});
23 changes: 23 additions & 0 deletions assets/js/components/ClusterDetails/ClusterNodeLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { EOS_WARNING_OUTLINED } from 'eos-icons-react';

import Tooltip from '@components/Tooltip';
import HostLink from '@components/HostLink';

function ClusterNodeLink({ name, hostId }) {
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
if (hostId) {
return <HostLink hostId={hostId}>{name}</HostLink>;
}
return (
<span className="group flex items-center relative">
<EOS_WARNING_OUTLINED size="base" className="centered fill-yellow-500" />
<span className="ml-1 truncate max-w-[100px]">{name}</span>
<Tooltip
tooltipText="Host currently not registered."
width="w-52 -translate-x-1/3"
/>
</span>
);
}

export default ClusterNodeLink;
32 changes: 32 additions & 0 deletions assets/js/components/ClusterDetails/ClusterNodeLink.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { renderWithRouterMatch } from '@lib/test-utils';
import ClusterNodeLink from '@components/ClusterDetails/ClusterNodeLink';

describe('ClusterNodeLink', () => {
it('renders HostLink when hostId is provided', () => {
const hostId = '12345678-abcd-1234-abcd-1234567890ab';
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
const name = 'host01';
const path = '/hosts/:hostId';

renderWithRouterMatch(<ClusterNodeLink hostId={hostId} name={name} />, {
path,
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
route: `/hosts/${hostId}`,
});

const hostLinkElement = screen.getByRole('link', { name });

expect(hostLinkElement).toBeInTheDocument();
expect(hostLinkElement).toHaveAttribute('href', `/hosts/${hostId}`);
});

it('renders warning span when hostId is not provided', () => {
const name = 'host02';
rtorrero marked this conversation as resolved.
Show resolved Hide resolved

render(<ClusterNodeLink name={name} />);
expect(
screen.getByText('Host currently not registered.')
).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions assets/js/components/ClusterDetails/HanaClusterDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ListView from '@components/ListView';
import Table from '@components/Table';
import Tooltip from '@components/Tooltip';
import TriggerChecksExecutionRequest from '@components/TriggerChecksExecutionRequest';
import HostLink from '@components/HostLink';
import ClusterNodeLink from '@components/ClusterDetails/ClusterNodeLink';
import ChecksResultOverview from '@components/ClusterDetails/ChecksResultOverview';
import ProviderLabel from '@components/ProviderLabel';
import SapSystemLink from '@components/SapSystemLink';
Expand All @@ -34,7 +34,7 @@ const siteDetailsConfig = {
title: 'Hostname',
key: '',
render: (_, hostData) => (
<HostLink hostId={hostData.id}>{hostData.name}</HostLink>
<ClusterNodeLink name={hostData.name} hostId={hostData.id} />
),
},
{ title: 'Role', key: 'hana_status' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export const Hana = {
},
};

export const WithUnregisteredHost = {
args: {
...Hana.args,
hosts: [hosts.pop()],
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
},
};

export const WithNoSelectedChecks = {
args: {
...Hana.args,
Expand Down
48 changes: 48 additions & 0 deletions assets/js/components/ClusterDetails/HanaClusterDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { renderWithRouter } from '@lib/test-utils';
import {
clusterFactory,
hostFactory,
hanaClusterDetailsNodesFactory,
checksExecutionCompletedFactory,
checksExecutionRunningFactory,
sapSystemFactory,
Expand Down Expand Up @@ -181,4 +182,51 @@ describe('HanaClusterDetails component', () => {
expect(sidContainer).toHaveTextContent(sid);
expect(sidContainer.querySelector('a')).toBeNull();
});

it('should display a host link in the site details if the host is registered', () => {
const registeredClusterNode = hanaClusterDetailsNodesFactory.build({
name: 'registeredhost',
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
});

const {
clusterID,
clusterName,
cib_last_written: cibLastWritten,
type: clusterType,
sid,
provider,
details,
} = clusterFactory.build({ details: { nodes: [registeredClusterNode] } });

const host = hostFactory.build({
hostname: registeredClusterNode.name,
cluster_id: clusterID,
});

const sapSystems = sapSystemFactory.buildList(2, { tenant: sid });

renderWithRouter(
<HanaClusterDetails
clusterID={clusterID}
clusterName={clusterName}
selectedChecks={[]}
hasSelectedChecks={false}
hosts={[host]}
clusterType={clusterType}
cibLastWritten={cibLastWritten}
sid={sid}
provider={provider}
sapSystems={sapSystems}
details={details}
lastExecution={null}
/>
);

const registeredHostContainer = screen.getByText('registeredhost');

expect(registeredHostContainer).toHaveAttribute(
'href',
`/hosts/${host.id}`
);
});
});
Loading