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
6 changes: 4 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,9 @@ const nodeDetailsConfig = {
{
title: 'Hostname',
key: '',
render: (_, { id, name }) => <HostLink hostId={id}>{name}</HostLink>,
render: (_, { id, name }) => (
<ClusterNodeLink hostId={id}>{name}</ClusterNodeLink>
),
},
{
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: Single.args.hosts.slice(0, 1),
},
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
38 changes: 30 additions & 8 deletions assets/js/components/ClusterDetails/AscsErsClusterDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ describe('ClusterDetails AscsErsClusterDetails component', () => {

nodes.forEach(
async (
{
id: clusterID,
name: nodeName,
role,
virtual_ip: virtualIp,
filesysten,
},
{ id: hostId, name: nodeName, role, virtual_ip: virtualIp, filesysten },
index
) => {
await waitFor(() => {
Expand All @@ -119,7 +113,7 @@ describe('ClusterDetails AscsErsClusterDetails component', () => {
expect(hostnameCell).toHaveTextContent(nodeName);
expect(hostnameCell)
.querySelector('a')
.toHaveAttributes('href', clusterID);
.toHaveAttributes('href', hostId);
expect(row.querySelector('td:nth-child(1)')).toHaveTextContent(role);
expect(row.querySelector('td:nth-child(2)')).toHaveTextContent(
virtualIp
Expand Down Expand Up @@ -200,4 +194,32 @@ describe('ClusterDetails AscsErsClusterDetails component', () => {
expect(sidContainer).toHaveTextContent(sid);
expect(sidContainer.querySelector('a')).toBeNull();
});

it('should not display a host link for unregistered hosts', () => {
const {
name,
cib_last_written: cibLastWritten,
provider,
details,
} = clusterFactory.build({ type: 'ascs_ers' });

const hosts = buildHostsFromAscsErsClusterDetails(details);
const unregisteredHost = hosts.pop();

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

expect(unregisteredHostContainer).not.toHaveAttribute('href');
});
});
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({ hostId, children }) {
if (hostId) {
return <HostLink hostId={hostId}>{children}</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]">{children}</span>
<Tooltip
tooltipText="Host currently not registered."
width="w-52 -translate-x-1/3"
/>
</span>
);
}

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

describe('ClusterNodeLink', () => {
it('renders HostLink when hostId is provided', () => {
const { id, hostname } = hostFactory.build();

renderWithRouter(<ClusterNodeLink hostId={id}>{hostname}</ClusterNodeLink>);

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

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

it('renders warning span when hostId is not provided', () => {
const { hostname } = hostFactory.build();

render(<ClusterNodeLink>{hostname}</ClusterNodeLink>);
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 hostId={hostData.id}>{hostData.name}</ClusterNodeLink>
),
},
{ 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.slice(0, 1),
},
};

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();

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(
registeredClusterNode.name
);

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