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

Add empty state to sbd details #2387

Merged
merged 10 commits into from
Mar 7, 2024
11 changes: 11 additions & 0 deletions assets/js/pages/ClusterDetails/HanaClusterDetails.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,14 @@ export const WithUnmanagedResources = {
details: unmanagedNodeResources,
},
};

export const WithNoSBDDevices = {
args: {
...Hana.args,
details: {
...Hana.args.details,
fencing_type: 'Diskless SBD',
sbd_devices: [],
},
},
};
25 changes: 15 additions & 10 deletions assets/js/pages/ClusterDetails/SBDDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';

import Pill from '@common/Pill';

const sbdDetailsHeader = 'SBD/Fencing';
const emptySBDListText = 'No additional fencing details to display.';

const getStatusPill = (status) =>
status === 'healthy' ? (
<Pill className="bg-green-200 text-green-800 mr-2">Healthy</Pill>
Expand All @@ -13,17 +16,19 @@ function SBDDetails({ sbdDevices }) {
return (
<>
<div className="mt-8">
<div>
<h2 className="text-2xl font-bold">SBD/Fencing</h2>
</div>
</div>
<div className="mt-2 bg-white shadow rounded-lg py-4 px-8 space-y-2 tn-sbd-details">
{sbdDevices.map(({ device, status }) => (
<div key={device}>
{getStatusPill(status)} {device}
</div>
))}
<h2 className="text-2xl font-bold">{sbdDetailsHeader}</h2>
</div>
{sbdDevices?.length > 0 ? (
<div className="mt-2 bg-white shadow rounded-lg py-4 px-8 space-y-2 tn-sbd-details">
{sbdDevices.map(({ device, status }) => (
<div key={device}>
{getStatusPill(status)} {device}
</div>
))}
</div>
) : (
<div className="mt-4">{emptySBDListText}</div>
)}
</>
);
}
Expand Down
47 changes: 47 additions & 0 deletions assets/js/pages/ClusterDetails/SBDDetails.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom';

import { sbdDevicesFactory } from '@lib/test-utils/factories';

import { capitalize } from 'lodash';

import SBDDetails from './SBDDetails';

describe('SBDDetails', () => {
it('should render empty state message when sbd devices are empty', () => {
const expectedEmptyStateMsg = 'No additional fencing details to display.';
const sbdDevices = [];

render(<SBDDetails sbdDevices={sbdDevices} />);

expect(screen.getByText(expectedEmptyStateMsg)).toBeInTheDocument();
});

it.each([{ health: 'unhealthy' }, { health: 'healthy' }])(
'should render sbd device with specified $health health',
({ health }) => {
const sbdDevices = sbdDevicesFactory.buildList(1, { status: health });
const { device: expectedDeviceName } = sbdDevices[0];

render(<SBDDetails sbdDevices={sbdDevices} />);

expect(screen.getByText(expectedDeviceName)).toBeTruthy();
expect(screen.getByText(capitalize(health))).toBeTruthy();
}
);

it('should render multiple devices and their status', () => {
const expectedSBD = [
sbdDevicesFactory.build({ status: 'unhealthy' }),
sbdDevicesFactory.build({ status: 'healthy' }),
];

render(<SBDDetails sbdDevices={expectedSBD} />);

expectedSBD.forEach(({ device, status }) => {
expect(screen.getByText(device)).toBeInTheDocument();
expect(screen.getByText(capitalize(status))).toBeInTheDocument();
});
});
});
Loading