@@ -2,8 +2,11 @@ import React from 'react';
22import { render , screen } from '@testing-library/react' ;
33import { API } from 'foremanReact/redux/API' ;
44import { CVECountCell } from '../CVECountCell' ;
5+ import * as ConfigHooks from '../../common/Hooks/ConfigHooks' ;
56
67jest . mock ( 'foremanReact/redux/API' ) ;
8+ jest . mock ( '../../common/Hooks/ConfigHooks' ) ;
9+
710API . get . mockImplementation ( async ( ) => ( {
811 data : [
912 {
@@ -14,15 +17,69 @@ API.get.mockImplementation(async () => ({
1417 ] ,
1518} ) ) ;
1619
20+ const hostDetailsMock = {
21+ name : 'test-host.example.com' ,
22+ subscription_facet_attributes : {
23+ uuid : 'test-uuid-123' ,
24+ } ,
25+ } ;
26+
1727describe ( 'CVECountCell' , ( ) => {
18- it ( 'renders an empty cves count column' , ( ) => {
19- const hostDetailsMock = {
28+ beforeEach ( ( ) => {
29+ ConfigHooks . useAdvisorEngineConfig . mockReturnValue ( true ) ;
30+ } ) ;
31+
32+ afterEach ( ( ) => {
33+ jest . clearAllMocks ( ) ;
34+ } ) ;
35+
36+ it ( 'renders an empty cves count column when no subscription UUID' , ( ) => {
37+ const hostDetailsMockIoP = {
2038 name : 'test-host.example.com' ,
2139 subscription_facet_attributes : {
2240 uuid : null , // no subscription
2341 } ,
2442 } ;
43+ render ( < CVECountCell hostDetails = { hostDetailsMockIoP } /> ) ;
44+ expect ( screen . getByRole ( 'img' , { hidden : true } ) ) . toBeTruthy ( ) ;
45+ } ) ;
46+
47+ it ( 'renders UnknownIcon when IoP is not enabled' , ( ) => {
48+ ConfigHooks . useAdvisorEngineConfig . mockReturnValue ( false ) ;
49+
50+ render ( < CVECountCell hostDetails = { hostDetailsMock } /> ) ;
51+ expect ( screen . getByRole ( 'img' , { hidden : true } ) ) . toBeTruthy ( ) ;
52+ expect ( ConfigHooks . useAdvisorEngineConfig ) . toHaveBeenCalled ( ) ;
53+ } ) ;
54+
55+ it ( 'renders UnknownIcon when IoP is enabled but CVE API call fails' , ( ) => {
56+ // Mock successful IoP config
57+ ConfigHooks . useAdvisorEngineConfig . mockReturnValue ( true ) ;
58+
59+ // Mock CVE API failure - override the global mock for this test
60+ API . get . mockImplementationOnce ( async ( ) => {
61+ throw new Error ( 'CVE API call failed' ) ;
62+ } ) ;
63+
64+ render ( < CVECountCell hostDetails = { hostDetailsMock } /> ) ;
65+
66+ // Should render UnknownIcon when CVE API fails
67+ expect ( screen . getByRole ( 'img' , { hidden : true } ) ) . toBeTruthy ( ) ;
68+ expect ( ConfigHooks . useAdvisorEngineConfig ) . toHaveBeenCalled ( ) ;
69+ } ) ;
70+
71+ it ( 'renders UnknownIcon when IoP is undefined (API call pending)' , ( ) => {
72+ ConfigHooks . useAdvisorEngineConfig . mockReturnValue ( undefined ) ;
73+
74+ const hostDetailsMock = {
75+ name : 'test-host.example.com' ,
76+ subscription_facet_attributes : {
77+ uuid : 'test-uuid-123' ,
78+ } ,
79+ } ;
80+
2581 render ( < CVECountCell hostDetails = { hostDetailsMock } /> ) ;
2682 expect ( screen . getByRole ( 'img' , { hidden : true } ) ) . toBeTruthy ( ) ;
83+ expect ( ConfigHooks . useAdvisorEngineConfig ) . toHaveBeenCalled ( ) ;
2784 } ) ;
2885} ) ;
0 commit comments