foreman_rh_cloud 12.0.0 → 12.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
  3. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  4. data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +2 -0
  5. data/app/services/foreman_rh_cloud/cloud_request.rb +4 -0
  6. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -1
  7. data/app/services/foreman_rh_cloud/rules_ingester.rb +12 -1
  8. data/config/routes.rb +4 -0
  9. data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
  10. data/lib/foreman_inventory_upload/generators/slice.rb +83 -42
  11. data/lib/foreman_inventory_upload.rb +5 -0
  12. data/lib/foreman_rh_cloud/engine.rb +15 -3
  13. data/lib/foreman_rh_cloud/version.rb +1 -1
  14. data/lib/foreman_rh_cloud.rb +2 -0
  15. data/package.json +1 -1
  16. data/test/unit/slice_generator_test.rb +212 -4
  17. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +5 -1
  18. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +2 -1
  19. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +27 -8
  20. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/index.js +11 -3
  21. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +71 -10
  22. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettingsSelectors.js +13 -1
  23. data/webpack/ForemanInventoryUpload/Components/InventorySettings/MinimalInventoryDropdown.js +107 -0
  24. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +9 -2
  25. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +8 -0
  26. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +53 -9
  27. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +72 -58
  28. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +61 -6
  29. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +18 -6
  30. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +54 -6
  31. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +2 -0
  32. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +8 -0
  33. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +4 -2
  34. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +1 -8
  35. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +4 -2
  36. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +47 -28
  37. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +46 -8
  38. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +2 -7
  39. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +1 -6
  40. data/webpack/common/Switcher/SwitcherPF4.js +11 -1
  41. metadata +4 -11
  42. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +0 -13
  43. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +0 -31
  44. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +0 -89
  45. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -62
  46. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +0 -10
  47. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +0 -43
  48. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +0 -72
  49. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +0 -23
@@ -10,6 +10,8 @@ exports[`Dashboard rendering with props 1`] = `
10
10
  "name": "Generating",
11
11
  "onClick": [Function],
12
12
  "props": Object {
13
+ "downloadButtonDisabled": [Function],
14
+ "downloadReports": [Function],
13
15
  "exitCode": "unknown",
14
16
  "restartProcess": [Function],
15
17
  "toggleFullScreen": [Function],
@@ -21,7 +23,6 @@ exports[`Dashboard rendering with props 1`] = `
21
23
  "name": "Uploading",
22
24
  "onClick": [Function],
23
25
  "props": Object {
24
- "downloadReports": [Function],
25
26
  "exitCode": "unknown",
26
27
  "toggleFullScreen": [Function],
27
28
  },
@@ -8,6 +8,27 @@ export const settingsDict = {
8
8
  'Enable automatic upload of your hosts inventory to the Red Hat cloud'
9
9
  ),
10
10
  },
11
+ allowAutoInsightsMismatchDelete: {
12
+ name: 'allow_auto_insights_mismatch_delete',
13
+ label: __('Automatic mismatch deletion'),
14
+ tooltip: __(
15
+ 'Enable automatic deletion of mismatched host records from the Red Hat cloud'
16
+ ),
17
+ },
18
+ };
19
+
20
+ // we don't use this anywhere, but leaving the comment just so you can, like, see
21
+ // export const parentSettingsDict = {
22
+ // insightsMinimalDataCollection: {
23
+ // name: 'insights_minimal_data_collection',
24
+ // label: __('Minimal data collection'),
25
+ // tooltip: __(
26
+ // 'Only send the minimum required data to Red Hat cloud, and obfuscate wherever possible'
27
+ // ),
28
+ // },
29
+ // };
30
+
31
+ export const childSettingsDict = {
11
32
  hostObfuscationEnabled: {
12
33
  name: 'obfuscate_inventory_hostnames',
13
34
  label: __('Obfuscate host names'),
@@ -20,16 +41,14 @@ export const settingsDict = {
20
41
  },
21
42
  excludePackagesEnabled: {
22
43
  name: 'exclude_installed_packages',
23
- label: __('Exclude installed Packages'),
44
+ label: __('Exclude installed packages'),
24
45
  tooltip: __(
25
46
  'Exclude installed packages from being uploaded to the Red Hat cloud'
26
47
  ),
27
48
  },
28
- allowAutoInsightsMismatchDelete: {
29
- name: 'allow_auto_insights_mismatch_delete',
30
- label: __('Automatic mismatch deletion'),
31
- tooltip: __(
32
- 'Enable automatic deletion of mismatched host records from the Red Hat cloud'
33
- ),
34
- },
49
+ };
50
+
51
+ export const allSettingsDict = {
52
+ ...settingsDict,
53
+ ...childSettingsDict,
35
54
  };
@@ -4,9 +4,8 @@ import { useSelector, useDispatch } from 'react-redux';
4
4
  import { selectSettings } from '../InventorySettingsSelectors';
5
5
  import { handleToggle } from './AdvancedSettingActions';
6
6
  import SwitcherPF4 from '../../../../common/Switcher/SwitcherPF4';
7
- import { settingsDict } from './AdvancedSettingsConstants';
8
7
 
9
- const AdvancedSetting = ({ setting }) => {
8
+ const AdvancedSetting = ({ setting, settingsDict, isLocked, lockedValue }) => {
10
9
  const settingValue = useSelector(store => selectSettings(store)[setting]);
11
10
  const dispatch = useDispatch();
12
11
  const onToggle = () =>
@@ -16,7 +15,8 @@ const AdvancedSetting = ({ setting }) => {
16
15
  id={settingsDict[setting].name}
17
16
  label={settingsDict[setting].label}
18
17
  tooltip={settingsDict[setting].tooltip}
19
- isChecked={settingValue}
18
+ isChecked={isLocked ? lockedValue : settingValue}
19
+ isDisabled={isLocked}
20
20
  onChange={onToggle}
21
21
  />
22
22
  );
@@ -24,6 +24,14 @@ const AdvancedSetting = ({ setting }) => {
24
24
 
25
25
  AdvancedSetting.propTypes = {
26
26
  setting: PropTypes.string.isRequired,
27
+ settingsDict: PropTypes.shape({}).isRequired,
28
+ isLocked: PropTypes.bool,
29
+ lockedValue: PropTypes.bool,
30
+ };
31
+
32
+ AdvancedSetting.defaultProps = {
33
+ isLocked: false,
34
+ lockedValue: true,
27
35
  };
28
36
 
29
37
  export default AdvancedSetting;
@@ -1,18 +1,79 @@
1
- import React from 'react';
1
+ import React, { useState } from 'react';
2
+ import { useSelector } from 'react-redux';
2
3
  import { translate as __ } from 'foremanReact/common/I18n';
4
+ import { Flex, FlexItem } from '@patternfly/react-core';
3
5
 
4
6
  import AdvancedSetting from './AdvancedSetting';
5
- import { settingsDict } from './AdvancedSetting/AdvancedSettingsConstants';
7
+ import {
8
+ childSettingsDict,
9
+ settingsDict,
10
+ } from './AdvancedSetting/AdvancedSettingsConstants';
11
+ import {
12
+ selectSubscriptionConnectionEnabled,
13
+ selectInsightsMinimalDataCollection,
14
+ } from './InventorySettingsSelectors'; // Make sure this path is correct!
15
+ import MinimalInventoryDropdown from './MinimalInventoryDropdown';
6
16
 
7
17
  import './InventorySettings.scss';
8
18
 
9
- const InventorySettings = () => (
10
- <div className="inventory-settings">
11
- <h3>{__('Settings')}</h3>
12
- {Object.keys(settingsDict).map(key => (
13
- <AdvancedSetting setting={key} key={key} />
14
- ))}
15
- </div>
16
- );
19
+ const InventorySettings = () => {
20
+ const subscriptionConnectionEnabled = useSelector(
21
+ state => selectSubscriptionConnectionEnabled(state) // Added (state) =>
22
+ );
23
+ const insightsMinimalDataCollection = useSelector(
24
+ state => selectInsightsMinimalDataCollection(state) // Added (state) =>
25
+ );
26
+ const [chosenValue, setChosenValue] = useState(null);
27
+ const settingKeys = new Set(Object.keys(settingsDict));
28
+
29
+ if (!subscriptionConnectionEnabled) {
30
+ settingKeys.delete('autoUploadEnabled');
31
+ }
32
+
33
+ return (
34
+ <div className="inventory-settings">
35
+ <h3>{__('Settings')}</h3>
36
+ {[...settingKeys].map(key => {
37
+ const isChildSetting = Object.hasOwnProperty.call(
38
+ childSettingsDict,
39
+ key
40
+ );
41
+ return (
42
+ <AdvancedSetting
43
+ key={key}
44
+ setting={key}
45
+ settingsDict={isChildSetting ? childSettingsDict : settingsDict}
46
+ isLocked={
47
+ isChildSetting &&
48
+ (chosenValue === 'minimal' || insightsMinimalDataCollection)
49
+ }
50
+ />
51
+ );
52
+ })}
53
+ <MinimalInventoryDropdown setChosenValue={setChosenValue} />
54
+ {Object.keys(childSettingsDict).length > 0 && ( // Only render this section if there are child settings
55
+ <div style={{ marginTop: '1.5em' }}>
56
+ <Flex>
57
+ <FlexItem>
58
+ <span style={{ width: '6em' }} />
59
+ </FlexItem>
60
+ <FlexItem>
61
+ {Object.keys(childSettingsDict).map(key => (
62
+ <AdvancedSetting
63
+ key={key}
64
+ setting={key}
65
+ settingsDict={childSettingsDict}
66
+ isLocked={
67
+ chosenValue === 'minimal' || insightsMinimalDataCollection
68
+ }
69
+ />
70
+ ))}
71
+ </FlexItem>
72
+ </Flex>
73
+ </div>
74
+ )}
75
+ </div>
76
+ );
77
+ };
17
78
 
18
79
  export default InventorySettings;
@@ -1,12 +1,21 @@
1
- import { selectAPIResponse } from 'foremanReact/redux/API/APISelectors';
1
+ import {
2
+ selectAPIResponse,
3
+ selectAPIStatus,
4
+ } from 'foremanReact/redux/API/APISelectors';
2
5
  import { INVENTORY_SETTINGS } from './InventorySettingsConstants';
3
6
 
4
7
  export const selectSettings = state =>
5
8
  selectAPIResponse(state, INVENTORY_SETTINGS);
6
9
 
10
+ export const selectSettingsStatus = state =>
11
+ selectAPIStatus(state, INVENTORY_SETTINGS);
12
+
7
13
  export const selectAutoUploadEnabled = state =>
8
14
  selectSettings(state).autoUploadEnabled;
9
15
 
16
+ export const selectSubscriptionConnectionEnabled = state =>
17
+ selectSettings(state).subscriptionConnectionEnabled;
18
+
10
19
  export const selectHostObfuscationEnabled = state =>
11
20
  selectSettings(state).hostObfuscationEnabled;
12
21
 
@@ -18,3 +27,6 @@ export const selectExcludePackages = state =>
18
27
 
19
28
  export const selectMismatchDelete = state =>
20
29
  selectSettings(state).allowAutoInsightsMismatchDelete;
30
+
31
+ export const selectInsightsMinimalDataCollection = state =>
32
+ selectSettings(state).insightsMinimalDataCollection;
@@ -0,0 +1,107 @@
1
+ import React, { useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useDispatch, useSelector } from 'react-redux';
4
+ import { translate as __ } from 'foremanReact/common/I18n';
5
+ import {
6
+ Dropdown,
7
+ DropdownItem,
8
+ DropdownList,
9
+ MenuToggle,
10
+ } from '@patternfly/react-core';
11
+
12
+ import { childSettingsDict } from './AdvancedSetting/AdvancedSettingsConstants';
13
+ import { setSetting } from './InventorySettingsActions';
14
+
15
+ import { selectInsightsMinimalDataCollection } from './InventorySettingsSelectors';
16
+
17
+ const MinimalInventoryDropdown = ({ setChosenValue }) => {
18
+ const dispatch = useDispatch();
19
+ const [isOpen, setIsOpen] = useState(false);
20
+ const dropdownValues = {
21
+ minimal: {
22
+ title: __('Minimal data collection'),
23
+ description: __(
24
+ 'Only send the minimum required data to Red Hat cloud, obfuscation settings are disabled'
25
+ ),
26
+ },
27
+ optional: {
28
+ title: __('Optional data collection'),
29
+ description: __(
30
+ 'Send additional data to enhance Insights services, as per the settings'
31
+ ),
32
+ },
33
+ };
34
+ const valueToBoolean = {
35
+ minimal: true,
36
+ optional: false,
37
+ };
38
+ const currentSettingBoolean = useSelector(
39
+ selectInsightsMinimalDataCollection
40
+ );
41
+ const currentDropdownValue = currentSettingBoolean ? 'minimal' : 'optional';
42
+ const onToggleClick = () => {
43
+ setIsOpen(!isOpen);
44
+ };
45
+ const onSelect = (_event, value) => {
46
+ setIsOpen(false);
47
+ setChosenValue(value);
48
+
49
+ dispatch(
50
+ setSetting({
51
+ setting: 'insights_minimal_data_collection',
52
+ value: valueToBoolean[value],
53
+ })
54
+ );
55
+
56
+ if (value === 'minimal') {
57
+ // If user wants to move to minimal data collection, turn on all related settings.
58
+ // These will be overridden by insights_minimal_data_collection anyway, but this takes care of the visuals.
59
+ Object.values(childSettingsDict).forEach(setting => {
60
+ dispatch(
61
+ setSetting({
62
+ setting: setting.name,
63
+ value: true,
64
+ })
65
+ );
66
+ });
67
+ }
68
+ };
69
+ return (
70
+ <Dropdown
71
+ isOpen={isOpen}
72
+ onSelect={onSelect}
73
+ onOpenChange={val => setIsOpen(val)}
74
+ toggle={toggleRef => (
75
+ <MenuToggle
76
+ ref={toggleRef}
77
+ isFullWidth
78
+ onClick={onToggleClick}
79
+ isExpanded={isOpen}
80
+ >
81
+ {dropdownValues[currentDropdownValue].title}
82
+ </MenuToggle>
83
+ )}
84
+ shouldFocusToggleOnSelect
85
+ >
86
+ <div style={{ maxWidth: '28em' }}>
87
+ <DropdownList>
88
+ {Object.entries(dropdownValues).map(([value, item]) => (
89
+ <DropdownItem
90
+ value={value}
91
+ key={value}
92
+ description={item.description}
93
+ >
94
+ {item.title}
95
+ </DropdownItem>
96
+ ))}
97
+ </DropdownList>
98
+ </div>
99
+ </Dropdown>
100
+ );
101
+ };
102
+
103
+ MinimalInventoryDropdown.propTypes = {
104
+ setChosenValue: PropTypes.func.isRequired,
105
+ };
106
+
107
+ export default MinimalInventoryDropdown;
@@ -1,12 +1,19 @@
1
1
  import React from 'react';
2
2
  import { noop } from 'foremanReact/common/helpers';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
3
4
 
4
5
  export const props = {
5
6
  items: [
6
7
  {
7
8
  icon: 'some-icon',
8
- name: 'some-name',
9
- component: () => <p>test</p>,
9
+ name: __('Generating'),
10
+ component: () => <p>test1</p>,
11
+ onClick: noop,
12
+ },
13
+ {
14
+ icon: 'other-icon',
15
+ name: __('Uploading'),
16
+ component: () => <p>test2</p>,
10
17
  onClick: noop,
11
18
  },
12
19
  ],
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useSelector } from 'react-redux';
2
3
  import PropTypes from 'prop-types';
3
4
  import {
4
5
  TabContainer,
@@ -9,8 +10,10 @@ import {
9
10
  Icon,
10
11
  noop,
11
12
  } from 'patternfly-react';
13
+ import { translate as __ } from 'foremanReact/common/I18n';
12
14
  import './navContainer.scss';
13
15
  import FullScreenModal from '../FullScreenModal';
16
+ import { selectSubscriptionConnectionEnabled } from '../InventorySettings/InventorySettingsSelectors';
14
17
 
15
18
  const NavContainer = ({
16
19
  items,
@@ -18,8 +21,13 @@ const NavContainer = ({
18
21
  toggleFullScreen,
19
22
  terminalProps,
20
23
  }) => {
24
+ const subscriptionConnectionEnabled = useSelector(
25
+ selectSubscriptionConnectionEnabled
26
+ );
21
27
  const navItems = items.map((item, index) => {
22
28
  const { name, icon, onClick } = item;
29
+ if (name === __('Uploading') && !subscriptionConnectionEnabled) return null;
30
+
23
31
  return (
24
32
  <NavItem
25
33
  key={index}
@@ -1,25 +1,69 @@
1
1
  import React from 'react';
2
- import { mount, testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+ import { Provider } from 'react-redux';
3
+ import configureMockStore from 'redux-mock-store';
4
+ import thunk from 'redux-thunk';
5
+ import { screen, render } from '@testing-library/react';
6
+ import { mount } from '@theforeman/test';
3
7
  import NavContainer from '../NavContainer';
4
8
  import { props } from '../NavContainer.fixtures';
5
9
 
6
- const fixtures = {
7
- 'render without Props': {},
8
- 'render with Props': props,
9
- };
10
+ const middlewares = [thunk];
11
+ const mockStore = configureMockStore(middlewares);
10
12
 
11
13
  describe('NavContainer', () => {
12
- describe('rendering', () =>
13
- testComponentSnapshotsWithFixtures(NavContainer, fixtures));
14
+ const renderOptions = {
15
+ API: {
16
+ INVENTORY_SETTINGS: {
17
+ response: { subscriptionConnectionEnabled: false },
18
+ },
19
+ },
20
+ };
14
21
 
15
- it('click should call onTabClick prop', () => {
22
+ test('click should call onTabClick prop', () => {
16
23
  const onTabClick = jest.fn();
17
24
  const modifiedProps = {
18
25
  ...props,
19
26
  };
20
27
  modifiedProps.items[0].onClick = onTabClick;
21
- const wrapper = mount(<NavContainer {...modifiedProps} />);
28
+ const store = mockStore(renderOptions);
29
+
30
+ const wrapper = mount(
31
+ <Provider store={store}>
32
+ <NavContainer {...modifiedProps} />
33
+ </Provider>
34
+ );
22
35
  wrapper.find('NavItem a').simulate('click');
23
36
  expect(onTabClick).toBeCalled();
24
37
  });
38
+
39
+ test('when subscription connection is enabled', () => {
40
+ const options = {
41
+ API: {
42
+ INVENTORY_SETTINGS: {
43
+ response: { subscriptionConnectionEnabled: true },
44
+ },
45
+ },
46
+ };
47
+ const store = mockStore(options);
48
+ render(
49
+ <Provider store={store}>
50
+ <NavContainer {...props} />
51
+ </Provider>
52
+ );
53
+
54
+ expect(screen.queryAllByText('Generating')).toHaveLength(1);
55
+ expect(screen.queryAllByText('Uploading')).toHaveLength(1);
56
+ });
57
+
58
+ test('when subscription connection is not enabled', () => {
59
+ const store = mockStore(renderOptions);
60
+ render(
61
+ <Provider store={store}>
62
+ <NavContainer {...props} />
63
+ </Provider>
64
+ );
65
+
66
+ expect(screen.queryAllByText('Generating')).toHaveLength(1);
67
+ expect(screen.queryAllByText('Uploading')).toHaveLength(0);
68
+ });
25
69
  });
@@ -1,68 +1,82 @@
1
1
  import React from 'react';
2
2
  import { Text } from '@patternfly/react-core';
3
+ import { useSelector } from 'react-redux';
3
4
 
4
5
  import { translate as __ } from 'foremanReact/common/I18n';
5
6
  import { FormattedMessage } from 'react-intl';
7
+ import { selectSubscriptionConnectionEnabled } from '../../../InventorySettings/InventorySettingsSelectors';
6
8
 
7
- export const PageDescription = () => (
8
- <div id="inventory_page_description">
9
- <Text>
10
- {__(
11
- 'The Red Hat Hybrid Cloud Console provides a set of cloud services, including Red Hat Insights and Subscriptions, that provide predictive analysis, remediation of issues, and unified subscription reporting for this Foreman instance.'
12
- )}
13
- </Text>
14
- <Text>
15
- {__(
16
- 'The Foreman inventory upload plugin automatically uploads Foreman host inventory data to the Inventory service of Insights, where it can also be used by the Subscriptions service for subscription reporting. If you use the Subscriptions service, enabling inventory uploads is required.'
17
- )}
18
- </Text>
19
- <Text>
20
- <FormattedMessage
21
- id="enable-upload-hint"
22
- defaultMessage={__(
23
- 'To enable this reporting for all Foreman organizations, set {uploadButtonName} to on. The data will be reported automatically once per day.'
9
+ export const PageDescription = () => {
10
+ const subscriptionConnectionEnabled = useSelector(
11
+ selectSubscriptionConnectionEnabled
12
+ );
13
+
14
+ return (
15
+ <div id="inventory_page_description">
16
+ <Text>
17
+ {__(
18
+ 'The Red Hat Hybrid Cloud Console provides a set of cloud services, including Red Hat Insights and Subscriptions, that provide predictive analysis, remediation of issues, and unified subscription reporting for this Foreman instance.'
24
19
  )}
25
- values={{
26
- uploadButtonName: <strong>{__('Automatic inventory upload')}</strong>,
27
- }}
28
- />
29
- </Text>
30
- <Text>
31
- <FormattedMessage
32
- id="restart-button-hint"
33
- defaultMessage={__(
34
- 'To manually upload the data for a specific organization, select an organization and click {restartButtonName}.'
20
+ </Text>
21
+ <Text>
22
+ {__(
23
+ 'The Foreman inventory upload plugin automatically uploads Foreman host inventory data to the Inventory service of Insights, where it can also be used by the Subscriptions service for subscription reporting. If you use the Subscriptions service, enabling inventory uploads is required.'
35
24
  )}
36
- values={{
37
- restartButtonName: (
38
- <strong>{__('Generate and upload report')}</strong>
39
- ),
40
- }}
41
- />
42
- </Text>
43
- <Text>
44
- {__('For more information about the Subscriptions service, see:')}
45
- &nbsp;
46
- <a
47
- href="https://docs.redhat.com/en/documentation/subscription_central/1-latest/html/getting_started_with_the_subscriptions_service/index"
48
- target="_blank"
49
- rel="noopener noreferrer"
50
- >
51
- {__('About subscription watch')}
52
- </a>
53
- </Text>
54
- <Text>
55
- {__('For more information about Insights and Cloud Connector, see:')}
56
- &nbsp;
57
- <a
58
- href="https://console.redhat.com/security/insights/"
59
- target="_blank"
60
- rel="noopener noreferrer"
61
- >
62
- {__('Red Hat Insights Data and Application Security')}
63
- </a>
64
- </Text>
65
- </div>
66
- );
25
+ </Text>
26
+ {subscriptionConnectionEnabled && (
27
+ <Text>
28
+ <FormattedMessage
29
+ id="enable-upload-hint"
30
+ defaultMessage={__(
31
+ 'To enable this reporting for all Foreman organizations, set {uploadButtonName} to on. The data will be reported automatically once per day.'
32
+ )}
33
+ values={{
34
+ uploadButtonName: (
35
+ <strong>{__('Automatic inventory upload')}</strong>
36
+ ),
37
+ }}
38
+ />
39
+ </Text>
40
+ )}
41
+ {subscriptionConnectionEnabled && (
42
+ <Text>
43
+ <FormattedMessage
44
+ id="restart-button-hint"
45
+ defaultMessage={__(
46
+ 'To manually upload the data for a specific organization, select an organization and click {restartButtonName}.'
47
+ )}
48
+ values={{
49
+ restartButtonName: (
50
+ <strong>{__('Generate and upload report')}</strong>
51
+ ),
52
+ }}
53
+ />
54
+ </Text>
55
+ )}
56
+ <Text>
57
+ {__('For more information about the Subscriptions service, see:')}
58
+ &nbsp;
59
+ <a
60
+ href="https://docs.redhat.com/en/documentation/subscription_central/1-latest/html/getting_started_with_the_subscriptions_service/index"
61
+ target="_blank"
62
+ rel="noopener noreferrer"
63
+ >
64
+ {__('About subscription watch')}
65
+ </a>
66
+ </Text>
67
+ <Text>
68
+ {__('For more information about Insights and Cloud Connector, see:')}
69
+ &nbsp;
70
+ <a
71
+ href="https://console.redhat.com/security/insights/"
72
+ target="_blank"
73
+ rel="noopener noreferrer"
74
+ >
75
+ {__('Red Hat Insights Data and Application Security')}
76
+ </a>
77
+ </Text>
78
+ </div>
79
+ );
80
+ };
67
81
 
68
82
  export default PageDescription;
@@ -1,11 +1,66 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
1
+ import React from 'react';
2
+ import { Provider } from 'react-redux';
3
+ import configureMockStore from 'redux-mock-store';
4
+ import thunk from 'redux-thunk';
5
+ import { screen, render } from '@testing-library/react';
2
6
  import { PageDescription } from '../PageDescription';
3
7
 
4
- const fixtures = {
5
- 'render without Props': {},
6
- };
8
+ jest.mock('react-intl', () => {
9
+ const actualReactIntl = jest.requireActual('react-intl');
10
+ return {
11
+ ...actualReactIntl,
12
+ FormattedMessage: ({ defaultMessage, id }) => defaultMessage || id,
13
+ useIntl: () => ({
14
+ formatMessage: ({ defaultMessage, id }) => defaultMessage || id,
15
+ }),
16
+ };
17
+ });
18
+ const middlewares = [thunk];
19
+ const mockStore = configureMockStore(middlewares);
7
20
 
8
21
  describe('PageDescription', () => {
9
- describe('rendering', () =>
10
- testComponentSnapshotsWithFixtures(PageDescription, fixtures));
22
+ test('when subscription connection is enabled', () => {
23
+ const renderOptions = {
24
+ API: {
25
+ INVENTORY_SETTINGS: {
26
+ response: { subscriptionConnectionEnabled: true },
27
+ },
28
+ },
29
+ };
30
+ const store = mockStore(renderOptions);
31
+
32
+ render(
33
+ <Provider store={store}>
34
+ <PageDescription />
35
+ </Provider>
36
+ );
37
+ expect(
38
+ screen.queryAllByText(
39
+ /To enable this reporting for all Foreman organizations/
40
+ )
41
+ ).toHaveLength(1);
42
+ });
43
+
44
+ test('when subscription connection is not enabled', () => {
45
+ const renderOptions = {
46
+ API: {
47
+ INVENTORY_SETTINGS: {
48
+ response: { subscriptionConnectionEnabled: false },
49
+ },
50
+ },
51
+ };
52
+ const store = mockStore(renderOptions);
53
+
54
+ render(
55
+ <Provider store={store}>
56
+ <PageDescription />
57
+ </Provider>
58
+ );
59
+
60
+ expect(
61
+ screen.queryAllByText(
62
+ /To enable this reporting for all Foreman organizations/
63
+ )
64
+ ).toHaveLength(0);
65
+ });
11
66
  });