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
@@ -0,0 +1,50 @@
1
+ require 'test_plugin_helper'
2
+ require 'foreman_tasks/test_helpers'
3
+
4
+ class OrganizationDestroyExtensionsTest < ActiveSupport::TestCase
5
+ include Dynflow::Testing
6
+
7
+ setup do
8
+ User.current = User.find_by(login: 'secret_admin')
9
+
10
+ @organization = stub
11
+ @organization.stubs(:label).returns('test_org')
12
+ @organization.stubs(:id).returns(1)
13
+ @organization.stubs(:validate_destroy).returns([])
14
+ @organization.stubs(:products).returns([])
15
+ @organization.stubs(:activation_keys).returns([])
16
+ @organization.stubs(:content_views).returns(stub(:non_default => []))
17
+ @organization.stubs(:default_content_view).returns(stub(:content_view_environments => []))
18
+ @organization.stubs(:promotion_paths).returns([])
19
+ @organization.stubs(:providers).returns([])
20
+ @organization.stubs(:library).returns(stub(:destroy! => true))
21
+
22
+ where_clause = mock
23
+ where_clause.stubs(:where).returns([])
24
+ ::Host.stubs(:unscoped).returns(where_clause)
25
+ end
26
+
27
+ teardown do
28
+ ForemanRhCloud.unstub(:with_iop_smart_proxy?)
29
+ end
30
+
31
+ test 'plans DestroyOrganizationHbiHostsJob when in IoP mode' do
32
+ ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
33
+
34
+ action = create_action(::Actions::Katello::Organization::Destroy)
35
+ action.stubs(:action_subject).with(@organization)
36
+ plan_action(action, @organization)
37
+
38
+ assert_action_planned_with(action, ForemanInventoryUpload::Async::DestroyOrganizationHbiHostsJob, @organization.id)
39
+ end
40
+
41
+ test 'does not plan DestroyOrganizationHbiHostsJob when not in IoP mode' do
42
+ ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
43
+
44
+ action = create_action(::Actions::Katello::Organization::Destroy)
45
+ action.stubs(:action_subject).with(@organization)
46
+ plan_action(action, @organization)
47
+
48
+ refute_action_planned(action, ForemanInventoryUpload::Async::DestroyOrganizationHbiHostsJob)
49
+ end
50
+ end
@@ -1,8 +1,8 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class URLRemediationsRetrieverTest < ActiveSupport::TestCase
4
- test 'Calls the given url' do
5
- retreiver = ForemanRhCloud::URLRemediationsRetriever.new(
4
+ test 'Calls the given url with GET when no hosts in URL' do
5
+ retriever = ForemanRhCloud::URLRemediationsRetriever.new(
6
6
  organization_id: FactoryBot.create(:organization).id,
7
7
  url: 'http://test.example.com',
8
8
  payload: 'TEST_PAYLOAD',
@@ -11,19 +11,96 @@ class URLRemediationsRetrieverTest < ActiveSupport::TestCase
11
11
  }
12
12
  )
13
13
 
14
- retreiver.stubs(:cert_auth_available?).returns(true)
14
+ retriever.stubs(:cert_auth_available?).returns(true)
15
15
 
16
16
  response = mock('response')
17
17
  response.stubs(:body).returns('TEST_RESPONSE')
18
- retreiver.expects(:execute_cloud_request).with do |params|
18
+ retriever.expects(:execute_cloud_request).with do |params|
19
19
  params[:method] == :get &&
20
20
  params[:url] == 'http://test.example.com' &&
21
21
  params[:headers][:custom1] == 'TEST_HEADER' &&
22
22
  params[:payload] == "\"TEST_PAYLOAD\""
23
23
  end.returns(response)
24
24
 
25
- actual = retreiver.create_playbook
25
+ actual = retriever.create_playbook
26
26
 
27
27
  assert_equal 'TEST_RESPONSE', actual
28
28
  end
29
+
30
+ test 'Uses POST with hosts in body when URL contains hosts query param' do
31
+ retriever = ForemanRhCloud::URLRemediationsRetriever.new(
32
+ organization_id: FactoryBot.create(:organization).id,
33
+ url: 'http://test.example.com/api/remediations/1234/playbook?hosts=uuid-1,uuid-2,uuid-3'
34
+ )
35
+
36
+ retriever.stubs(:cert_auth_available?).returns(true)
37
+
38
+ response = mock('response')
39
+ response.stubs(:body).returns('TEST_PLAYBOOK')
40
+ retriever.expects(:execute_cloud_request).with do |params|
41
+ params[:method] == :post &&
42
+ params[:url] == 'http://test.example.com/api/remediations/1234/playbook' &&
43
+ JSON.parse(params[:payload]) == ['uuid-1', 'uuid-2', 'uuid-3']
44
+ end.returns(response)
45
+
46
+ actual = retriever.create_playbook
47
+
48
+ assert_equal 'TEST_PLAYBOOK', actual
49
+ end
50
+
51
+ test 'Preserves other query params when extracting hosts' do
52
+ retriever = ForemanRhCloud::URLRemediationsRetriever.new(
53
+ organization_id: FactoryBot.create(:organization).id,
54
+ url: 'http://test.example.com/api/remediations/1234/playbook?hosts=uuid-1,uuid-2&localhost=false'
55
+ )
56
+
57
+ retriever.stubs(:cert_auth_available?).returns(true)
58
+
59
+ response = mock('response')
60
+ response.stubs(:body).returns('TEST_PLAYBOOK')
61
+ retriever.expects(:execute_cloud_request).with do |params|
62
+ params[:method] == :post &&
63
+ params[:url].include?('localhost=false') &&
64
+ !params[:url].include?('hosts=') &&
65
+ JSON.parse(params[:payload]) == ['uuid-1', 'uuid-2']
66
+ end.returns(response)
67
+
68
+ retriever.create_playbook
69
+ end
70
+
71
+ test 'Merges multiple hosts query params into a single array' do
72
+ retriever = ForemanRhCloud::URLRemediationsRetriever.new(
73
+ organization_id: FactoryBot.create(:organization).id,
74
+ url: 'http://test.example.com/api/remediations/1234/playbook?hosts=uuid-1&hosts=uuid-2'
75
+ )
76
+
77
+ retriever.stubs(:cert_auth_available?).returns(true)
78
+
79
+ response = mock('response')
80
+ response.stubs(:body).returns('TEST_PLAYBOOK')
81
+ retriever.expects(:execute_cloud_request).with do |params|
82
+ params[:method] == :post &&
83
+ params[:url] == 'http://test.example.com/api/remediations/1234/playbook' &&
84
+ JSON.parse(params[:payload]) == ['uuid-1', 'uuid-2']
85
+ end.returns(response)
86
+
87
+ retriever.create_playbook
88
+ end
89
+
90
+ test 'Falls back to GET when hosts query param is empty' do
91
+ retriever = ForemanRhCloud::URLRemediationsRetriever.new(
92
+ organization_id: FactoryBot.create(:organization).id,
93
+ url: 'http://test.example.com/api/remediations/1234/playbook?hosts='
94
+ )
95
+
96
+ retriever.stubs(:cert_auth_available?).returns(true)
97
+
98
+ response = mock('response')
99
+ response.stubs(:body).returns('TEST_PLAYBOOK')
100
+ retriever.expects(:execute_cloud_request).with do |params|
101
+ params[:method] == :get
102
+ end.returns(response)
103
+
104
+ retriever.create_playbook
105
+ end
29
106
  end
@@ -1,13 +1,14 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import EmptyResults from '../EmptyResults';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('EmptyResults', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(EmptyResults, fixtures));
6
+ it('renders the empty results message', () => {
7
+ render(<EmptyResults />);
8
+ expect(
9
+ screen.getByText(
10
+ "Oops! Couldn't find organization that matches your query"
11
+ )
12
+ ).toBeTruthy();
13
+ });
13
14
  });
@@ -1,13 +1,17 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import EmptyState from '../EmptyState';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('EmptyState', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(EmptyState, fixtures));
6
+ it('renders fetching data message', () => {
7
+ render(<EmptyState />);
8
+ expect(
9
+ screen.getByText('Fetching data about your accounts')
10
+ ).toBeTruthy();
11
+ });
12
+
13
+ it('renders loading indicator', () => {
14
+ render(<EmptyState />);
15
+ expect(screen.getByText('Loading...')).toBeTruthy();
16
+ });
13
17
  });
@@ -1,13 +1,24 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import ErrorState from '../ErrorState';
4
4
 
5
- const fixtures = {
6
- 'render without Props': {},
7
- /** fixtures, props for the component */
8
- };
9
-
10
5
  describe('ErrorState', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(ErrorState, fixtures));
6
+ it('renders the error message heading', () => {
7
+ render(<ErrorState error="Something went wrong" />);
8
+ expect(
9
+ screen.getByText(
10
+ 'Encountered an error while trying to access the server:'
11
+ )
12
+ ).toBeTruthy();
13
+ });
14
+
15
+ it('renders the error description', () => {
16
+ render(<ErrorState error="Connection refused" />);
17
+ expect(screen.getByText('Connection refused')).toBeTruthy();
18
+ });
19
+
20
+ it('renders with empty error by default', () => {
21
+ const { container } = render(<ErrorState />);
22
+ expect(container.querySelector('.error_description')).toBeTruthy();
23
+ });
13
24
  });
@@ -1,13 +1,36 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { Accordion } from '@patternfly/react-core';
3
4
  import ListItem from '../ListItem';
4
- import { props } from '../ListItem.fixtures';
5
5
 
6
- const fixtures = {
7
- 'render with Props': props,
8
- };
6
+ jest.mock('../../../../Dashboard', () => () => null);
7
+
8
+ const renderListItem = props =>
9
+ render(
10
+ <Accordion>
11
+ <ListItem {...props} />
12
+ </Accordion>
13
+ );
9
14
 
10
15
  describe('ListItem', () => {
11
- describe('rendering', () =>
12
- testComponentSnapshotsWithFixtures(ListItem, fixtures));
16
+ const defaultProps = {
17
+ label: 'test-org',
18
+ account: {
19
+ generated_status: 'unknown',
20
+ uploaded_status: 'unknown',
21
+ id: 1,
22
+ },
23
+ };
24
+
25
+ it('renders the account label', () => {
26
+ renderListItem(defaultProps);
27
+ expect(screen.getByText('test-org')).toBeTruthy();
28
+ });
29
+
30
+ it('renders Generated and Uploaded status labels', () => {
31
+ renderListItem(defaultProps);
32
+ expect(screen.getByText('Generated')).toBeTruthy();
33
+ expect(screen.getByText('Uploaded')).toBeTruthy();
34
+ });
35
+
13
36
  });
@@ -1,14 +1,30 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import ListItemStatus from '../ListItemStatus';
4
- import { props } from '../ListItemStatus.fixtures';
5
-
6
- const fixtures = {
7
- 'render without Props': {},
8
- 'render with Props': props,
9
- };
10
4
 
11
5
  describe('ListItemStatus', () => {
12
- describe('rendering', () =>
13
- testComponentSnapshotsWithFixtures(ListItemStatus, fixtures));
6
+ it('renders Generated and Uploaded labels', () => {
7
+ render(<ListItemStatus />);
8
+ expect(screen.getByText('Generated')).toBeTruthy();
9
+ expect(screen.getByText('Uploaded')).toBeTruthy();
10
+ });
11
+
12
+ it('shows dash placeholders for unknown status', () => {
13
+ render(
14
+ <ListItemStatus
15
+ account={{ generated_status: 'unknown', uploaded_status: 'unknown' }}
16
+ />
17
+ );
18
+ expect(screen.getAllByText('--')).toHaveLength(2);
19
+ });
20
+
21
+ it('renders with provided account statuses', () => {
22
+ render(
23
+ <ListItemStatus
24
+ account={{ generated_status: 'success', uploaded_status: 'running' }}
25
+ />
26
+ );
27
+ expect(screen.getByText('Generated')).toBeTruthy();
28
+ expect(screen.getByText('Uploaded')).toBeTruthy();
29
+ });
14
30
  });
@@ -1,14 +1,38 @@
1
- import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
-
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
3
  import AccountList from '../AccountList';
4
- import { props } from '../AccountList.fixtures';
4
+ import { accounts } from '../AccountList.fixtures';
5
5
 
6
- const fixtures = {
7
- 'render with props': props,
8
- 'show empty results': { ...props, filterTerm: 'not_matching_term' },
9
- };
6
+ jest.mock('../Components/ListItem', () => ({ label }) => (
7
+ <div>{label}</div>
8
+ ));
10
9
 
11
10
  describe('AccountList', () => {
12
- describe('rendering', () =>
13
- testComponentSnapshotsWithFixtures(AccountList, fixtures));
11
+ it('renders account labels', () => {
12
+ render(<AccountList accounts={accounts} />);
13
+ Object.keys(accounts).forEach(label => {
14
+ expect(screen.getByText(label)).toBeTruthy();
15
+ });
16
+ });
17
+
18
+ it('shows empty results when filterTerm matches nothing', () => {
19
+ render(<AccountList accounts={accounts} filterTerm="not_matching_term" />);
20
+ expect(
21
+ screen.getByText(
22
+ "Oops! Couldn't find organization that matches your query"
23
+ )
24
+ ).toBeTruthy();
25
+ });
26
+
27
+ it('shows empty state when accounts are empty', () => {
28
+ render(<AccountList accounts={{}} />);
29
+ expect(
30
+ screen.getByText('Fetching data about your accounts')
31
+ ).toBeTruthy();
32
+ });
33
+
34
+ it('shows error state when error is present', () => {
35
+ render(<AccountList accounts={{}} error="Server error" />);
36
+ expect(screen.getByText('Server error')).toBeTruthy();
37
+ });
14
38
  });
@@ -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
  });