foreman_rh_cloud 11.4.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +2 -2
  3. data/app/controllers/concerns/inventory_upload/report_actions.rb +1 -1
  4. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +2 -0
  5. data/app/controllers/foreman_inventory_upload/uploads_settings_controller.rb +2 -0
  6. data/app/services/foreman_rh_cloud/cloud_request.rb +4 -0
  7. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +7 -1
  8. data/app/services/foreman_rh_cloud/rules_ingester.rb +12 -1
  9. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +3 -3
  10. data/lib/foreman_inventory_upload/async/upload_report_job.rb +4 -4
  11. data/lib/foreman_inventory_upload/generators/queries.rb +2 -0
  12. data/lib/foreman_inventory_upload/generators/slice.rb +83 -42
  13. data/lib/foreman_inventory_upload.rb +5 -0
  14. data/lib/foreman_rh_cloud/engine.rb +15 -3
  15. data/lib/foreman_rh_cloud/version.rb +1 -1
  16. data/lib/foreman_rh_cloud.rb +2 -0
  17. data/package.json +5 -5
  18. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +1 -1
  19. data/test/jobs/upload_report_job_test.rb +1 -1
  20. data/test/unit/slice_generator_test.rb +212 -4
  21. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +1 -7
  22. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +1 -5
  23. data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +3 -3
  24. data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +5 -1
  25. data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +2 -1
  26. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilter.js +1 -1
  27. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/inventoryFilter.scss +1 -1
  28. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants.js +27 -8
  29. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/index.js +11 -3
  30. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettings.js +71 -10
  31. data/webpack/ForemanInventoryUpload/Components/InventorySettings/InventorySettingsSelectors.js +13 -1
  32. data/webpack/ForemanInventoryUpload/Components/InventorySettings/MinimalInventoryDropdown.js +107 -0
  33. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +9 -2
  34. data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +8 -0
  35. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +53 -9
  36. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.scss +5 -5
  37. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageTitle.js +5 -4
  38. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudPingModal/index.js +18 -3
  39. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +72 -58
  40. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/PageDescription.test.js +61 -6
  41. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButton.js +0 -1
  42. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +0 -1
  43. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +18 -6
  44. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +54 -6
  45. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +2 -0
  46. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +8 -0
  47. data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +4 -2
  48. data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +1 -8
  49. data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +4 -2
  50. data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +47 -28
  51. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +46 -8
  52. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +2 -7
  53. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +3 -16
  54. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +5 -1
  55. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableConstants.js +1 -1
  56. data/webpack/InsightsCloudSync/Components/InsightsTable/Pagination.js +7 -7
  57. data/webpack/InsightsCloudSync/Components/InsightsTable/table.scss +1 -1
  58. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +5 -1
  59. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationTableConstants.js +8 -1
  60. data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +8 -2
  61. data/webpack/InsightsCloudSync/InsightsCloudSync.scss +1 -1
  62. data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +11 -2
  63. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +5 -4
  64. data/webpack/common/DropdownToggle.js +2 -2
  65. data/webpack/common/Switcher/HelpLabel.js +1 -1
  66. data/webpack/common/Switcher/SwitcherPF4.js +11 -1
  67. data/webpack/common/Switcher/SwitcherPF4.scss +1 -1
  68. data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +2 -6
  69. data/webpack/common/table/EmptyState.js +25 -18
  70. metadata +4 -43
  71. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettings.test.js +0 -13
  72. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettings.test.js.snap +0 -31
  73. data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +0 -89
  74. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -62
  75. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/__snapshots__/ToolbarButtons.test.js.snap +0 -10
  76. data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +0 -43
  77. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/AdvancedSettings.js +0 -72
  78. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/components/AdvancedSettings/index.js +0 -23
@@ -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
  });
@@ -12,18 +12,18 @@
12
12
  font-size: 16px;
13
13
  }
14
14
 
15
- .pf-c-dropdown__toggle {
15
+ .pf-v5-c-dropdown__toggle {
16
16
  margin-right: -20px;
17
17
  }
18
18
 
19
19
  .settings-alert {
20
20
  margin-bottom: 30px;
21
- .pf-c-alert {
21
+ .pf-v5-c-alert {
22
22
  margin-bottom: 5px;
23
23
 
24
- .pf-c-alert__title {
25
- font-size: var(--pf-global--FontSize--md);
26
- line-height: var(--pf-global--LineHeight--md);
24
+ .pf-v5-c-alert__title {
25
+ font-size: var(--pf-v5-global--FontSize--md);
26
+ line-height: var(--pf-v5-global--LineHeight--md);
27
27
  }
28
28
  }
29
29
  }
@@ -1,12 +1,11 @@
1
1
  import React, { useState } from 'react';
2
+ import { Grid, GridItem } from '@patternfly/react-core';
2
3
  import {
3
4
  Dropdown,
4
5
  DropdownItem,
5
6
  KebabToggle,
6
7
  DropdownPosition,
7
- Grid,
8
- GridItem,
9
- } from '@patternfly/react-core';
8
+ } from '@patternfly/react-core/deprecated';
10
9
  import Head from 'foremanReact/components/Head';
11
10
  import {
12
11
  INVENTORY_PAGE_TITLE,
@@ -58,7 +57,9 @@ const PageTitle = () => {
58
57
  className="title-dropdown"
59
58
  onSelect={() => setIsDropdownOpen(false)}
60
59
  toggle={
61
- <KebabToggle onToggle={isOpen => setIsDropdownOpen(isOpen)} />
60
+ <KebabToggle
61
+ onToggle={(_event, isOpen) => setIsDropdownOpen(isOpen)}
62
+ />
62
63
  }
63
64
  isOpen={isDropdownOpen}
64
65
  isPlain
@@ -2,7 +2,11 @@
2
2
  import React, { useCallback, useEffect, useState } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { useDispatch, useSelector } from 'react-redux';
5
- import { Table, TableBody, TableHeader } from '@patternfly/react-table';
5
+ import {
6
+ Table,
7
+ TableBody,
8
+ TableHeader,
9
+ } from '@patternfly/react-table/deprecated';
6
10
  import {
7
11
  Card,
8
12
  CardTitle,
@@ -11,6 +15,7 @@ import {
11
15
  ModalVariant,
12
16
  Spinner,
13
17
  Text,
18
+ Icon,
14
19
  } from '@patternfly/react-core';
15
20
  import {
16
21
  CheckCircleIcon,
@@ -108,8 +113,18 @@ const CloudPingModal = ({ title, isOpen, toggle }) => {
108
113
 
109
114
  const StatusIcon = ({ isPending, authStatus }) => {
110
115
  if (isPending) return <Spinner size="sm" />;
111
- if (authStatus.success) return <CheckCircleIcon color="green" />;
112
- if (authStatus.error) return <ExclamationCircleIcon color="red" />;
116
+ if (authStatus.success)
117
+ return (
118
+ <Icon color="green">
119
+ <CheckCircleIcon />
120
+ </Icon>
121
+ );
122
+ if (authStatus.error)
123
+ return (
124
+ <Icon color="red">
125
+ <ExclamationCircleIcon />
126
+ </Icon>
127
+ );
113
128
  return <Spinner size="sm" />;
114
129
  };
115
130
 
@@ -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
  });
@@ -22,7 +22,6 @@ class SyncButton extends React.Component {
22
22
  <Button
23
23
  className="sync_button"
24
24
  onClick={handleClick}
25
- size="lg"
26
25
  isDisabled={status === STATUS.PENDING}
27
26
  variant="secondary"
28
27
  >
@@ -6,7 +6,6 @@ exports[`SyncButton rendering render with Props 1`] = `
6
6
  className="sync_button"
7
7
  isDisabled={false}
8
8
  onClick={[Function]}
9
- size="lg"
10
9
  variant="secondary"
11
10
  >
12
11
  Sync all inventory status
@@ -1,13 +1,25 @@
1
1
  import React from 'react';
2
+ import { useSelector } from 'react-redux';
2
3
  import SyncButton from '../SyncButton';
3
4
  import CloudConnectorButton from '../CloudConnectorButton';
4
5
  import './toolbarButtons.scss';
6
+ import { selectSubscriptionConnectionEnabled } from '../../../InventorySettings/InventorySettingsSelectors';
5
7
 
6
- const ToolbarButtons = () => (
7
- <div className="inventory_toolbar_buttons">
8
- <CloudConnectorButton />
9
- <SyncButton />
10
- </div>
11
- );
8
+ const ToolbarButtons = () => {
9
+ const subscriptionConnectionEnabled = useSelector(
10
+ selectSubscriptionConnectionEnabled
11
+ );
12
+
13
+ if (!subscriptionConnectionEnabled) {
14
+ return null;
15
+ }
16
+
17
+ return (
18
+ <div className="inventory_toolbar_buttons">
19
+ <CloudConnectorButton />
20
+ <SyncButton />
21
+ </div>
22
+ );
23
+ };
12
24
 
13
25
  export default ToolbarButtons;
@@ -1,12 +1,60 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
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';
3
6
  import ToolbarButtons from '../ToolbarButtons';
4
7
 
5
- const fixtures = {
6
- 'render without Props': {},
8
+ const middlewares = [thunk];
9
+ const mockStore = configureMockStore(middlewares);
10
+
11
+ const renderOptions = {
12
+ API: {
13
+ INVENTORY_SETTINGS: {
14
+ response: { subscriptionConnectionEnabled: true },
15
+ },
16
+ },
17
+ ForemanRhCloud: {
18
+ inventoryUpload: {
19
+ accountsList: {
20
+ CloudConnectorStatus: {},
21
+ },
22
+ },
23
+ },
7
24
  };
8
25
 
9
26
  describe('ToolbarButtons', () => {
10
- describe('rendering', () =>
11
- testComponentSnapshotsWithFixtures(ToolbarButtons, fixtures));
27
+ test('when subscription connection is enabled', () => {
28
+ const store = mockStore(renderOptions);
29
+
30
+ render(
31
+ <Provider store={store}>
32
+ <ToolbarButtons />
33
+ </Provider>
34
+ );
35
+ expect(screen.queryAllByText('Configure cloud connector')).toHaveLength(1);
36
+ expect(screen.queryAllByText('Sync all inventory status')).toHaveLength(1);
37
+ });
38
+
39
+ test('when subscription connection is not enabled', () => {
40
+ const localSetting = {
41
+ API: {
42
+ INVENTORY_SETTINGS: {
43
+ response: { subscriptionConnectionEnabled: false },
44
+ },
45
+ },
46
+ };
47
+ const store = mockStore({
48
+ ...renderOptions,
49
+ ...localSetting,
50
+ });
51
+
52
+ render(
53
+ <Provider store={store}>
54
+ <ToolbarButtons />
55
+ </Provider>
56
+ );
57
+ expect(screen.queryAllByText('Configure cloud connector')).toHaveLength(0);
58
+ expect(screen.queryAllByText('Sync all inventory status')).toHaveLength(0);
59
+ });
12
60
  });