foreman_rh_cloud 14.1.2 → 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 (111) hide show
  1. checksums.yaml +4 -4
  2. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +26 -4
  3. data/lib/foreman_inventory_upload.rb +8 -1
  4. data/lib/foreman_rh_cloud/version.rb +1 -1
  5. data/lib/foreman_rh_cloud.rb +36 -9
  6. data/lib/insights_cloud/async/insights_generate_notifications.rb +10 -1
  7. data/lib/inventory_sync/async/inventory_self_host_sync.rb +12 -2
  8. data/package.json +1 -1
  9. data/test/jobs/insights_generate_notifications_test.rb +26 -0
  10. data/test/jobs/inventory_self_host_sync_test.rb +9 -0
  11. data/test/unit/foreman_rh_cloud_self_host_test.rb +50 -2
  12. data/test/unit/metadata_generator_test.rb +24 -1
  13. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/EmptyResults.test.js +10 -9
  14. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -9
  15. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +20 -9
  16. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +31 -8
  17. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +26 -10
  18. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +33 -9
  19. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +55 -35
  20. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -9
  21. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilter.test.js +12 -15
  22. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/integration.test.js +32 -12
  23. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageTitle.test.js +14 -7
  24. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorButton.test.js +47 -18
  25. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/SettingsWarning.test.js +58 -15
  26. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButton.test.js +23 -9
  27. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/SyncButtonSelectors.test.js +19 -17
  28. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +25 -37
  29. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +28 -8
  30. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +25 -8
  31. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +11 -9
  32. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +11 -9
  33. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +33 -12
  34. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryHelpers.test.js +21 -8
  35. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsActions.test.js +61 -47
  36. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +48 -4
  37. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableActions.test.js +126 -35
  38. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTableSelectors.test.js +90 -24
  39. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +79 -21
  40. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncActions.test.js +31 -6
  41. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTab.test.js +42 -9
  42. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +91 -53
  43. data/webpack/common/Switcher/__tests__/HelpLabel.test.js +25 -10
  44. data/webpack/common/Switcher/__tests__/SwitcherPF4.test.js +41 -10
  45. metadata +3 -67
  46. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyResults/__tests__/__snapshots__/EmptyResults.test.js.snap +0 -18
  47. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +0 -25
  48. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +0 -20
  49. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +0 -47
  50. data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +0 -59
  51. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +0 -34
  52. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +0 -14
  53. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +0 -25
  54. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +0 -49
  55. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +0 -86
  56. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +0 -75
  57. data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +0 -46
  58. data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +0 -26
  59. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterActions.test.js +0 -14
  60. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterReducer.test.js +0 -28
  61. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/InventoryFilterSelectors.test.js +0 -21
  62. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilter.test.js.snap +0 -21
  63. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterActions.test.js.snap +0 -17
  64. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterReducer.test.js.snap +0 -19
  65. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/InventoryFilterSelectors.test.js.snap +0 -9
  66. data/webpack/ForemanInventoryUpload/Components/InventoryFilter/__tests__/__snapshots__/integration.test.js.snap +0 -43
  67. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/AdvancedSettingActions.test.js +0 -9
  68. data/webpack/ForemanInventoryUpload/Components/InventorySettings/AdvancedSetting/__tests__/__snapshots__/AdvancedSettingActions.test.js.snap +0 -18
  69. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/InventorySettingsActions.test.js +0 -14
  70. data/webpack/ForemanInventoryUpload/Components/InventorySettings/__tests__/__snapshots__/InventorySettingsActions.test.js.snap +0 -26
  71. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +0 -68
  72. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/CloudConnectorActions.test.js +0 -9
  73. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorActions.test.js.snap +0 -11
  74. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/CloudConnectorButton/__tests__/__snapshots__/CloudConnectorButton.test.js.snap +0 -59
  75. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SettingsWarning/__snapshots__/SettingsWarning.test.js.snap +0 -32
  76. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButton.test.js.snap +0 -15
  77. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/SyncButtonSelectors.test.js.snap +0 -3
  78. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -58
  79. data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +0 -23
  80. data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +0 -74
  81. data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +0 -18
  82. data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +0 -12
  83. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/__snapshots__/InventoryAutoUpload.test.js.snap +0 -96
  84. data/webpack/ForemanInventoryUpload/__tests__/ForemanInventoryUpload.test.js +0 -10
  85. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +0 -5
  86. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryUpload.test.js.snap +0 -14
  87. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsReducer.test.js +0 -33
  88. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/InsightsSettingsSelectors.test.js +0 -21
  89. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsActions.test.js.snap +0 -65
  90. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsReducer.test.js.snap +0 -19
  91. data/webpack/InsightsCloudSync/Components/InsightsSettings/__tests__/__snapshots__/InsightsSettingsSelectors.test.js.snap +0 -9
  92. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +0 -131
  93. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableSelectors.test.js.snap +0 -87
  94. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +0 -10
  95. data/webpack/InsightsCloudSync/__tests__/InsightsCloudSyncHelpers.test.js +0 -9
  96. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +0 -15
  97. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncHelpers.test.js.snap +0 -3
  98. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabActions.test.js +0 -19
  99. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js +0 -26
  100. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js +0 -13
  101. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap +0 -34
  102. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap +0 -56
  103. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap +0 -32
  104. data/webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabSelectors.test.js.snap +0 -18
  105. data/webpack/__tests__/ForemanRhCloudSelectors.test.js +0 -22
  106. data/webpack/__tests__/ForemanRhCloudTestHelpers.test.js +0 -20
  107. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -19
  108. data/webpack/__tests__/__snapshots__/ForemanRhCloudSelectors.test.js.snap +0 -25
  109. data/webpack/__tests__/__snapshots__/ForemanRhCloudTestHelpers.test.js.snap +0 -39
  110. data/webpack/common/Switcher/__tests__/__snapshots__/HelpLabel.test.js.snap +0 -16
  111. data/webpack/common/Switcher/__tests__/__snapshots__/SwitcherPF4.test.js.snap +0 -24
@@ -1,5 +1,3 @@
1
- import { testReducerSnapshotWithFixtures } from '@theforeman/test';
2
-
3
1
  import {
4
2
  INVENTORY_ACCOUNT_STATUS_POLLING,
5
3
  INVENTORY_ACCOUNT_STATUS_POLLING_START,
@@ -14,45 +12,67 @@ import {
14
12
  accountID,
15
13
  processStatusName,
16
14
  pollingResponse,
15
+ accounts,
16
+ CloudConnectorStatus,
17
17
  } from '../AccountList.fixtures';
18
18
 
19
- const fixtures = {
20
- 'should return the initial state': {},
21
- 'should handle INVENTORY_ACCOUNT_STATUS_POLLING': {
22
- action: {
19
+ describe('AccountList reducer', () => {
20
+ it('returns the initial state', () => {
21
+ const state = reducer(undefined, { type: '@@INIT' });
22
+ expect(state.accounts).toEqual({});
23
+ expect(state.pollingProcessID).toBe(0);
24
+ expect(state.error).toBeNull();
25
+ });
26
+
27
+ it('handles INVENTORY_ACCOUNT_STATUS_POLLING', () => {
28
+ const state = reducer(undefined, {
23
29
  type: INVENTORY_ACCOUNT_STATUS_POLLING,
24
30
  payload: pollingResponse,
25
- },
26
- },
27
- 'should handle INVENTORY_ACCOUNT_STATUS_POLLING_ERROR': {
28
- action: {
31
+ });
32
+ expect(state.accounts).toEqual(accounts);
33
+ expect(state.CloudConnectorStatus).toEqual(CloudConnectorStatus);
34
+ expect(state.error).toBeNull();
35
+ });
36
+
37
+ it('handles INVENTORY_ACCOUNT_STATUS_POLLING_ERROR', () => {
38
+ const state = reducer(undefined, {
29
39
  type: INVENTORY_ACCOUNT_STATUS_POLLING_ERROR,
30
40
  payload: { error },
31
- },
32
- },
33
- 'should handle INVENTORY_ACCOUNT_STATUS_POLLING_START': {
34
- action: {
41
+ });
42
+ expect(state.accounts).toEqual({});
43
+ expect(state.error).toBe(error);
44
+ });
45
+
46
+ it('handles INVENTORY_ACCOUNT_STATUS_POLLING_START', () => {
47
+ const state = reducer(undefined, {
48
+ type: INVENTORY_ACCOUNT_STATUS_POLLING_START,
49
+ payload: { pollingProcessID },
50
+ });
51
+ expect(state.pollingProcessID).toBe(pollingProcessID);
52
+ });
53
+
54
+ it('handles INVENTORY_ACCOUNT_STATUS_POLLING_STOP (default case)', () => {
55
+ const prevState = reducer(undefined, {
35
56
  type: INVENTORY_ACCOUNT_STATUS_POLLING_START,
36
- payload: {
37
- pollingProcessID,
38
- },
39
- },
40
- },
41
- 'should handle INVENTORY_ACCOUNT_STATUS_POLLING_STOP': {
42
- action: {
57
+ payload: { pollingProcessID },
58
+ });
59
+ const state = reducer(prevState, {
43
60
  type: INVENTORY_ACCOUNT_STATUS_POLLING_STOP,
44
- },
45
- },
46
- 'should handle INVENTORY_PROCESS_RESTART': {
47
- action: {
48
- type: INVENTORY_PROCESS_RESTART,
49
- payload: {
50
- accountID,
51
- processStatusName,
52
- },
53
- },
54
- },
55
- };
61
+ });
62
+ expect(state.pollingProcessID).toBe(pollingProcessID);
63
+ expect(state.accounts).toEqual({});
64
+ expect(state.error).toBeNull();
65
+ });
56
66
 
57
- describe('AccountList reducer', () =>
58
- testReducerSnapshotWithFixtures(reducer, fixtures));
67
+ it('handles INVENTORY_PROCESS_RESTART', () => {
68
+ const stateWithAccounts = reducer(undefined, {
69
+ type: INVENTORY_ACCOUNT_STATUS_POLLING,
70
+ payload: pollingResponse,
71
+ });
72
+ const state = reducer(stateWithAccounts, {
73
+ type: INVENTORY_PROCESS_RESTART,
74
+ payload: { accountID, processStatusName },
75
+ });
76
+ expect(state.accounts[accountID][processStatusName]).toBe('Restarting...');
77
+ });
78
+ });
@@ -1,13 +1,17 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen, fireEvent } from '@testing-library/react';
3
3
  import FileDownload from '../FileDownload';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('FileDownload', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(FileDownload, fixtures));
6
+ it('renders the download button', () => {
7
+ render(<FileDownload />);
8
+ expect(screen.getByRole('button', { name: /Download Report/ })).toBeTruthy();
9
+ });
10
+
11
+ it('calls onClick when button is clicked', () => {
12
+ const onClick = jest.fn();
13
+ render(<FileDownload onClick={onClick} />);
14
+ fireEvent.click(screen.getByRole('button', { name: /Download Report/ }));
15
+ expect(onClick).toHaveBeenCalledTimes(1);
16
+ });
13
17
  });
@@ -1,20 +1,17 @@
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 InventoryFilter from '../InventoryFilter';
5
- import { filterTerm, organization } from '../InventoryFilter.fixtures';
6
4
 
7
- const fixtures = {
8
- 'render with props': {
9
- handleFilterChange: noop,
10
- handleFilterClear: noop,
11
- filterTerm,
12
- organization,
13
- },
14
- /** fixtures, props for the component */
15
- };
5
+ jest.mock('foremanReact/Root/Context/ForemanContext');
16
6
 
17
7
  describe('InventoryFilter', () => {
18
- describe('rendering', () =>
19
- testComponentSnapshotsWithFixtures(InventoryFilter, fixtures));
8
+ it('renders the filter input', () => {
9
+ render(<InventoryFilter />);
10
+ expect(screen.getByPlaceholderText('Filter..')).toBeTruthy();
11
+ });
12
+
13
+ it('displays the current filter term', () => {
14
+ render(<InventoryFilter filterTerm="test-filter" />);
15
+ expect(screen.getByDisplayValue('test-filter')).toBeTruthy();
16
+ });
20
17
  });
@@ -1,18 +1,38 @@
1
1
  import React from 'react';
2
- import { IntegrationTestHelper } from '@theforeman/test';
3
- import InventoryFilter from '../index';
4
- import reducers from '../../../../ForemanRhCloudReducers';
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';
6
+ import ConnectedInventoryFilter from '../index';
7
+ import { INVENTORY_FILTER_UPDATE } from '../InventoryFilterConstants';
8
+
9
+ jest.mock('foremanReact/Root/Context/ForemanContext');
10
+
11
+ const mockStore = configureMockStore([thunk]);
5
12
 
6
13
  describe('InventoryFilter integration test', () => {
7
- it('should flow', async () => {
8
- const integrationTestHelper = new IntegrationTestHelper(reducers);
9
- const wrapper = integrationTestHelper.mount(<InventoryFilter />);
10
- const input = wrapper.find('input[id="inventory_filter_input"]');
11
- input.simulate('change', { target: { value: 'some_new_filter' } });
12
- await IntegrationTestHelper.flushAllPromises();
13
- wrapper.update();
14
- integrationTestHelper.takeStoreAndLastActionSnapshot(
15
- 'filter have been updated'
14
+ it('dispatches filter update action on input change', () => {
15
+ const store = mockStore({
16
+ ForemanRhCloud: {
17
+ inventoryUpload: {
18
+ inventoryFilter: { filterTerm: '' },
19
+ },
20
+ },
21
+ });
22
+
23
+ render(
24
+ <Provider store={store}>
25
+ <ConnectedInventoryFilter />
26
+ </Provider>
27
+ );
28
+
29
+ const input = screen.getByPlaceholderText('Filter..');
30
+ fireEvent.change(input, { target: { value: 'some_new_filter' } });
31
+
32
+ const actions = store.getActions();
33
+ const filterAction = actions.find(
34
+ a => a.type === INVENTORY_FILTER_UPDATE && a.payload.filterTerm === 'some_new_filter'
16
35
  );
36
+ expect(filterAction).toBeTruthy();
17
37
  });
18
38
  });
@@ -1,12 +1,19 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import PageTitle from '../PageTitle';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- };
5
+ jest.mock('../components/CloudPingModal', () => () => (
6
+ <div data-testid="cloud-ping-modal">CloudPingModal</div>
7
+ ));
8
8
 
9
9
  describe('PageTitle', () => {
10
- describe('rendering', () =>
11
- testComponentSnapshotsWithFixtures(PageTitle, fixtures));
10
+ it('renders the page title', () => {
11
+ render(<PageTitle />);
12
+ expect(screen.getByText('Red Hat Inventory')).toBeTruthy();
13
+ });
14
+
15
+ it('renders the kebab dropdown', () => {
16
+ const { container } = render(<PageTitle />);
17
+ expect(container.querySelector('.title-dropdown')).toBeTruthy();
18
+ });
12
19
  });
@@ -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
  });