Skip to content

Commit be94411

Browse files
authored
Merge pull request #298 from aali309/GITOPS-10536-console-plugin-status-tests-4.18
cherry-pick Add unit tests for health & application set status to release-4.18 branch
2 parents 610a68f + 88031ca commit be94411

5 files changed

Lines changed: 96 additions & 27 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { renderToStaticMarkup } from 'react-dom/server';
2+
3+
import ApplicationSetStatus from './ApplicationSetStatus';
4+
5+
describe('ApplicationSetStatus', () => {
6+
it('renders Healthy', () => {
7+
expect(renderToStaticMarkup(<ApplicationSetStatus status="Healthy" />)).toMatchInlineSnapshot(
8+
`"<span><svg data-icon="HeartIcon" style="color:var(--pf-v5-global--success-color--100)"></svg> Healthy</span>"`,
9+
);
10+
});
11+
12+
it('renders Error', () => {
13+
expect(renderToStaticMarkup(<ApplicationSetStatus status="Error" />)).toMatchInlineSnapshot(
14+
`"<span><svg data-icon="HeartBrokenIcon" style="color:var(--pf-v5-global--danger-color--100)"></svg> Error</span>"`,
15+
);
16+
});
17+
18+
it('renders Unknown for unrecognised status', () => {
19+
expect(renderToStaticMarkup(<ApplicationSetStatus status="Unknown" />)).toMatchInlineSnapshot(
20+
`"<span><svg data-icon="UnknownIcon" style="color:var(--pf-v5-global--disabled-color--100)"></svg> Unknown</span>"`,
21+
);
22+
});
23+
24+
it('renders Unknown icon for empty status', () => {
25+
expect(renderToStaticMarkup(<ApplicationSetStatus status="" />)).toMatchInlineSnapshot(
26+
`"<span><svg data-icon="UnknownIcon" style="color:var(--pf-v5-global--disabled-color--100)"></svg> </span>"`,
27+
);
28+
});
29+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as React from 'react';
2+
import {
3+
HealthDegradedIcon,
4+
HealthHealthyIcon,
5+
HealthUnknownIcon,
6+
} from 'src/gitops/utils/components/Icons/Icons';
7+
import { ApplicationSetStatus as AppSetStatus } from 'src/gitops/utils/constants';
8+
9+
interface ApplicationSetStatusProps {
10+
status: string;
11+
}
12+
13+
const ApplicationSetStatus: React.FC<ApplicationSetStatusProps> = ({ status }) => {
14+
let targetIcon: React.ReactNode;
15+
16+
switch (status) {
17+
case AppSetStatus.HEALTHY:
18+
targetIcon = <HealthHealthyIcon />;
19+
break;
20+
case AppSetStatus.ERROR:
21+
targetIcon = <HealthDegradedIcon />;
22+
break;
23+
default:
24+
targetIcon = <HealthUnknownIcon />;
25+
}
26+
27+
return (
28+
<span>
29+
{targetIcon} {status}
30+
</span>
31+
);
32+
};
33+
34+
export default ApplicationSetStatus;

src/gitops/Statuses/HealthStatus.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,30 @@ describe('HealthStatus', () => {
2020
);
2121
});
2222

23+
it('renders Suspended', () => {
24+
expect(renderToStaticMarkup(<HealthStatus status="Suspended" />)).toMatchInlineSnapshot(
25+
`"<div><div><svg data-icon="OutlinedPauseCircleIcon" style="color:var(--pf-v5-global--disabled-color--100)"></svg> Suspended</div></div>"`,
26+
);
27+
});
28+
29+
it('renders Missing', () => {
30+
expect(renderToStaticMarkup(<HealthStatus status="Missing" />)).toMatchInlineSnapshot(
31+
`"<div><div><svg data-icon="GhostIcon" style="color:var(--pf-v5-global--warning-color--100)"></svg> Missing</div></div>"`,
32+
);
33+
});
34+
2335
it('renders Unknown for unrecognized status', () => {
2436
expect(renderToStaticMarkup(<HealthStatus status="SomethingElse" />)).toMatchInlineSnapshot(
2537
`"<div><div><svg data-icon="UnknownIcon" style="color:var(--pf-v5-global--disabled-color--100)"></svg> SomethingElse</div></div>"`,
2638
);
2739
});
2840

41+
it('renders Unknown for undefined status', () => {
42+
expect(renderToStaticMarkup(<HealthStatus status={undefined as any} />)).toMatchInlineSnapshot(
43+
`"<div><div><svg data-icon="UnknownIcon" style="color:var(--pf-v5-global--disabled-color--100)"></svg> </div></div>"`,
44+
);
45+
});
46+
2947
it('renders popover when message is provided', () => {
3048
expect(
3149
renderToStaticMarkup(<HealthStatus status="Degraded" message="Something broke" />),
@@ -65,4 +83,12 @@ describe('HealthStatusIcon', () => {
6583
`"<svg data-icon="CircleNotchIcon" class="undefined fa-spin" style="color:#0DADEA" aria-label="Progressing"></svg>"`,
6684
);
6785
});
86+
87+
it('renders Unknown icon for unrecognised status', () => {
88+
expect(
89+
renderToStaticMarkup(<HealthStatusIcon status={'SomethingElse' as any} />),
90+
).toMatchInlineSnapshot(
91+
`"<i title="SomethingElse" class="fa fa-question-circle utils-health-status-icon" style="color:#CCD6DD"></i>"`,
92+
);
93+
});
6894
});

src/gitops/Statuses/SyncStatus.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ describe('SyncStatus', () => {
2525
`"<span> </span>"`,
2626
);
2727
});
28+
29+
it('renders Unknown icon for undefined status', () => {
30+
expect(renderToStaticMarkup(<SyncStatus status={undefined as any} />)).toMatchInlineSnapshot(
31+
`"<span> </span>"`,
32+
);
33+
});
2834
});

src/gitops/components/shared/ApplicationSetList.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ import { Tbody, Td, ThProps, Tr } from '@patternfly/react-table';
2626

2727
import { useApplicationSetActionsProvider } from '../../hooks/useApplicationSetActionsProvider';
2828
import { ApplicationSetKind, ApplicationSetModel } from '../../models/ApplicationSetModel';
29+
import ApplicationSetStatusFragment from '../../Statuses/ApplicationSetStatus';
2930
import ActionsDropdown from '../../utils/components/ActionDropDown/ActionDropDown';
30-
// Import status icons for consistency with ApplicationList
31-
import {
32-
HealthDegradedIcon,
33-
HealthHealthyIcon,
34-
HealthUnknownIcon,
35-
} from '../../utils/components/Icons/Icons';
3631
import { ApplicationSetStatus } from '../../utils/constants';
3732
import { getAppSetGeneratorCount, getAppSetStatus } from '../../utils/gitops';
3833
import { modelToGroupVersionKind, modelToRef } from '../../utils/utils';
@@ -90,27 +85,6 @@ const getGeneratedAppsCount = (
9085
}).length;
9186
};
9287

93-
const ApplicationSetStatusFragment: React.FC<{ status: string }> = ({ status }) => {
94-
let targetIcon: React.ReactNode;
95-
96-
switch (status) {
97-
case ApplicationSetStatus.HEALTHY:
98-
targetIcon = <HealthHealthyIcon />;
99-
break;
100-
case ApplicationSetStatus.ERROR:
101-
targetIcon = <HealthDegradedIcon />;
102-
break;
103-
default:
104-
targetIcon = <HealthUnknownIcon />;
105-
}
106-
107-
return (
108-
<span>
109-
{targetIcon} {status}
110-
</span>
111-
);
112-
};
113-
11488
interface ApplicationSetProps {
11589
namespace: string;
11690
hideNameLabelFilters?: boolean;

0 commit comments

Comments
 (0)