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 ensa version sap system details #1559

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/js/components/ClusterDetails/AscsErsClusterDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ProviderLabel from '@components/ProviderLabel';
import DottedPagination from '@components/DottedPagination';
import HostLink from '@components/HostLink';
import SapSystemLink from '@components/SapSystemLink';
import { renderEnsaVersion } from '@components/SapSystemDetails';

import ChecksComingSoon from '@static/checks-coming-soon.svg';

Expand Down Expand Up @@ -140,8 +141,7 @@ function AscsErsClusterDetails({
{
title: 'ENSA version',
content: currentSapSystem?.ensa_version || '-',
render: (content) =>
content === 'no_ensa' ? '-' : content.toUpperCase(),
render: (content) => renderEnsaVersion(content),
},
{
title: 'Filesystem resource based',
Expand Down
51 changes: 51 additions & 0 deletions assets/js/components/DatabaseDetails/DatabaseDetails.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';

import {
clusterFactory,
databaseInstanceFactory,
databaseFactory,
hostFactory,
} from '@lib/test-utils/factories';
import { DATABASE_TYPE } from '@lib/model';
import { keysToCamel } from '@lib/serialization';

import { GenericSystemDetails } from '@components/SapSystemDetails';

const system = {
...keysToCamel(
databaseFactory.build({ instances: databaseInstanceFactory.buildList(2) })
),
hosts: hostFactory.buildList(2, { cluster: clusterFactory.build() }),
};

function ContainerWrapper({ children }) {
return (
<div className="max-w-7xl mx-auto px-4 sm:px-6 md:px-8">{children}</div>
);
}

export default {
title: 'DatabaseDetails',
components: GenericSystemDetails,
decorators: [
(Story) => (
<MemoryRouter>
<Story />
</MemoryRouter>
),
],
render: (args) => (
<ContainerWrapper>
<GenericSystemDetails {...args} />
</ContainerWrapper>
),
};

export const Database = {
args: {
title: 'Database Details',
type: DATABASE_TYPE,
system,
},
};
12 changes: 12 additions & 0 deletions assets/js/components/SapSystemDetails/GenericSystemDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
systemInstancesTableConfiguration,
} from './tableConfigs';

export const renderEnsaVersion = (ensaVersion) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if the place for this function is the best one.
Suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can both leave it here or have a dedicated file, if we maybe get to have more and more render functions we can have something like renderers.js or something like that. For now I think we can leave it

Copy link
Contributor

Choose a reason for hiding this comment

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

(if you happen to find another file name that isn't utils feels free)

ensaVersion === 'no_ensa' ? '-' : ensaVersion.toUpperCase();

const renderType = (t) =>
t === APPLICATION_TYPE ? 'Application server' : 'HANA Database';

Expand Down Expand Up @@ -43,6 +46,15 @@ export function GenericSystemDetails({ title, type, system }) {
title: 'Type',
content: renderType(type),
},
...(type === APPLICATION_TYPE
? [
{
title: 'ENSA version',
content: system.ensaVersion || '-',
render: (content) => renderEnsaVersion(content),
},
]
: []),
{
title: '',
content: type,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import React from 'react';
import { faker } from '@faker-js/faker';
import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import { keysToCamel } from '@lib/serialization';
import { APPLICATION_TYPE } from '@lib/model';
import { renderWithRouter } from '@lib/test-utils';
import { hostFactory, sapSystemFactory } from '@lib/test-utils/factories';
import {
hostFactory,
sapSystemApplicationInstanceFactory,
sapSystemFactory,
} from '@lib/test-utils/factories';

import { GenericSystemDetails } from './GenericSystemDetails';

describe('GenericSystemDetails', () => {
it('should render correctly', () => {
const title = faker.datatype.uuid();
const sapSystem = keysToCamel(sapSystemFactory.build());
const sapSystem = keysToCamel(
sapSystemFactory.build({
ensa_version: 'ensa1',
instances: sapSystemApplicationInstanceFactory.buildList(5),
})
);
sapSystem.hosts = hostFactory.buildList(5);

const { sid, applicationInstances } = sapSystem;
Expand All @@ -29,6 +39,7 @@ describe('GenericSystemDetails', () => {
expect(screen.getByText(title)).toBeTruthy();
expect(screen.getByText('Application server')).toBeTruthy();
expect(screen.getByText(sid)).toBeTruthy();
expect('ENSA1').toBeTruthy();
features.split('|').forEach((role) => {
expect(screen.queryAllByText(role)).toBeTruthy();
});
Expand All @@ -42,4 +53,24 @@ describe('GenericSystemDetails', () => {

expect(screen.getByText('Not Found')).toBeTruthy();
});

it('should not render ENSA version if it is not available', () => {
const sapSystem = keysToCamel(
sapSystemFactory.build({
ensa_version: 'no_ensa',
instances: sapSystemApplicationInstanceFactory.buildList(5),
})
);
sapSystem.hosts = hostFactory.buildList(5);

renderWithRouter(
<GenericSystemDetails
title={faker.datatype.uuid()}
system={sapSystem}
type={APPLICATION_TYPE}
/>
);

expect(screen.getByText('ENSA version').nextSibling).toHaveTextContent('-');
});
});
53 changes: 53 additions & 0 deletions assets/js/components/SapSystemDetails/SapSystemDetails.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';

import {
clusterFactory,
hostFactory,
sapSystemApplicationInstanceFactory,
sapSystemFactory,
} from '@lib/test-utils/factories';
import { APPLICATION_TYPE } from '@lib/model';
import { keysToCamel } from '@lib/serialization';

import { GenericSystemDetails } from './GenericSystemDetails';

const system = {
...keysToCamel(
sapSystemFactory.build({
instances: sapSystemApplicationInstanceFactory.buildList(2),
})
),
hosts: hostFactory.buildList(2, { cluster: clusterFactory.build() }),
};

function ContainerWrapper({ children }) {
return (
<div className="max-w-7xl mx-auto px-4 sm:px-6 md:px-8">{children}</div>
);
}

export default {
title: 'SapSystemDetails',
components: GenericSystemDetails,
decorators: [
(Story) => (
<MemoryRouter>
<Story />
</MemoryRouter>
),
],
render: (args) => (
<ContainerWrapper>
<GenericSystemDetails {...args} />
</ContainerWrapper>
),
};

export const SapSystem = {
args: {
title: 'SAP System Details',
type: APPLICATION_TYPE,
system,
},
};
5 changes: 4 additions & 1 deletion assets/js/components/SapSystemDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import SapSystemDetails from './SapSystemDetails';
import InstanceStatus from './InstanceStatus';
import Features from './Features';

export { GenericSystemDetails } from './GenericSystemDetails';
export {
GenericSystemDetails,
renderEnsaVersion,
} from './GenericSystemDetails';

export { Features, InstanceStatus };

Expand Down
14 changes: 12 additions & 2 deletions assets/js/lib/test-utils/factories/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

const healthEnum = () => faker.helpers.arrayElement(['passing', 'critical']);
const healthEnum = () =>
faker.helpers.arrayElement(['passing', 'critical', 'warning', 'unknown']);
const features = () =>
faker.helpers.arrayElements(['HDB', 'HDB_WORKER', 'HDB_STANDBY']);

export const databaseInstanceFactory = Factory.define(() => ({
host_id: faker.datatype.uuid(),
sap_system_id: faker.datatype.uuid(),
health: healthEnum(),
host_id: faker.datatype.uuid(),
http_port: faker.internet.port(),
https_port: faker.internet.port(),
instance_hostname: faker.hacker.noun(),
instance_number: faker.datatype.number({ min: 10, max: 99 }).toString(),
sid: faker.random.alpha({ casing: 'upper', count: 3 }),
features: features().join('|'),
start_priority: faker.datatype.number({ min: 1, max: 9 }).toString(),
}));

export const databaseFactory = Factory.define(({ params }) => {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/lib/test-utils/factories/sapSystems.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { databaseInstanceFactory } from './databases';

const ensaVersion = () =>
faker.helpers.arrayElement(['no_ensa', 'ensa1', 'ensa2']);
const healthEnum = () => faker.helpers.arrayElement(['passing', 'critical']);
const healthEnum = () =>
faker.helpers.arrayElement(['passing', 'critical', 'warning', 'unknown']);
const roles = () =>
faker.helpers.arrayElements([
'MESSAGESERVER',
Expand Down