1+ import React from 'react' ;
2+ import { render , screen } from '@testing-library/react' ;
3+ import { Provider } from 'react-redux' ;
4+ import configureMockStore from 'redux-mock-store' ;
5+ import thunk from 'redux-thunk' ;
16import { testComponentSnapshotsWithFixtures } from '@theforeman/test' ;
2-
7+ import { useAPI } from 'foremanReact/common/hooks/API/APIHooks' ;
8+ import {
9+ setupAdvisorEngineTest ,
10+ createBaseStoreWithAdvisorConfig ,
11+ } from '../../../../__mocks__/testHelpers/advisorEngineTestHelper' ;
312import PageHeader from '../PageHeader' ;
413
14+ // Mock useAPI to return values based on the key
15+ jest . mock ( 'foremanReact/common/hooks/API/APIHooks' ) ;
16+
17+ const mockUseAPI = useAPI ;
18+
19+ // Mock child components to isolate PageHeader testing
20+ // This prevents child component complexity from affecting our tests
21+ jest . mock ( '../components/SettingsWarning' , ( ) => ( ) => (
22+ < div data-testid = "settings-warning" > SettingsWarning</ div >
23+ ) ) ;
24+ jest . mock ( '../PageTitle' , ( ) => ( ) => (
25+ < div data-testid = "page-title" > PageTitle</ div >
26+ ) ) ;
27+ jest . mock ( '../../InventorySettings' , ( ) => ( ) => (
28+ < div data-testid = "inventory-settings" > InventorySettings</ div >
29+ ) ) ;
30+ jest . mock ( '../components/PageDescription' , ( ) => ( ) => (
31+ < div data-testid = "page-description" > PageDescription</ div >
32+ ) ) ;
33+ jest . mock ( '../../InventoryFilter' , ( ) => ( ) => (
34+ < div data-testid = "inventory-filter" > InventoryFilter</ div >
35+ ) ) ;
36+ jest . mock ( '../components/ToolbarButtons' , ( ) => ( ) => (
37+ < div data-testid = "toolbar-buttons" > ToolbarButtons</ div >
38+ ) ) ;
39+
40+ const middlewares = [ thunk ] ;
41+ const mockStore = configureMockStore ( middlewares ) ;
42+
43+ // Create store states using helper
44+ const baseStoreState = createBaseStoreWithAdvisorConfig ( false ) ;
45+ const iopModeStoreState = createBaseStoreWithAdvisorConfig ( true ) ;
46+
547const fixtures = {
648 'render without Props' : { } ,
749 /** fixtures, props for the component */
@@ -10,4 +52,115 @@ const fixtures = {
1052describe ( 'PageHeader' , ( ) => {
1153 describe ( 'rendering' , ( ) =>
1254 testComponentSnapshotsWithFixtures ( PageHeader , fixtures ) ) ;
55+
56+ describe ( 'component behavior' , ( ) => {
57+ test ( 'renders all components when not in IoP mode' , ( ) => {
58+ setupAdvisorEngineTest ( mockUseAPI , false ) ;
59+ const store = mockStore ( baseStoreState ) ;
60+
61+ render (
62+ < Provider store = { store } >
63+ < PageHeader />
64+ </ Provider >
65+ ) ;
66+
67+ // All components should be present when not in IoP mode
68+ expect ( screen . getByTestId ( 'settings-warning' ) ) . toBeTruthy ( ) ;
69+ expect ( screen . getByTestId ( 'page-title' ) ) . toBeTruthy ( ) ;
70+ expect ( screen . getByTestId ( 'inventory-settings' ) ) . toBeTruthy ( ) ;
71+ expect ( screen . getByTestId ( 'page-description' ) ) . toBeTruthy ( ) ;
72+ expect ( screen . getByTestId ( 'inventory-filter' ) ) . toBeTruthy ( ) ;
73+ expect ( screen . getByTestId ( 'toolbar-buttons' ) ) . toBeTruthy ( ) ;
74+ } ) ;
75+
76+ test ( 'hides inventory settings and description when in IoP mode' , ( ) => {
77+ setupAdvisorEngineTest ( mockUseAPI , true ) ;
78+ const store = mockStore ( iopModeStoreState ) ;
79+
80+ render (
81+ < Provider store = { store } >
82+ < PageHeader />
83+ </ Provider >
84+ ) ;
85+
86+ // Core components should still be present
87+ expect ( screen . getByTestId ( 'settings-warning' ) ) . toBeTruthy ( ) ;
88+ expect ( screen . getByTestId ( 'page-title' ) ) . toBeTruthy ( ) ;
89+ expect ( screen . getByTestId ( 'inventory-filter' ) ) . toBeTruthy ( ) ;
90+ expect ( screen . getByTestId ( 'toolbar-buttons' ) ) . toBeTruthy ( ) ;
91+
92+ // These components should be hidden in IoP mode
93+ expect ( screen . queryByTestId ( 'inventory-settings' ) ) . toBeNull ( ) ;
94+ expect ( screen . queryByTestId ( 'page-description' ) ) . toBeNull ( ) ;
95+ } ) ;
96+
97+ test ( 'renders with correct CSS class' , ( ) => {
98+ setupAdvisorEngineTest ( mockUseAPI , false ) ;
99+ const store = mockStore ( baseStoreState ) ;
100+
101+ const { container } = render (
102+ < Provider store = { store } >
103+ < PageHeader />
104+ </ Provider >
105+ ) ;
106+
107+ expect ( container . querySelector ( '.inventory-upload-header' ) ) . toBeTruthy ( ) ;
108+ } ) ;
109+
110+ test ( 'renders grid layout with correct structure' , ( ) => {
111+ setupAdvisorEngineTest ( mockUseAPI , false ) ;
112+ const store = mockStore ( baseStoreState ) ;
113+
114+ const { container } = render (
115+ < Provider store = { store } >
116+ < PageHeader />
117+ </ Provider >
118+ ) ;
119+
120+ // Check for grid row
121+ const gridRow = container . querySelector ( '.row' ) ;
122+ expect ( gridRow ) . toBeTruthy ( ) ;
123+
124+ // Check for grid columns with correct classes
125+ const filterColumn = container . querySelector ( '.col-xs-4' ) ;
126+ expect ( filterColumn ) . toBeTruthy ( ) ;
127+
128+ const toolbarColumn = container . querySelector ( '.col-xs-7' ) ;
129+ expect ( toolbarColumn ) . toBeTruthy ( ) ;
130+ } ) ;
131+
132+ test ( 'renders description section only when not in IoP mode' , ( ) => {
133+ setupAdvisorEngineTest ( mockUseAPI , false ) ;
134+ const store = mockStore ( baseStoreState ) ;
135+
136+ const { container } = render (
137+ < Provider store = { store } >
138+ < PageHeader />
139+ </ Provider >
140+ ) ;
141+
142+ // Description section should be present when not in IoP mode
143+ const descriptionSection = container . querySelector (
144+ '.inventory-upload-header-description'
145+ ) ;
146+ expect ( descriptionSection ) . toBeTruthy ( ) ;
147+ } ) ;
148+
149+ test ( 'does not render description section when in IoP mode' , ( ) => {
150+ setupAdvisorEngineTest ( mockUseAPI , true ) ;
151+ const store = mockStore ( iopModeStoreState ) ;
152+
153+ const { container } = render (
154+ < Provider store = { store } >
155+ < PageHeader />
156+ </ Provider >
157+ ) ;
158+
159+ // Description section should not be present in IoP mode
160+ const descriptionSection = container . querySelector (
161+ '.inventory-upload-header-description'
162+ ) ;
163+ expect ( descriptionSection ) . toBeNull ( ) ;
164+ } ) ;
165+ } ) ;
13166} ) ;
0 commit comments