Skip to content

Commit

Permalink
Add HomeHealthSummary storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Jun 15, 2023
1 parent 76102d2 commit cab8f52
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 19 deletions.
9 changes: 3 additions & 6 deletions assets/js/components/HealthSummary/HomeHealthSummary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
import Table from '@components/Table';
import HealthIcon from '@components/Health/HealthIcon';
import { Link } from 'react-router-dom';
import { useSelector } from 'react-redux';
import PageHeader from '@components/PageHeader';
import HealthSummary from '@components/HealthSummary';
import useQueryStringValues from '@hooks/useQueryStringValues';
Expand Down Expand Up @@ -78,11 +77,7 @@ const healthSummaryTableConfig = {
],
};

export function HomeHealthSummary() {
const { loading, sapSystemsHealth } = useSelector(
(state) => state.sapSystemsHealthSummary
);

function HomeHealthSummary({ sapSystemsHealth, loading }) {
const {
extractedParams: { health: healthFilters = [] },
setQueryValues,
Expand Down Expand Up @@ -146,3 +141,5 @@ export function HomeHealthSummary() {
</div>
);
}

export default HomeHealthSummary;
56 changes: 56 additions & 0 deletions assets/js/components/HealthSummary/HomeHealthSummary.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';

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

import HomeHealthSummary from './HomeHealthSummary';

const randomSummary = healthSummaryFactory.buildList(3);
const healthySummary = healthSummaryFactory.buildList(3, {
clustersHealth: 'passing',
databaseHealth: 'passing',
hostsHealth: 'passing',
sapsystemHealth: 'passing',
});

export default {
title: 'HomeHealthSummary',
components: HomeHealthSummary,
decorators: [
(Story) => (
<MemoryRouter>
<Story />
</MemoryRouter>
),
],
};

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

export const Random = {
args: {
sapSystemsHealth: randomSummary,
loading: false,
},
render: (args) => (
<ContainerWrapper>
<HomeHealthSummary {...args} />
</ContainerWrapper>
),
};

export const Healthy = {
args: {
...Random.args,
sapSystemsHealth: healthySummary,
},
render: (args) => (
<ContainerWrapper>
<HomeHealthSummary {...args} />
</ContainerWrapper>
),
};
13 changes: 13 additions & 0 deletions assets/js/components/HealthSummary/HomeHealthSummaryPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { useSelector } from 'react-redux';
import HomeHealthSummary from './HomeHealthSummary';

export function HomeHealthSummaryPage() {
const { loading, sapSystemsHealth } = useSelector(
(state) => state.sapSystemsHealthSummary
);

return (
<HomeHealthSummary sapSystemsHealth={sapSystemsHealth} loading={loading} />
);
}
2 changes: 1 addition & 1 deletion assets/js/components/HealthSummary/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HealthSummary from './HealthSummary';

export { HomeHealthSummary } from './HomeHealthSummary';
export { HomeHealthSummaryPage } from './HomeHealthSummaryPage';

export default HealthSummary;
4 changes: 2 additions & 2 deletions assets/js/components/Home/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { HomeHealthSummary } from '@components/HealthSummary';
import { HomeHealthSummaryPage } from '@components/HealthSummary';

function Home() {
return <HomeHealthSummary />;
return <HomeHealthSummaryPage />;
}

export default Home;
4 changes: 2 additions & 2 deletions assets/js/lib/test-utils/factories/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';

import { resultEnum } from '.';
import { healthEnum } from '.';

const clusterTypeEnum = () =>
faker.helpers.arrayElement(['unknown', 'hana_scale_up']);
Expand All @@ -15,6 +15,6 @@ export const clusterFactory = Factory.define(({ sequence }) => ({
hosts_number: faker.datatype.number(),
resources_number: faker.datatype.number(),
type: clusterTypeEnum(),
health: resultEnum(),
health: healthEnum(),
selected_checks: [],
}));
14 changes: 6 additions & 8 deletions assets/js/lib/test-utils/factories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export * from './sapSystems';
export * from './clusters';
export * from './databases';

const healthEnum = () =>
const executionStateEnum = () =>
faker.helpers.arrayElement(['requested', 'running', 'not_running']);

export const resultEnum = () =>
faker.helpers.arrayElement(['passing', 'critical', 'warning']);
export const healthEnum = () =>
faker.helpers.arrayElement(['passing', 'critical', 'warning', 'unknown']);

export const checkFactory = Factory.define(() => ({
id: faker.datatype.uuid(),
description: faker.lorem.paragraph(),
executionState: healthEnum,
executionState: executionStateEnum,
health: healthEnum,
}));

Expand All @@ -29,10 +29,8 @@ export const healthSummaryFactory = Factory.define(() => ({
hostsHealth: healthEnum(),
id: faker.datatype.uuid(),
sapsystemHealth: healthEnum(),
sid: faker.random.alphaNumeric({
length: 3,
casing: 'upper',
}),
sid: faker.random.alphaNumeric(3, { casing: 'upper' }),
tenant: faker.random.alphaNumeric(3, { casing: 'upper' }),
}));

export const catalogCheckFactory = Factory.define(() => ({
Expand Down

0 comments on commit cab8f52

Please sign in to comment.