foreman_rh_cloud 14.1.1 → 14.1.3

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 (122) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +4 -8
  3. data/app/controllers/insights_cloud/ui_requests_controller.rb +3 -7
  4. data/app/services/foreman_rh_cloud/url_remediations_retriever.rb +19 -5
  5. data/lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb +49 -0
  6. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +26 -4
  7. data/lib/foreman_inventory_upload.rb +12 -1
  8. data/lib/foreman_rh_cloud/engine.rb +1 -0
  9. data/lib/foreman_rh_cloud/organization_destroy_extensions.rb +10 -0
  10. data/lib/foreman_rh_cloud/version.rb +1 -1
  11. data/lib/foreman_rh_cloud.rb +36 -9
  12. data/lib/insights_cloud/async/insights_generate_notifications.rb +10 -1
  13. data/lib/inventory_sync/async/inventory_self_host_sync.rb +12 -2
  14. data/package.json +1 -1
  15. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +16 -2
  16. data/test/controllers/insights_cloud/ui_requests_controller_test.rb +16 -2
  17. data/test/jobs/destroy_organization_hbi_hosts_job_test.rb +63 -0
  18. data/test/jobs/insights_generate_notifications_test.rb +26 -0
  19. data/test/jobs/inventory_self_host_sync_test.rb +9 -0
  20. data/test/unit/foreman_rh_cloud_self_host_test.rb +50 -2
  21. data/test/unit/metadata_generator_test.rb +24 -1
  22. data/test/unit/organization_destroy_extensions_test.rb +50 -0
  23. data/test/unit/services/foreman_rh_cloud/url_remediations_retriever_test.rb +82 -5
  24. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +10 -9
  25. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -9
  26. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +20 -9
  27. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +31 -8
  28. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +26 -10
  29. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +33 -9
  30. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +55 -35
  31. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -9
  32. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +12 -15
  33. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +32 -12
  34. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageTitle.test.js +14 -7
  35. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorButton.test.js +47 -18
  36. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +58 -15
  37. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +23 -9
  38. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +19 -17
  39. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +25 -37
  40. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +28 -8
  41. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +25 -8
  42. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +11 -9
  43. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +11 -9
  44. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +33 -12
  45. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +21 -8
  46. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +61 -47
  47. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +48 -4
  48. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +126 -35
  49. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableSelectors.test.js +90 -24
  50. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +79 -21
  51. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +31 -6
  52. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +42 -9
  53. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +91 -53
  54. data/webpack/common/Switcher/__tests__/HelpLabel.test.js +25 -10
  55. data/webpack/common/Switcher/__tests__/SwitcherPF4.test.js +41 -10
  56. metadata +9 -95
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +0 -18
  58. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +0 -25
  59. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +0 -20
  60. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +0 -47
  61. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +0 -59
  62. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +0 -34
  63. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +0 -14
  64. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +0 -25
  65. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +0 -49
  66. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +0 -86
  67. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +0 -75
  68. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +0 -46
  69. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +0 -26
  70. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +0 -14
  71. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +0 -28
  72. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +0 -21
  73. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +0 -21
  74. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +0 -17
  75. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +0 -19
  76. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +0 -9
  77. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -43
  78. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/AdvancedSettingActions.test.js +0 -9
  79. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/__snapshots__/AdvancedSettingActions.test.js.snap +0 -18
  80. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettingsActions.test.js +0 -14
  81. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettingsActions.test.js.snap +0 -26
  82. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +0 -68
  83. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorActions.test.js +0 -9
  84. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorActions.test.js.snap +0 -11
  85. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorButton.test.js.snap +0 -59
  86. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +0 -32
  87. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +0 -15
  88. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +0 -3
  89. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -58
  90. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -23
  91. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +0 -74
  92. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +0 -18
  93. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +0 -12
  94. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +0 -96
  95. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryUpload.test.js +0 -10
  96. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +0 -5
  97. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryUpload.test.js.snap +0 -14
  98. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +0 -33
  99. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +0 -21
  100. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +0 -65
  101. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -19
  102. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +0 -9
  103. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +0 -131
  104. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +0 -87
  105. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +0 -10
  106. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +0 -9
  107. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +0 -15
  108. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +0 -3
  109. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +0 -19
  110. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +0 -26
  111. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +0 -13
  112. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +0 -34
  113. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +0 -56
  114. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +0 -32
  115. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +0 -18
  116. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +0 -22
  117. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +0 -20
  118. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -19
  119. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +0 -25
  120. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +0 -39
  121. data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +0 -16
  122. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +0 -24
@@ -1,22 +1,51 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
2
3
  import { CloudConnectorButton } from '../CloudConnectorButton';
3
4
  import { CONNECTOR_STATUS } from '../CloudConnectorConstants';
4
5
 
5
- const fixtures = {
6
- 'render no cloud connector': {
7
- status: CONNECTOR_STATUS.NOT_RESOLVED,
8
- onClick: jest.fn(),
9
- },
10
- 'render resolved cloud connector': {
11
- status: CONNECTOR_STATUS.RESOLVED,
12
- onClick: jest.fn(),
13
- },
14
- 'render pending connector': {
15
- jobLink: '/job-link',
16
- status: CONNECTOR_STATUS.PENDING,
17
- onClick: jest.fn(),
18
- },
19
- };
6
+ describe('CloudConnectorButton', () => {
7
+ it('renders "Configure cloud connector" when not resolved', () => {
8
+ render(
9
+ <CloudConnectorButton
10
+ status={CONNECTOR_STATUS.NOT_RESOLVED}
11
+ onClick={jest.fn()}
12
+ />
13
+ );
14
+ expect(screen.getByRole('button', { name: /Configure cloud connector/ })).toBeTruthy();
15
+ });
20
16
 
21
- describe('CloudConnectorButton', () =>
22
- testComponentSnapshotsWithFixtures(CloudConnectorButton, fixtures));
17
+ it('renders "Reconfigure cloud connector" when resolved', () => {
18
+ render(
19
+ <CloudConnectorButton
20
+ status={CONNECTOR_STATUS.RESOLVED}
21
+ onClick={jest.fn()}
22
+ />
23
+ );
24
+ expect(screen.getByRole('button', { name: /Reconfigure cloud connector/ })).toBeTruthy();
25
+ });
26
+
27
+ it('renders in-progress button when pending', () => {
28
+ render(
29
+ <CloudConnectorButton
30
+ status={CONNECTOR_STATUS.PENDING}
31
+ onClick={jest.fn()}
32
+ jobLink="/job-link"
33
+ />
34
+ );
35
+ expect(
36
+ screen.getByText('Cloud Connector is in progress')
37
+ ).toBeTruthy();
38
+ });
39
+
40
+ it('calls onClick when configure button is clicked', () => {
41
+ const onClick = jest.fn();
42
+ render(
43
+ <CloudConnectorButton
44
+ status={CONNECTOR_STATUS.NOT_RESOLVED}
45
+ onClick={onClick}
46
+ />
47
+ );
48
+ fireEvent.click(screen.getByRole('button', { name: /Configure cloud connector/ }));
49
+ expect(onClick).toHaveBeenCalledTimes(1);
50
+ });
51
+ });
@@ -1,18 +1,61 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
2
3
  import { SettingsWarning } from './SettingsWarning';
3
4
 
4
- const fixtures = {
5
- 'with 2 alerts': {
6
- autoUpload: false,
7
- hostObfuscation: true,
8
- isCloudConnector: true,
9
- },
10
- 'with isCloudConnector false': {
11
- autoUpload: true,
12
- hostObfuscation: true,
13
- isCloudConnector: false,
14
- },
15
- };
5
+ describe('SettingsWarning', () => {
6
+ it('renders nothing when isCloudConnector is false', () => {
7
+ render(
8
+ <SettingsWarning autoUpload={false} isCloudConnector={false} />
9
+ );
10
+ expect(screen.queryByRole('alert')).toBeNull();
11
+ });
16
12
 
17
- describe('SettingsWarning', () =>
18
- testComponentSnapshotsWithFixtures(SettingsWarning, fixtures));
13
+ it('renders nothing when autoUpload is on and obfuscation is off', () => {
14
+ render(
15
+ <SettingsWarning
16
+ autoUpload
17
+ hostObfuscation={false}
18
+ isCloudConnector
19
+ />
20
+ );
21
+ expect(screen.queryByRole('alert')).toBeNull();
22
+ });
23
+
24
+ it('renders upload warning when autoUpload is disabled', () => {
25
+ render(
26
+ <SettingsWarning
27
+ autoUpload={false}
28
+ hostObfuscation={false}
29
+ isCloudConnector
30
+ />
31
+ );
32
+ expect(
33
+ screen.getByText(/inventory auto-upload is disabled/)
34
+ ).toBeTruthy();
35
+ });
36
+
37
+ it('renders obfuscation warning when hostObfuscation is enabled', () => {
38
+ render(
39
+ <SettingsWarning autoUpload hostObfuscation isCloudConnector />
40
+ );
41
+ expect(
42
+ screen.getByText(/obfuscating host names setting is enabled/)
43
+ ).toBeTruthy();
44
+ });
45
+
46
+ it('renders both warnings when both conditions met', () => {
47
+ render(
48
+ <SettingsWarning
49
+ autoUpload={false}
50
+ hostObfuscation
51
+ isCloudConnector
52
+ />
53
+ );
54
+ expect(
55
+ screen.getByText(/inventory auto-upload is disabled/)
56
+ ).toBeTruthy();
57
+ expect(
58
+ screen.getByText(/obfuscating host names setting is enabled/)
59
+ ).toBeTruthy();
60
+ });
61
+ });
@@ -1,13 +1,27 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
- import { noop } from 'foremanReact/common/helpers';
3
-
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
4
3
  import SyncButton from '../SyncButton';
5
4
 
6
- const fixtures = {
7
- 'render with Props': { handleSync: noop },
8
- };
9
-
10
5
  describe('SyncButton', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(SyncButton, fixtures));
6
+ it('renders the sync button text', () => {
7
+ render(<SyncButton handleSync={jest.fn()} />);
8
+ expect(screen.getByRole('button', { name: /Sync all inventory status/ })).toBeTruthy();
9
+ });
10
+
11
+ it('calls handleSync on click', () => {
12
+ const handleSync = jest.fn();
13
+ render(<SyncButton handleSync={handleSync} />);
14
+ fireEvent.click(screen.getByRole('button'));
15
+ expect(handleSync).toHaveBeenCalledTimes(1);
16
+ });
17
+
18
+ it('disables button when status is PENDING', () => {
19
+ render(<SyncButton handleSync={jest.fn()} status="PENDING" />);
20
+ expect(screen.getByRole('button').disabled).toBe(true);
21
+ });
22
+
23
+ it('enables button when status is not PENDING', () => {
24
+ render(<SyncButton handleSync={jest.fn()} status="RESOLVED" />);
25
+ expect(screen.getByRole('button').disabled).toBe(false);
26
+ });
13
27
  });
@@ -1,27 +1,29 @@
1
- import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2
1
  import { selectTaskStatus } from '../SyncButtonSelectors';
3
2
 
4
- const state = {
3
+ const buildState = result => ({
5
4
  API: {
6
5
  INVENTORY_SYNC_TASK_UPDATE: {
7
6
  response: {
8
- endedAt: '2021-03-08T14:27:30.718+02:00',
9
- output: {
10
- host_statuses: {
11
- sync: 0,
12
- disconnect: 2,
13
- },
14
- },
15
- result: 'pending',
7
+ result,
16
8
  },
17
- status: 'RESOLVED',
18
9
  },
19
10
  },
20
- };
11
+ });
21
12
 
22
- const fixtures = {
23
- 'should return InventorySync status': () => selectTaskStatus(state),
24
- };
13
+ describe('SyncButton selectors', () => {
14
+ it('uppercases the result string', () => {
15
+ expect(selectTaskStatus(buildState('pending'))).toBe('PENDING');
16
+ });
25
17
 
26
- describe('SyncButton selectors', () =>
27
- testSelectorsSnapshotWithFixtures(fixtures));
18
+ it('handles other result strings', () => {
19
+ expect(selectTaskStatus(buildState('success'))).toBe('SUCCESS');
20
+ });
21
+
22
+ it('returns null when result is not a string', () => {
23
+ expect(selectTaskStatus(buildState(null))).toBeNull();
24
+ });
25
+
26
+ it('returns null when result is undefined', () => {
27
+ expect(selectTaskStatus(buildState(undefined))).toBeNull();
28
+ });
29
+ });
@@ -1,52 +1,40 @@
1
1
  import React from 'react';
2
- import { IntegrationTestHelper } from '@theforeman/test';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
+ import { Provider } from 'react-redux';
4
+ import configureMockStore from 'redux-mock-store';
5
+ import thunk from 'redux-thunk';
3
6
  import * as API from 'foremanReact/redux/API';
4
- import { noop } from 'foremanReact/common/helpers';
5
- import SyncButton from '../index';
7
+ import ConnectedSyncButton from '../index';
6
8
  import { successResponse } from './SyncButtonFixtures';
7
- import {
8
- INVENTORY_SYNC,
9
- INVENTORY_SYNC_TASK_UPDATE,
10
- } from '../SyncButtonConstants';
9
+ import { INVENTORY_SYNC } from '../SyncButtonConstants';
11
10
 
12
11
  jest.spyOn(API, 'post');
13
- jest.spyOn(API, 'get');
12
+
13
+ const mockStore = configureMockStore([thunk]);
14
14
 
15
15
  describe('SyncButton integration test', () => {
16
- it('Successful task was triggered on the server resulting in an info toast and polling on the task', async () => {
17
- API.post.mockImplementation(({ handleSuccess = noop, key, ...action }) => {
18
- if (key === INVENTORY_SYNC) {
16
+ it('dispatches sync action when button is clicked', () => {
17
+ API.post.mockImplementation(({ handleSuccess, key, ...action }) => {
18
+ if (key === INVENTORY_SYNC && handleSuccess) {
19
19
  handleSuccess(successResponse);
20
20
  }
21
21
  return { type: 'API_POST', ...action };
22
22
  });
23
- API.get.mockImplementation(({ handleSuccess = noop, key, ...action }) => {
24
- if (key === INVENTORY_SYNC_TASK_UPDATE) {
25
- handleSuccess(
26
- {
27
- data: {
28
- endedAt: '2021-03-22T15:59:02.468+02:00',
29
- output: {
30
- host_statuses: {
31
- sync: 0,
32
- disconnect: 2,
33
- user_omitted: 1,
34
- },
35
- },
36
- result: 'success',
37
- },
38
- },
39
- jest.fn
40
- );
41
- }
42
- return { type: 'API_GET', ...action };
23
+
24
+ const store = mockStore({
25
+ API: {},
43
26
  });
44
27
 
45
- const integrationTestHelper = new IntegrationTestHelper();
46
- const wrapper = integrationTestHelper.mount(<SyncButton />);
47
- const instance = wrapper.find('SyncButton').instance();
48
- instance.props.handleSync();
49
- await IntegrationTestHelper.flushAllPromises();
50
- integrationTestHelper.takeActionsSnapshot('handleSync was called');
28
+ render(
29
+ <Provider store={store}>
30
+ <ConnectedSyncButton />
31
+ </Provider>
32
+ );
33
+
34
+ fireEvent.click(screen.getByRole('button'));
35
+
36
+ const actions = store.getActions();
37
+ const syncAction = actions.find(a => a.type === 'API_POST');
38
+ expect(syncAction).toBeTruthy();
51
39
  });
52
40
  });
@@ -1,13 +1,33 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { IntlProvider } from 'react-intl';
3
4
  import ScheduledRun from '../ScheduledRun';
4
- import { props } from '../ScheduledRun.fixtures';
5
5
 
6
- const fixtures = {
7
- 'render with Props': props,
8
- };
6
+ const renderWithIntl = ui =>
7
+ render(<IntlProvider locale="en">{ui}</IntlProvider>);
9
8
 
10
9
  describe('ScheduledRun', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(ScheduledRun, fixtures));
10
+ it('renders next run info when autoUploadEnabled and date are set', () => {
11
+ renderWithIntl(
12
+ <ScheduledRun date="2019-08-21T16:14:16.520+03:00" autoUploadEnabled />
13
+ );
14
+ expect(screen.getByText(/Next run:/)).toBeTruthy();
15
+ });
16
+
17
+ it('renders nothing when autoUploadEnabled is false', () => {
18
+ renderWithIntl(
19
+ <ScheduledRun
20
+ date="2019-08-21T16:14:16.520+03:00"
21
+ autoUploadEnabled={false}
22
+ />
23
+ );
24
+ expect(screen.queryByText(/Next run:/)).toBeNull();
25
+ });
26
+
27
+ it('renders nothing when date is null', () => {
28
+ renderWithIntl(
29
+ <ScheduledRun date={null} autoUploadEnabled />
30
+ );
31
+ expect(screen.queryByText(/Next run:/)).toBeNull();
32
+ });
13
33
  });
@@ -1,13 +1,30 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
3
  import StatusChart from '../StatusChart';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
5
+ jest.mock('patternfly-react', () => ({
6
+ Grid: { Col: ({ children }) => <div>{children}</div> },
7
+ DonutChart: ({ title }) => (
8
+ <div data-testid="donut-chart">
9
+ <span>{title?.primary}</span>
10
+ <span>{title?.secondary}</span>
11
+ </div>
12
+ ),
13
+ }));
9
14
 
10
15
  describe('StatusChart', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(StatusChart, fixtures));
16
+ it('renders the status chart container', () => {
17
+ const { container } = render(<StatusChart />);
18
+ expect(container.querySelector('.status-chart')).toBeTruthy();
19
+ });
20
+
21
+ it('passes the completed percentage to the chart', () => {
22
+ const { getByText } = render(<StatusChart completed={75} />);
23
+ expect(getByText('75%')).toBeTruthy();
24
+ });
25
+
26
+ it('shows Completed label', () => {
27
+ const { getByText } = render(<StatusChart completed={50} />);
28
+ expect(getByText('Completed')).toBeTruthy();
29
+ });
13
30
  });
@@ -1,13 +1,15 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import TabContainer from '../TabContainer';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('TabContainer', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(TabContainer, fixtures));
6
+ it('renders children', () => {
7
+ render(<TabContainer><span>Tab content</span></TabContainer>);
8
+ expect(screen.getByText('Tab content')).toBeTruthy();
9
+ });
10
+
11
+ it('renders with custom className', () => {
12
+ const { container } = render(<TabContainer className="my-tab" />);
13
+ expect(container.querySelector('.my-tab')).toBeTruthy();
14
+ });
13
15
  });
@@ -1,13 +1,15 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import TabFooter from '../TabFooter';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('TabFooter', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(TabFooter, fixtures));
6
+ it('renders children', () => {
7
+ render(<TabFooter><span>Footer content</span></TabFooter>);
8
+ expect(screen.getByText('Footer content')).toBeTruthy();
9
+ });
10
+
11
+ it('renders with the tab-footer class', () => {
12
+ const { container } = render(<TabFooter />);
13
+ expect(container.querySelector('.tab-footer')).toBeTruthy();
14
+ });
13
15
  });
@@ -1,17 +1,38 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
- import { noop } from 'foremanReact/common/helpers';
3
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
4
3
  import InventoryAutoUpload from '../InventoryAutoUpload';
5
4
 
6
- const fixtures = {
7
- 'render with props': {
8
- autoUploadEnabled: true,
9
- setSetting: noop,
10
- getSettings: noop,
11
- },
12
- };
5
+ jest.mock(
6
+ '../../../Components/InventorySettings/InventorySettings',
7
+ () => () => <div data-testid="inventory-settings">InventorySettings</div>
8
+ );
13
9
 
14
10
  describe('InventoryAutoUpload', () => {
15
- describe('rendering', () =>
16
- testComponentSnapshotsWithFixtures(InventoryAutoUpload, fixtures));
11
+ const buildProps = (overrides = {}) => ({
12
+ autoUploadEnabled: true,
13
+ setSetting: jest.fn(),
14
+ getSettings: jest.fn(),
15
+ ...overrides,
16
+ });
17
+
18
+ it('renders the heading', () => {
19
+ render(<InventoryAutoUpload {...buildProps()} />);
20
+ expect(screen.getByText('Red Hat Cloud Inventory')).toBeTruthy();
21
+ });
22
+
23
+ it('renders the auto upload switcher', () => {
24
+ render(<InventoryAutoUpload {...buildProps()} />);
25
+ expect(screen.getByText('Inventory Auto Upload')).toBeTruthy();
26
+ });
27
+
28
+ it('renders the advanced settings button', () => {
29
+ render(<InventoryAutoUpload {...buildProps()} />);
30
+ expect(screen.getByRole('button', { name: /Show Advanced Settings/ })).toBeTruthy();
31
+ });
32
+
33
+ it('calls getSettings on mount', () => {
34
+ const props = buildProps();
35
+ render(<InventoryAutoUpload {...props} />);
36
+ expect(props.getSettings).toHaveBeenCalled();
37
+ });
17
38
  });
@@ -1,10 +1,23 @@
1
- import { testSelectorsSnapshotWithFixtures } from '@theforeman/test';
2
- import { inventoryUrl, getInventoryDocsUrl } from '../ForemanInventoryHelpers';
1
+ import { isExitCodeLoading } from '../ForemanInventoryHelpers';
3
2
 
4
- const fixtures = {
5
- 'should return inventory Url': () => inventoryUrl('test_path'),
6
- 'should return inventory docs url': () => getInventoryDocsUrl(),
7
- };
3
+ describe('ForemanInventoryUpload helpers', () => {
4
+ describe('isExitCodeLoading', () => {
5
+ it('returns true when exit code contains "running"', () => {
6
+ expect(isExitCodeLoading('currently running')).toBe(true);
7
+ });
8
8
 
9
- describe('ForemanInventoryUpload helpers', () =>
10
- testSelectorsSnapshotWithFixtures(fixtures));
9
+ it('returns true when exit code contains "restarting"', () => {
10
+ expect(isExitCodeLoading('restarting now')).toBe(true);
11
+ });
12
+
13
+ it('is case-insensitive', () => {
14
+ expect(isExitCodeLoading('RUNNING')).toBe(true);
15
+ expect(isExitCodeLoading('Restarting')).toBe(true);
16
+ });
17
+
18
+ it('returns false when exit code contains neither', () => {
19
+ expect(isExitCodeLoading('exit 0')).toBe(false);
20
+ expect(isExitCodeLoading('completed')).toBe(false);
21
+ });
22
+ });
23
+ });
@@ -1,62 +1,76 @@
1
- import { testActionSnapshotWithFixtures } from '@theforeman/test';
2
1
  import { API } from 'foremanReact/redux/API';
3
2
  import {
4
3
  getInsightsSyncSettings,
5
4
  setInsightsSyncEnabled,
6
5
  } from '../InsightsSettingsActions';
7
- import { rhCloudStateWrapper } from '../../../../ForemanRhCloudTestHelpers';
8
-
9
- const serverMock = {
10
- data: { insightsSyncEnabled: true },
11
- };
6
+ import {
7
+ INSIGHTS_SYNC_SETTING_SET,
8
+ INSIGHTS_SYNC_SETTINGS_GET_SUCCESS,
9
+ } from '../InsightsSettingsConstants';
12
10
 
13
11
  jest.mock('foremanReact/redux/API');
14
- API.get.mockImplementation(() => serverMock);
15
- API.patch.mockImplementation(() => serverMock);
16
-
17
- const runWithGetState = (state, action, params) => dispatch => {
18
- const getState = () => rhCloudStateWrapper({ InsightsCloudSync: state });
19
- action(params)(dispatch, getState);
20
- };
21
-
22
- const fixtures = {
23
- 'should generate INSIGHTS_SYNC_SETTINGS_GET_SUCCESS action': () =>
24
- runWithGetState({ settings: {} }, getInsightsSyncSettings, {}),
25
- 'should handle getInsightsSyncSettings with error ': () => {
26
- API.get.mockImplementationOnce(() =>
27
- Promise.reject(new Error('Network error!'))
28
- );
29
- return runWithGetState({ settings: {} }, getInsightsSyncSettings, {});
30
- },
31
- 'should generate INSIGHTS_SYNC_SETTING_SET action': () =>
32
- runWithGetState(
33
- { settings: { insightsSyncEnabled: false } },
34
- setInsightsSyncEnabled,
35
- true
36
- ),
37
- 'should handle setInsightsSyncEnabled with error ': () => {
38
- API.patch.mockImplementationOnce(() =>
39
- Promise.reject(new Error('Network error!'))
40
- );
41
- return runWithGetState(
42
- { settings: { insightsSyncEnabled: false } },
43
- setInsightsSyncEnabled,
44
- true
45
- );
46
- },
47
- };
48
12
 
49
13
  describe('InsightsSettings actions', () => {
50
- const { location } = window;
14
+ let dispatch;
51
15
 
52
- beforeAll(() => {
53
- delete window.location;
54
- window.location = { href: jest.fn() };
16
+ beforeEach(() => {
17
+ dispatch = jest.fn();
18
+ jest.clearAllMocks();
55
19
  });
56
20
 
57
- afterAll(() => {
58
- window.location = location;
21
+ describe('getInsightsSyncSettings', () => {
22
+ it('dispatches success action with settings on success', async () => {
23
+ API.get.mockResolvedValue({ data: { insightsSyncEnabled: true } });
24
+
25
+ await getInsightsSyncSettings()(dispatch);
26
+
27
+ expect(API.get).toHaveBeenCalledWith('/insights_cloud/settings');
28
+ expect(dispatch).toHaveBeenCalledWith({
29
+ type: INSIGHTS_SYNC_SETTINGS_GET_SUCCESS,
30
+ payload: { settings: { insightsSyncEnabled: true } },
31
+ });
32
+ });
33
+
34
+ it('dispatches error toast on failure', async () => {
35
+ API.get.mockRejectedValue(new Error('Network error!'));
36
+
37
+ await getInsightsSyncSettings()(dispatch);
38
+
39
+ expect(dispatch).toHaveBeenCalledWith({
40
+ type: 'TOASTS_ADD',
41
+ payload: {
42
+ message: { sticky: true, type: 'error', message: 'Network error!' },
43
+ },
44
+ });
45
+ });
59
46
  });
60
47
 
61
- return testActionSnapshotWithFixtures(fixtures);
48
+ describe('setInsightsSyncEnabled', () => {
49
+ it('dispatches setting set action on success', async () => {
50
+ API.patch.mockResolvedValue({ data: { insightsSyncEnabled: true } });
51
+
52
+ await setInsightsSyncEnabled(true)(dispatch);
53
+
54
+ expect(API.patch).toHaveBeenCalledWith('/insights_cloud/settings', {
55
+ insightsSyncEnabled: true,
56
+ });
57
+ expect(dispatch).toHaveBeenCalledWith({
58
+ type: INSIGHTS_SYNC_SETTING_SET,
59
+ payload: { settings: { insightsSyncEnabled: true } },
60
+ });
61
+ });
62
+
63
+ it('dispatches error toast on failure', async () => {
64
+ API.patch.mockRejectedValue(new Error('Network error!'));
65
+
66
+ await setInsightsSyncEnabled(true)(dispatch);
67
+
68
+ expect(dispatch).toHaveBeenCalledWith({
69
+ type: 'TOASTS_ADD',
70
+ payload: {
71
+ message: { sticky: true, type: 'error', message: 'Network error!' },
72
+ },
73
+ });
74
+ });
75
+ });
62
76
  });