Skip to content

Commit 32ef189

Browse files
committed
Conditionally hide UI components and enable inventory sync in IOP mode
- Enable inventory synchronization in local advisor engine environments - Hide cloud-specific UI elements when use_iop_mode is true - Conditionally display settings based on iop mode - Remove APIHooks.js and update tests accordingly This allows inventory sync to run in IOP mode while hiding cloud-specific UI components that are not relevant in local advisor engine environments.
1 parent b15680c commit 32ef189

File tree

12 files changed

+432
-301
lines changed

12 files changed

+432
-301
lines changed

lib/inventory_sync/async/inventory_hosts_sync.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class InventoryHostsSync < QueryInventoryJob
88
set_callback :step, :around, :create_missing_hosts
99

1010
def plan(organizations)
11-
# Do not run for local advisor, since we use sub-man id to identify hosts.
12-
return if ForemanRhCloud.with_iop_smart_proxy?
1311
# by default the tasks will be executed concurrently
1412
super(organizations)
1513
plan_self_host_sync

webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ import InventoryFilter from '../InventoryFilter';
66
import ToolbarButtons from './components/ToolbarButtons';
77
import SettingsWarning from './components/SettingsWarning';
88
import PageTitle from './PageTitle';
9+
import { useIopConfig } from '../../../common/Hooks/ConfigHooks';
910
import './PageHeader.scss';
1011

11-
const PageHeader = () => (
12-
<div className="inventory-upload-header">
13-
<SettingsWarning />
14-
<PageTitle />
15-
<div className="inventory-upload-header-description">
16-
<InventorySettings />
17-
<PageDescription />
12+
const PageHeader = () => {
13+
const useIopMode = useIopConfig();
14+
15+
return (
16+
<div className="inventory-upload-header">
17+
<SettingsWarning />
18+
<PageTitle />
19+
{!useIopMode && (
20+
<div className="inventory-upload-header-description">
21+
<InventorySettings />
22+
<PageDescription />
23+
</div>
24+
)}
25+
<Grid.Row>
26+
<Grid.Col xs={4}>
27+
<InventoryFilter />
28+
</Grid.Col>
29+
<Grid.Col xs={7} xsOffset={1}>
30+
<ToolbarButtons />
31+
</Grid.Col>
32+
</Grid.Row>
1833
</div>
19-
<Grid.Row>
20-
<Grid.Col xs={4}>
21-
<InventoryFilter />
22-
</Grid.Col>
23-
<Grid.Col xs={7} xsOffset={1}>
24-
<ToolbarButtons />
25-
</Grid.Col>
26-
</Grid.Row>
27-
</div>
28-
);
34+
);
35+
};
2936

3037
PageHeader.propTypes = {};
3138

Lines changed: 178 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,183 @@
1-
import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2-
1+
import React from 'react';
2+
import { screen } from '@testing-library/react';
3+
import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers';
34
import PageHeader from '../PageHeader';
45

5-
const fixtures = {
6-
'render without Props': {},
7-
/** fixtures, props for the component */
8-
};
6+
// Create a variable to control IoP mode in tests
7+
let mockIopMode = false;
8+
9+
// Mock ForemanContext
10+
jest.mock('foremanReact/Root/Context/ForemanContext', () => ({
11+
useForemanContext: () => ({
12+
metadata: {
13+
foreman_rh_cloud: {
14+
iop: mockIopMode,
15+
},
16+
},
17+
UI: {},
18+
}),
19+
}));
20+
21+
// Mock child components to isolate PageHeader testing
22+
// This prevents child component complexity from affecting our tests
23+
jest.mock('../components/SettingsWarning', () => () => (
24+
<div data-testid="settings-warning">SettingsWarning</div>
25+
));
26+
jest.mock('../PageTitle', () => () => (
27+
<div data-testid="page-title">PageTitle</div>
28+
));
29+
jest.mock('../../InventorySettings', () => () => (
30+
<div data-testid="inventory-settings">InventorySettings</div>
31+
));
32+
jest.mock('../components/PageDescription', () => () => (
33+
<div data-testid="page-description">PageDescription</div>
34+
));
35+
jest.mock('../../InventoryFilter', () => () => (
36+
<div data-testid="inventory-filter">InventoryFilter</div>
37+
));
38+
jest.mock('../components/ToolbarButtons', () => () => (
39+
<div data-testid="toolbar-buttons">ToolbarButtons</div>
40+
));
41+
42+
const { renderWithStore } = rtlHelpers;
943

1044
describe('PageHeader', () => {
11-
describe('rendering', () =>
12-
testComponentSnapshotsWithFixtures(PageHeader, fixtures));
45+
describe('component behavior', () => {
46+
test('renders all components when not in IoP mode', () => {
47+
mockIopMode = false; // Ensure IoP mode is disabled for this test
48+
49+
renderWithStore(<PageHeader />, {
50+
API: {
51+
INVENTORY_SETTINGS: {
52+
response: { subscriptionConnectionEnabled: true },
53+
},
54+
ADVISOR_ENGINE_CONFIG: {
55+
response: { use_iop_mode: false },
56+
status: 'RESOLVED',
57+
},
58+
},
59+
});
60+
61+
// All components should be present when not in IoP mode
62+
expect(screen.getByTestId('settings-warning')).toBeTruthy();
63+
expect(screen.getByTestId('page-title')).toBeTruthy();
64+
expect(screen.getByTestId('inventory-settings')).toBeTruthy();
65+
expect(screen.getByTestId('page-description')).toBeTruthy();
66+
expect(screen.getByTestId('inventory-filter')).toBeTruthy();
67+
expect(screen.getByTestId('toolbar-buttons')).toBeTruthy();
68+
});
69+
70+
test('hides inventory settings and description when in IoP mode', () => {
71+
mockIopMode = true; // Enable IoP mode for this test
72+
73+
renderWithStore(<PageHeader />, {
74+
API: {
75+
INVENTORY_SETTINGS: {
76+
response: { subscriptionConnectionEnabled: true },
77+
},
78+
ADVISOR_ENGINE_CONFIG: {
79+
response: { use_iop_mode: true },
80+
status: 'RESOLVED',
81+
},
82+
},
83+
});
84+
85+
// Core components should still be present
86+
expect(screen.getByTestId('settings-warning')).toBeTruthy();
87+
expect(screen.getByTestId('page-title')).toBeTruthy();
88+
expect(screen.getByTestId('inventory-filter')).toBeTruthy();
89+
expect(screen.getByTestId('toolbar-buttons')).toBeTruthy();
90+
91+
// These components should be hidden in IoP mode
92+
expect(screen.queryByTestId('inventory-settings')).toBeNull();
93+
expect(screen.queryByTestId('page-description')).toBeNull();
94+
});
95+
96+
test('renders with correct CSS class', () => {
97+
mockIopMode = false; // Ensure IoP mode is disabled for this test
98+
99+
const { container } = renderWithStore(<PageHeader />, {
100+
API: {
101+
INVENTORY_SETTINGS: {
102+
response: { subscriptionConnectionEnabled: true },
103+
},
104+
ADVISOR_ENGINE_CONFIG: {
105+
response: { use_iop_mode: false },
106+
status: 'RESOLVED',
107+
},
108+
},
109+
});
110+
111+
expect(container.querySelector('.inventory-upload-header')).toBeTruthy();
112+
});
113+
114+
test('renders grid layout with correct structure', () => {
115+
mockIopMode = false; // Ensure IoP mode is disabled for this test
116+
117+
const { container } = renderWithStore(<PageHeader />, {
118+
API: {
119+
INVENTORY_SETTINGS: {
120+
response: { subscriptionConnectionEnabled: true },
121+
},
122+
ADVISOR_ENGINE_CONFIG: {
123+
response: { use_iop_mode: false },
124+
status: 'RESOLVED',
125+
},
126+
},
127+
});
128+
129+
const gridRow = container.querySelector('.row');
130+
expect(gridRow).toBeTruthy();
131+
132+
const filterColumn = container.querySelector('.col-xs-4');
133+
expect(filterColumn).toBeTruthy();
134+
135+
const toolbarColumn = container.querySelector('.col-xs-7');
136+
expect(toolbarColumn).toBeTruthy();
137+
});
138+
139+
test('renders description section only when not in IoP mode', () => {
140+
mockIopMode = false; // Ensure IoP mode is disabled for this test
141+
142+
const { container } = renderWithStore(<PageHeader />, {
143+
API: {
144+
INVENTORY_SETTINGS: {
145+
response: { subscriptionConnectionEnabled: true },
146+
},
147+
ADVISOR_ENGINE_CONFIG: {
148+
response: { use_iop_mode: false },
149+
status: 'RESOLVED',
150+
},
151+
},
152+
});
153+
154+
// Description section should be present when not in IoP mode
155+
const descriptionSection = container.querySelector(
156+
'.inventory-upload-header-description'
157+
);
158+
expect(descriptionSection).toBeTruthy();
159+
});
160+
161+
test('does not render description section when in IoP mode', () => {
162+
mockIopMode = true; // Enable IoP mode for this test
163+
164+
const { container } = renderWithStore(<PageHeader />, {
165+
API: {
166+
INVENTORY_SETTINGS: {
167+
response: { subscriptionConnectionEnabled: true },
168+
},
169+
ADVISOR_ENGINE_CONFIG: {
170+
response: { use_iop_mode: true },
171+
status: 'RESOLVED',
172+
},
173+
},
174+
});
175+
176+
// Description section should not be present in IoP mode
177+
const descriptionSection = container.querySelector(
178+
'.inventory-upload-header-description'
179+
);
180+
expect(descriptionSection).toBeNull();
181+
});
182+
});
13183
});

webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap

Lines changed: 0 additions & 36 deletions
This file was deleted.

webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import SyncButton from '../SyncButton';
44
import CloudConnectorButton from '../CloudConnectorButton';
55
import './toolbarButtons.scss';
66
import { selectSubscriptionConnectionEnabled } from '../../../InventorySettings/InventorySettingsSelectors';
7+
import { useIopConfig } from '../../../../../common/Hooks/ConfigHooks';
78

89
const ToolbarButtons = () => {
910
const subscriptionConnectionEnabled = useSelector(
1011
selectSubscriptionConnectionEnabled
1112
);
13+
const useIopMode = useIopConfig();
1214

1315
if (!subscriptionConnectionEnabled) {
1416
return null;
1517
}
1618

1719
return (
1820
<div className="inventory_toolbar_buttons">
19-
<CloudConnectorButton />
21+
{!useIopMode && <CloudConnectorButton />}
2022
<SyncButton />
2123
</div>
2224
);

0 commit comments

Comments
 (0)