foreman_rh_cloud 13.2.9 → 14.0.1

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +61 -61
  3. data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +68 -68
  4. data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +9 -9
  5. data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +60 -60
  6. data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +60 -60
  7. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +0 -9
  8. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +2 -9
  9. data/app/models/concerns/rh_cloud_host.rb +3 -35
  10. data/app/models/insights_client_report_status.rb +1 -9
  11. data/app/models/inventory_sync/inventory_status.rb +4 -16
  12. data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +5 -12
  13. data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +2 -8
  14. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +0 -8
  15. data/lib/foreman_inventory_upload/generators/queries.rb +1 -1
  16. data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
  17. data/lib/foreman_rh_cloud/engine.rb +0 -1
  18. data/lib/foreman_rh_cloud/version.rb +1 -1
  19. data/lib/insights_cloud/async/vmaas_reposcan_sync.rb +8 -23
  20. data/lib/inventory_sync/async/inventory_full_sync.rb +3 -39
  21. data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  22. data/locale/fr/foreman_rh_cloud.edit.po +1032 -0
  23. data/locale/fr/foreman_rh_cloud.po +65 -66
  24. data/locale/fr/foreman_rh_cloud.po.time_stamp +0 -0
  25. data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  26. data/locale/ja/foreman_rh_cloud.edit.po +1026 -0
  27. data/locale/ja/foreman_rh_cloud.po +70 -72
  28. data/locale/ja/foreman_rh_cloud.po.time_stamp +0 -0
  29. data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  30. data/locale/ka/foreman_rh_cloud.edit.po +1025 -0
  31. data/locale/ka/foreman_rh_cloud.po +10 -11
  32. data/locale/ka/foreman_rh_cloud.po.time_stamp +0 -0
  33. data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  34. data/locale/ko/foreman_rh_cloud.edit.po +1029 -0
  35. data/locale/ko/foreman_rh_cloud.po +63 -64
  36. data/locale/ko/foreman_rh_cloud.po.time_stamp +0 -0
  37. data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  38. data/locale/zh_CN/foreman_rh_cloud.edit.po +1031 -0
  39. data/locale/zh_CN/foreman_rh_cloud.po +64 -65
  40. data/locale/zh_CN/foreman_rh_cloud.po.time_stamp +0 -0
  41. data/package.json +1 -1
  42. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +1 -41
  43. data/test/jobs/insights_client_status_aging_test.rb +0 -40
  44. data/test/jobs/inventory_full_sync_test.rb +4 -219
  45. data/test/jobs/inventory_hosts_sync_test.rb +5 -7
  46. data/test/jobs/inventory_self_host_sync_test.rb +1 -1
  47. data/test/models/insights_client_report_status_test.rb +0 -109
  48. data/test/unit/archived_report_generator_test.rb +1 -2
  49. data/test/unit/fact_helpers_test.rb +0 -16
  50. data/test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb +25 -80
  51. data/test/unit/rh_cloud_host_test.rb +0 -214
  52. data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +1 -1
  53. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +1 -1
  54. data/test/unit/slice_generator_test.rb +2 -21
  55. data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +1 -6
  56. data/webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js +6 -45
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +1 -3
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +2 -8
  59. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -1
  60. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +0 -1
  61. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +17 -43
  62. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +0 -7
  63. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +14 -44
  64. metadata +16 -10
  65. data/app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb +0 -23
  66. data/test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb +0 -70
  67. data/test/models/inventory_sync/inventory_status_test.rb +0 -85
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js +0 -82
  69. data/webpack/InsightsHostDetailsTab/__tests__/NewHostDetailsTab.test.js +0 -154
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_rh_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.2.9
4
+ version: 14.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman Red Hat Cloud team
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-02-25 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: foreman_ansible
@@ -101,7 +102,6 @@ files:
101
102
  - app/controllers/concerns/foreman_rh_cloud/iop_smart_proxy_access.rb
102
103
  - app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb
103
104
  - app/controllers/concerns/insights_cloud/candlepin_cache.rb
104
- - app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb
105
105
  - app/controllers/concerns/insights_cloud/client_authentication.rb
106
106
  - app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb
107
107
  - app/controllers/concerns/inventory_upload/report_actions.rb
@@ -234,22 +234,31 @@ files:
234
234
  - locale/Makefile
235
235
  - locale/foreman_rh_cloud.pot
236
236
  - locale/fr/LC_MESSAGES/foreman_rh_cloud.mo
237
+ - locale/fr/foreman_rh_cloud.edit.po
237
238
  - locale/fr/foreman_rh_cloud.po
239
+ - locale/fr/foreman_rh_cloud.po.time_stamp
238
240
  - locale/gemspec.rb
239
241
  - locale/ja/LC_MESSAGES/foreman_rh_cloud.mo
242
+ - locale/ja/foreman_rh_cloud.edit.po
240
243
  - locale/ja/foreman_rh_cloud.po
244
+ - locale/ja/foreman_rh_cloud.po.time_stamp
241
245
  - locale/ka/LC_MESSAGES/foreman_rh_cloud.mo
246
+ - locale/ka/foreman_rh_cloud.edit.po
242
247
  - locale/ka/foreman_rh_cloud.po
248
+ - locale/ka/foreman_rh_cloud.po.time_stamp
243
249
  - locale/ko/LC_MESSAGES/foreman_rh_cloud.mo
250
+ - locale/ko/foreman_rh_cloud.edit.po
244
251
  - locale/ko/foreman_rh_cloud.po
252
+ - locale/ko/foreman_rh_cloud.po.time_stamp
245
253
  - locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo
254
+ - locale/zh_CN/foreman_rh_cloud.edit.po
246
255
  - locale/zh_CN/foreman_rh_cloud.po
256
+ - locale/zh_CN/foreman_rh_cloud.po.time_stamp
247
257
  - package.json
248
258
  - test/controllers/accounts_controller_test.rb
249
259
  - test/controllers/insights_cloud/api/advisor_engine_controller_test.rb
250
260
  - test/controllers/insights_cloud/api/cloud_request_controller_test.rb
251
261
  - test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
252
- - test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb
253
262
  - test/controllers/insights_cloud/ui_requests_controller_test.rb
254
263
  - test/controllers/insights_sync/settings_controller_test.rb
255
264
  - test/controllers/inventory_upload/api/inventory_controller_test.rb
@@ -276,7 +285,6 @@ files:
276
285
  - test/jobs/single_host_report_job_test.rb
277
286
  - test/jobs/upload_report_direct_job_test.rb
278
287
  - test/models/insights_client_report_status_test.rb
279
- - test/models/inventory_sync/inventory_status_test.rb
280
288
  - test/test_plugin_helper.rb
281
289
  - test/unit/archived_report_generator_test.rb
282
290
  - test/unit/fact_helpers_test.rb
@@ -451,7 +459,6 @@ files:
451
459
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap
452
460
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js
453
461
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js
454
- - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js
455
462
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/index.js
456
463
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js
457
464
  - webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js
@@ -590,7 +597,6 @@ files:
590
597
  - webpack/InsightsHostDetailsTab/__tests__/InsightsTabReducer.test.js
591
598
  - webpack/InsightsHostDetailsTab/__tests__/InsightsTabSelectors.test.js
592
599
  - webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js
593
- - webpack/InsightsHostDetailsTab/__tests__/NewHostDetailsTab.test.js
594
600
  - webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTab.test.js.snap
595
601
  - webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabActions.test.js.snap
596
602
  - webpack/InsightsHostDetailsTab/__tests__/__snapshots__/InsightsTabReducer.test.js.snap
@@ -656,6 +662,7 @@ homepage: https://github.com/theforeman/foreman_rh_cloud
656
662
  licenses:
657
663
  - GPL-3.0
658
664
  metadata: {}
665
+ post_install_message:
659
666
  rdoc_options: []
660
667
  require_paths:
661
668
  - lib
@@ -673,7 +680,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
673
680
  - !ruby/object:Gem::Version
674
681
  version: '0'
675
682
  requirements: []
676
- rubygems_version: 4.0.6
683
+ rubygems_version: 3.2.33
684
+ signing_key:
677
685
  specification_version: 4
678
686
  summary: Summary of ForemanRhCloud.
679
687
  test_files:
@@ -681,7 +689,6 @@ test_files:
681
689
  - test/controllers/insights_cloud/api/advisor_engine_controller_test.rb
682
690
  - test/controllers/insights_cloud/api/cloud_request_controller_test.rb
683
691
  - test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb
684
- - test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb
685
692
  - test/controllers/insights_cloud/ui_requests_controller_test.rb
686
693
  - test/controllers/insights_sync/settings_controller_test.rb
687
694
  - test/controllers/inventory_upload/api/inventory_controller_test.rb
@@ -708,7 +715,6 @@ test_files:
708
715
  - test/jobs/single_host_report_job_test.rb
709
716
  - test/jobs/upload_report_direct_job_test.rb
710
717
  - test/models/insights_client_report_status_test.rb
711
- - test/models/inventory_sync/inventory_status_test.rb
712
718
  - test/test_plugin_helper.rb
713
719
  - test/unit/archived_report_generator_test.rb
714
720
  - test/unit/fact_helpers_test.rb
@@ -1,23 +0,0 @@
1
- module InsightsCloud
2
- module CandlepinProxiesExtensions
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- # Update insights client status when hosts check in via subscription-manager facts upload
7
- # rubocop:disable Rails/LexicallyScopedActionFilter
8
- after_action :update_insights_client_status, only: [:facts]
9
- # rubocop:enable Rails/LexicallyScopedActionFilter
10
- end
11
-
12
- def update_insights_client_status
13
- # Update InsightsClientReportStatus whenever host checks in via subscription-manager
14
- # This ensures USER_OMITTED status gets set even when insights-client isn't installed
15
- # (parameter=false means insights-client won't be installed, so it won't hit MachineTelemetriesController)
16
- hoststatus = @host.get_status(InsightsClientReportStatus)
17
- Rails.logger.debug "Current status: #{hoststatus.to_label}"
18
- @host.get_status(InsightsClientReportStatus).refresh!
19
- @host.refresh_global_status!
20
- Rails.logger.debug "New status: #{hoststatus.to_label}"
21
- end
22
- end
23
- end
@@ -1,70 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module InsightsCloud
4
- class CandlepinProxiesExtensionsTest < ActiveSupport::TestCase
5
- setup do
6
- @organization = FactoryBot.create(:organization)
7
- @host = FactoryBot.create(:host, :with_subscription, :managed, organization: @organization)
8
- end
9
-
10
- test 'updates InsightsClientReportStatus to USER_OMITTED when parameter is false' do
11
- # Set parameter to false so status should be USER_OMITTED
12
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
13
-
14
- # Simulate what the callback does
15
- @host.get_status(InsightsClientReportStatus).refresh!
16
- @host.refresh_global_status!
17
-
18
- # Verify the status was updated
19
- @host.reload
20
- insights_status = @host.get_status(InsightsClientReportStatus)
21
- assert insights_status.persisted?, 'InsightsClientReportStatus should be persisted'
22
- assert_equal InsightsClientReportStatus::USER_OMITTED, insights_status.status,
23
- 'Status should be USER_OMITTED when host_registration_insights=false'
24
- end
25
-
26
- test 'sets USER_OMITTED status when parameter is inherited from hostgroup' do
27
- # Create hostgroup with parameter
28
- hostgroup = FactoryBot.create(:hostgroup)
29
- hostgroup.group_parameters << GroupParameter.create(
30
- name: 'host_registration_insights',
31
- value: 'false',
32
- key_type: 'boolean'
33
- )
34
- hostgroup.save!
35
-
36
- @host.hostgroup = hostgroup
37
- @host.save!
38
-
39
- # Simulate what the callback does
40
- @host.get_status(InsightsClientReportStatus).refresh!
41
- @host.refresh_global_status!
42
-
43
- # Verify status respects inherited parameter
44
- @host.reload
45
- insights_status = @host.get_status(InsightsClientReportStatus)
46
- assert_equal InsightsClientReportStatus::USER_OMITTED, insights_status.status,
47
- 'Status should be USER_OMITTED when host_registration_insights=false is inherited from hostgroup'
48
- end
49
-
50
- test 'refreshes global status' do
51
- FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
52
-
53
- # Simulate what the callback does
54
- @host.get_status(InsightsClientReportStatus).refresh!
55
- @host.refresh_global_status!
56
-
57
- # Verify global status was updated
58
- @host.reload
59
- assert_not_nil @host.global_status, 'Global status should be set'
60
- end
61
-
62
- test 'CandlepinProxiesController includes the update_insights_client_status method' do
63
- # Verify the concern is included and method is available
64
- controller = Katello::Api::Rhsm::CandlepinProxiesController.new
65
-
66
- assert_respond_to controller, :update_insights_client_status,
67
- 'CandlepinProxiesController should have update_insights_client_status method from concern'
68
- end
69
- end
70
- end
@@ -1,85 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- module InventorySync
4
- class InventoryStatusTest < ActiveSupport::TestCase
5
- setup do
6
- @host = FactoryBot.create(:host, :managed)
7
- end
8
-
9
- test 'status constants are defined correctly' do
10
- assert_equal 0, InventorySync::InventoryStatus::DISCONNECT
11
- assert_equal 1, InventorySync::InventoryStatus::SYNC
12
- assert_equal 2, InventorySync::InventoryStatus::USER_OMITTED
13
- end
14
-
15
- test 'to_global returns OK for USER_OMITTED status' do
16
- status = @host.get_status(InventorySync::InventoryStatus)
17
- status.status = InventorySync::InventoryStatus::USER_OMITTED
18
- status.save!
19
-
20
- assert_equal HostStatus::Global::OK, status.to_global
21
- end
22
-
23
- test 'to_global returns WARN for DISCONNECT status' do
24
- status = @host.get_status(InventorySync::InventoryStatus)
25
- status.status = InventorySync::InventoryStatus::DISCONNECT
26
- status.save!
27
-
28
- assert_equal HostStatus::Global::WARN, status.to_global
29
- end
30
-
31
- test 'to_global returns OK for SYNC status' do
32
- status = @host.get_status(InventorySync::InventoryStatus)
33
- status.status = InventorySync::InventoryStatus::SYNC
34
- status.save!
35
-
36
- assert_equal HostStatus::Global::OK, status.to_global
37
- end
38
-
39
- test 'to_label returns appropriate messages for each status' do
40
- status = @host.get_status(InventorySync::InventoryStatus)
41
-
42
- # Test DISCONNECT label
43
- status.status = InventorySync::InventoryStatus::DISCONNECT
44
- status.save!
45
- label = status.to_label
46
- assert_match(/not present/, label.downcase)
47
- assert_match(/console\.redhat\.com/, label)
48
-
49
- # Test SYNC label
50
- status.status = InventorySync::InventoryStatus::SYNC
51
- status.save!
52
- label = status.to_label
53
- assert_match(/uploaded.*present/, label.downcase)
54
- assert_match(/console\.redhat\.com/, label)
55
-
56
- # Test USER_OMITTED label
57
- status.status = InventorySync::InventoryStatus::USER_OMITTED
58
- status.save!
59
- label = status.to_label
60
- assert_match(/excluded/, label.downcase)
61
- assert_match(/host parameter/, label.downcase)
62
- assert_match(/console\.redhat\.com/, label)
63
- end
64
-
65
- test 'relevant? returns true in regular (non-IoP) mode' do
66
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
67
-
68
- status = @host.get_status(InventorySync::InventoryStatus)
69
- status.status = InventorySync::InventoryStatus::SYNC
70
- status.save!
71
-
72
- assert status.relevant?, 'Inventory status should be relevant in regular mode'
73
- end
74
-
75
- test 'relevant? returns false in IoP mode' do
76
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
77
-
78
- status = @host.get_status(InventorySync::InventoryStatus)
79
- status.status = InventorySync::InventoryStatus::SYNC
80
- status.save!
81
-
82
- refute status.relevant?, 'Inventory status should NOT be relevant in IoP mode'
83
- end
84
- end
85
- end
@@ -1,82 +0,0 @@
1
- import React from 'react';
2
- import { shallow } from '@theforeman/test';
3
- import Toast from '../Toast';
4
-
5
- describe('Toast', () => {
6
- it('renders with all three status counts including user_omitted', () => {
7
- const wrapper = shallow(
8
- <Toast syncHosts={5} disconnectHosts={3} userOmittedHosts={2} />
9
- );
10
-
11
- const links = wrapper.find('HostsWithStatusLink');
12
- expect(links).toHaveLength(3);
13
-
14
- // Check the children (numbers) of each link
15
- expect(
16
- links
17
- .at(0)
18
- .children()
19
- .text()
20
- ).toBe('5');
21
- expect(
22
- links
23
- .at(1)
24
- .children()
25
- .text()
26
- ).toBe('3');
27
- expect(
28
- links
29
- .at(2)
30
- .children()
31
- .text()
32
- ).toBe('2');
33
- });
34
-
35
- it('does not render user_omitted section when count is 0', () => {
36
- const wrapper = shallow(
37
- <Toast syncHosts={5} disconnectHosts={3} userOmittedHosts={0} />
38
- );
39
-
40
- // Should have only 2 HostsWithStatusLink components (sync and disconnect)
41
- const links = wrapper.find('HostsWithStatusLink');
42
- expect(links).toHaveLength(2);
43
-
44
- // Should not contain the user_omitted explanation text
45
- expect(wrapper.text()).not.toContain(
46
- 'host_registration_insights_inventory parameter value is false'
47
- );
48
- });
49
-
50
- it('renders without crashing when userOmittedHosts is not provided (default)', () => {
51
- const wrapper = shallow(<Toast syncHosts={5} disconnectHosts={3} />);
52
-
53
- // Should use default value of 0, so only 2 links
54
- const links = wrapper.find('HostsWithStatusLink');
55
- expect(links).toHaveLength(2);
56
-
57
- // Verify the count values
58
- expect(
59
- links
60
- .at(0)
61
- .children()
62
- .text()
63
- ).toBe('5');
64
- expect(
65
- links
66
- .at(1)
67
- .children()
68
- .text()
69
- ).toBe('3');
70
- });
71
-
72
- it('renders correct status links for each category', () => {
73
- const wrapper = shallow(
74
- <Toast syncHosts={5} disconnectHosts={3} userOmittedHosts={2} />
75
- );
76
-
77
- const links = wrapper.find('HostsWithStatusLink');
78
- expect(links.at(0).prop('statusName')).toBe('sync');
79
- expect(links.at(1).prop('statusName')).toBe('disconnect');
80
- expect(links.at(2).prop('statusName')).toBe('user_omitted');
81
- });
82
- });
@@ -1,154 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import '@testing-library/jest-dom';
4
- import { Provider } from 'react-redux';
5
- import configureMockStore from 'redux-mock-store';
6
- import thunk from 'redux-thunk';
7
- import NewHostDetailsTab from '../NewHostDetailsTab';
8
-
9
- jest.mock('../../common/Hooks/ConfigHooks', () => ({
10
- useIopConfig: jest.fn(() => false),
11
- }));
12
-
13
- jest.mock('foremanReact/common/I18n', () => ({
14
- translate: jest.fn(str => str),
15
- }));
16
-
17
- const mockStore = configureMockStore([thunk]);
18
-
19
- describe('NewHostDetailsTab', () => {
20
- let store;
21
- let mockRouter;
22
-
23
- beforeEach(() => {
24
- mockRouter = {
25
- push: jest.fn(),
26
- replace: jest.fn(),
27
- location: {
28
- pathname: '/new/hosts/test-host.example.com',
29
- search: '?page=1&per_page=20',
30
- hash: '#/Insights',
31
- query: { page: '1', per_page: '20' },
32
- },
33
- };
34
-
35
- store = mockStore({
36
- API: {},
37
- ForemanRhCloud: {
38
- InsightsCloudSync: {
39
- table: {
40
- selectedIds: {},
41
- isAllSelected: false,
42
- showSelectAllAlert: false,
43
- },
44
- },
45
- },
46
- insightsHostDetailsTab: {
47
- query: '',
48
- hits: [],
49
- selectedIds: {},
50
- error: null,
51
- },
52
- router: {
53
- location: {
54
- pathname: '/new/hosts/test-host.example.com',
55
- search: '?page=1&per_page=20',
56
- hash: '#/Insights',
57
- query: { page: '1', per_page: '20' },
58
- },
59
- },
60
- });
61
- });
62
-
63
- afterEach(() => {
64
- jest.clearAllMocks();
65
- });
66
-
67
- describe('cleanup effect', () => {
68
- it('should preserve hash when clearing search params on unmount', () => {
69
- const { unmount } = render(
70
- <Provider store={store}>
71
- <NewHostDetailsTab
72
- hostName="test-host.example.com"
73
- router={mockRouter}
74
- />
75
- </Provider>
76
- );
77
-
78
- // Unmount the component to trigger cleanup
79
- unmount();
80
-
81
- // Verify router.replace was called with both search: null AND the existing hash
82
- expect(mockRouter.replace).toHaveBeenCalledWith({
83
- search: null,
84
- hash: '#/Insights',
85
- });
86
- });
87
-
88
- it('should only clear search params when no hash exists', () => {
89
- mockRouter.location.hash = '';
90
-
91
- const { unmount } = render(
92
- <Provider store={store}>
93
- <NewHostDetailsTab
94
- hostName="test-host.example.com"
95
- router={mockRouter}
96
- />
97
- </Provider>
98
- );
99
-
100
- unmount();
101
-
102
- // When there's no hash, should only pass search: null
103
- expect(mockRouter.replace).toHaveBeenCalledWith({
104
- search: null,
105
- });
106
- });
107
-
108
- it('should handle router.location being undefined gracefully', () => {
109
- const routerWithoutLocation = {
110
- push: jest.fn(),
111
- replace: jest.fn(),
112
- location: undefined,
113
- };
114
-
115
- const { unmount } = render(
116
- <Provider store={store}>
117
- <NewHostDetailsTab
118
- hostName="test-host.example.com"
119
- router={routerWithoutLocation}
120
- />
121
- </Provider>
122
- );
123
-
124
- unmount();
125
-
126
- // Should still call replace with search: null even if location is undefined
127
- expect(routerWithoutLocation.replace).toHaveBeenCalledWith({
128
- search: null,
129
- });
130
- });
131
-
132
- it('should use the latest hash value at unmount time, not a stale captured value', () => {
133
- const { unmount } = render(
134
- <Provider store={store}>
135
- <NewHostDetailsTab
136
- hostName="test-host.example.com"
137
- router={mockRouter}
138
- />
139
- </Provider>
140
- );
141
-
142
- // Change the hash after mount, before unmount
143
- mockRouter.location.hash = '#/Overview';
144
-
145
- unmount();
146
-
147
- // Verify router.replace was called with the UPDATED hash, not the initial '#/Insights'
148
- expect(mockRouter.replace).toHaveBeenCalledWith({
149
- search: null,
150
- hash: '#/Overview',
151
- });
152
- });
153
- });
154
- });