Skip to content

Commit

Permalink
Add HomeHealthSummary storybook (#1529)
Browse files Browse the repository at this point in the history
* Add HomeHealthSummary storybook

* Adapt HomeHealthSummary tests

* Get back resultEnum as it does not have unknown value

* Add unclustered story

* Move render to default export

* Add empty story
  • Loading branch information
arbulu89 authored Jun 20, 2023
1 parent 4d93d9f commit ed5bd0c
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 48 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;
72 changes: 72 additions & 0 deletions assets/js/components/HealthSummary/HomeHealthSummary.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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',
});
const unClusteredSummary = healthSummaryFactory.buildList(3, {
clusterId: null,
clustersHealth: 'unknown',
databaseHealth: 'passing',
hostsHealth: 'passing',
sapsystemHealth: 'passing',
});

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

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

export const Random = {
args: {
sapSystemsHealth: randomSummary,
loading: false,
},
};

export const Empty = {
args: {
...Random.args,
sapSystemsHealth: [],
},
};

export const Healthy = {
args: {
...Random.args,
sapSystemsHealth: healthySummary,
},
};

export const UnClustered = {
args: {
...Random.args,
sapSystemsHealth: unClusteredSummary,
},
};
53 changes: 25 additions & 28 deletions assets/js/components/HealthSummary/HomeHealthSummary.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { screen, fireEvent } from '@testing-library/react';
import 'intersection-observer';
import '@testing-library/jest-dom';

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

import { HomeHealthSummary } from './HomeHealthSummary';
import HomeHealthSummary from './HomeHealthSummary';

const homeHealthSummaryActionPayload = [
const homeHealthSummaryData = [
healthSummaryFactory.build({
clustersHealth: 'passing',
databaseHealth: 'passing',
Expand Down Expand Up @@ -38,21 +38,15 @@ const homeHealthSummaryActionPayload = [
}),
];

const initialState = {
sapSystemsHealthSummary: {
sapSystemsHealth: homeHealthSummaryActionPayload,
loading: false,
},
};

describe('HomeHealthSummary component', () => {
it('should have a clickable SAP INSTANCE icon with link to the belonging instance', () => {
const [StatefulHomeHealthSummary] = withState(
<HomeHealthSummary />,
initialState
const { container } = renderWithRouter(
<HomeHealthSummary
sapSystemsHealth={homeHealthSummaryData}
loading={false}
/>
);
const { container } = renderWithRouter(StatefulHomeHealthSummary);
const [{ id }] = homeHealthSummaryActionPayload;
const [{ id }] = homeHealthSummaryData;

expect(
container
Expand All @@ -62,12 +56,13 @@ describe('HomeHealthSummary component', () => {
});

it('should have a clickable PACEMAKER CLUSTER icon with link to the belonging cluster when available', () => {
const [StatefulHomeHealthSummary] = withState(
<HomeHealthSummary />,
initialState
const { container } = renderWithRouter(
<HomeHealthSummary
sapSystemsHealth={homeHealthSummaryData}
loading={false}
/>
);
const { container } = renderWithRouter(StatefulHomeHealthSummary);
const [{ clusterId }] = homeHealthSummaryActionPayload;
const [{ clusterId }] = homeHealthSummaryData;

expect(
container
Expand All @@ -89,11 +84,12 @@ describe('HomeHealthSummary component', () => {

describe('HomeHealthSummary component', () => {
it('should have a working link to the passing checks in the overview component', () => {
const [StatefulHomeHealthSummary] = withState(
<HomeHealthSummary />,
initialState
const { container } = renderWithRouter(
<HomeHealthSummary
sapSystemsHealth={homeHealthSummaryData}
loading={false}
/>
);
const { container } = renderWithRouter(StatefulHomeHealthSummary);

expect(
container
Expand All @@ -104,11 +100,12 @@ describe('HomeHealthSummary component', () => {

describe('health box filter behaviour', () => {
it('should put the filters values in the query string when health filters are selected', async () => {
const [StatefulHomeHealthSummary] = withState(
<HomeHealthSummary />,
initialState
const { container } = renderWithRouter(
<HomeHealthSummary
sapSystemsHealth={homeHealthSummaryData}
loading={false}
/>
);
const { container } = renderWithRouter(StatefulHomeHealthSummary);

expect(container.querySelector('tbody').childNodes.length).toEqual(4);

Expand Down
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 @@ -4,7 +4,7 @@ import { Factory } from 'fishery';
import day from 'dayjs';

import {
resultEnum,
healthEnum,
cloudProviderEnum,
hostFactory,
sapSystemFactory,
Expand Down Expand Up @@ -109,7 +109,7 @@ export const clusterFactory = Factory.define(({ sequence, params }) => {
hosts_number: faker.datatype.number(),
resources_number: faker.datatype.number(),
type: clusterTypeEnum(),
health: resultEnum(),
health: healthEnum(),
selected_checks: [],
provider: cloudProviderEnum(),
cib_last_written: day(faker.date.recent()).format('ddd MMM D h:mm:ss YYYY'),
Expand Down
5 changes: 4 additions & 1 deletion assets/js/lib/test-utils/factories/executions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable import/no-extraneous-dependencies */
import { faker } from '@faker-js/faker';
import { Factory } from 'fishery';
import { hostFactory, resultEnum, randomObjectFactory } from '.';
import { hostFactory, randomObjectFactory } from '.';

export const checksExecutionStatusEnum = () =>
faker.helpers.arrayElement(['running', 'completed', 'requested']);

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

const expectationReturnTypeEnum = () =>
faker.helpers.arrayElement(['expect', 'expect_same']);

Expand Down
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 @@ -37,16 +37,16 @@ export const randomObjectFactory = Factory.define(({ transientParams }) => {
);
});

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 @@ -58,10 +58,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 catalogExpectExpectationFactory = Factory.define(
Expand Down

0 comments on commit ed5bd0c

Please sign in to comment.