foreman_puppet 10.1.3 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  3. data/app/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller.rb +75 -1
  4. data/app/models/concerns/foreman_puppet/extensions/host.rb +2 -2
  5. data/app/models/concerns/foreman_puppet/extensions/host_common.rb +35 -0
  6. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +10 -3
  7. data/app/models/foreman_puppet/config_group.rb +6 -0
  8. data/app/models/foreman_puppet/puppetclass.rb +14 -0
  9. data/app/services/concerns/foreman_puppet/extensions/bulk_hosts_manager.rb +18 -0
  10. data/config/api_routes.rb +1 -0
  11. data/db/seeds.d/111_puppet_proxy_feature.rb +1 -1
  12. data/lib/foreman_puppet/register.rb +2 -1
  13. data/lib/foreman_puppet/version.rb +1 -1
  14. data/test/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller_test.rb +93 -0
  15. data/test/models/foreman_puppet/host_test.rb +66 -0
  16. data/test/models/foreman_puppet/hostgroup_test.rb +32 -0
  17. data/test/services/foreman_puppet/bulk_hosts_manager_test.rb +45 -0
  18. data/webpack/__mocks__/foremanReact/redux/API/index.js +8 -0
  19. data/webpack/global_index.js +18 -1
  20. data/webpack/src/Extends/Hosts/ActionsBar/index.js +20 -0
  21. data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/__tests__/actions.test.js +0 -7
  22. data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/index.js +9 -13
  23. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetCAProxy/__tests__/index.test.js +3 -0
  24. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetCAProxy/index.js +2 -0
  25. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/BulkChangePuppetEnvironmentModal.js +239 -0
  26. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/BulkChangePuppetEnvironmentModal.test.js +155 -0
  27. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/actions.test.js +49 -0
  28. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/index.test.js +66 -0
  29. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/actions.js +37 -0
  30. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/index.js +30 -0
  31. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/__tests__/index.test.js +160 -44
  32. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/index.js +2 -0
  33. data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/__tests__/actions.test.js +0 -6
  34. data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/index.js +8 -13
  35. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/__tests__/index.test.js +138 -38
  36. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/index.js +2 -0
  37. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/BulkRemovePuppetEnvironmentModal.js +148 -0
  38. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/BulkRemovePuppetEnvironmentModal.test.js +80 -0
  39. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/index.test.js +66 -0
  40. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/index.js +30 -0
  41. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/__tests__/index.test.js +125 -33
  42. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/index.js +2 -0
  43. data/webpack/src/Router/routes.fixtures.js +13 -0
  44. data/webpack/src/Router/routes.test.js +68 -8
  45. data/webpack/src/foreman_puppet_host_form.test.js +3 -1
  46. data/webpack/test_setup.js +1 -0
  47. metadata +14 -3
  48. data/webpack/src/Router/__snapshots__/routes.test.js.snap +0 -3
@@ -0,0 +1,30 @@
1
+ import React, { useContext } from 'react';
2
+ import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
3
+ import { useBulkModalOpen } from 'foremanReact/common/BulkModalStateHelper';
4
+ import BulkChangePuppetEnvironmentModal from './BulkChangePuppetEnvironmentModal';
5
+
6
+ const BulkChangePuppetEnvironmentScene = () => {
7
+ const {
8
+ selectAllHostsMode,
9
+ selectedCount,
10
+ fetchBulkParams,
11
+ refreshTableData,
12
+ } = useContext(ForemanActionsBarContext);
13
+ const { isOpen, close: closeModal } = useBulkModalOpen(
14
+ 'bulk-change-puppet-environment'
15
+ );
16
+
17
+ return (
18
+ <BulkChangePuppetEnvironmentModal
19
+ fetchBulkParams={fetchBulkParams}
20
+ selectedCount={selectedCount}
21
+ selectAllHostsMode={selectAllHostsMode}
22
+ isOpen={isOpen}
23
+ closeModal={closeModal}
24
+ onSuccess={refreshTableData}
25
+ />
26
+ );
27
+ };
28
+
29
+ export { BulkChangePuppetEnvironmentModal };
30
+ export default BulkChangePuppetEnvironmentScene;
@@ -1,66 +1,182 @@
1
1
  import React from 'react';
2
- import { mount } from '@theforeman/test';
2
+ import { act, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import '@testing-library/jest-dom';
3
5
 
4
6
  import { openBulkModal } from 'foremanReact/common/BulkModalStateHelper';
5
7
  import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
8
+ import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers';
9
+ import { APIActions } from 'foremanReact/redux/API';
10
+ import API from 'foremanReact/redux/API/API';
6
11
 
7
12
  import BulkChangePuppetProxyScene from '../index';
8
- import BulkChangeProxyCommon from '../../BulkChangeProxyCommon';
13
+ import { BULK_CHANGE_PUPPET_PROXY_KEY } from '../../BulkChangeProxyCommon/actions';
9
14
 
10
- jest.mock('foremanReact/components/HostDetails/ActionsBar', () => ({
11
- ForemanActionsBarContext: jest.requireActual('react').createContext(),
12
- }));
15
+ jest.mock('foremanReact/redux/API', () => {
16
+ const actual = jest.requireActual('foremanReact/redux/API');
13
17
 
14
- jest.mock('../../BulkChangeProxyCommon', () => ({
15
- __esModule: true,
16
- default: jest.fn(() => null),
17
- }));
18
-
19
- describe('BulkChangePuppetProxyScene', () => {
20
- const fetchBulkParams = jest.fn();
21
- const contextValue = {
22
- selectAllHostsMode: false,
23
- selectedCount: 2,
24
- selectedResults: [1, 2],
25
- fetchBulkParams,
18
+ return {
19
+ ...actual,
20
+ APIActions: {
21
+ ...actual.APIActions,
22
+ put: jest.fn(params => ({ type: 'MOCK_API_PUT', payload: params })),
23
+ },
26
24
  };
25
+ });
26
+
27
+ jest.mock('foremanReact/redux/API/APISelectors', () =>
28
+ jest.requireActual('foremanReact/redux/API/APISelectors')
29
+ );
30
+
31
+ const { renderWithStoreAndI18n } = rtlHelpers;
32
+
33
+ const MODAL_ID = 'bulk-change-puppet-proxy';
34
+
35
+ const fetchBulkParams = jest.fn(() => 'id ^ (1,2)');
36
+ const refreshTableData = jest.fn();
37
+
38
+ const defaultContextValue = {
39
+ selectAllHostsMode: false,
40
+ selectedCount: 2,
41
+ selectedResults: [1, 2],
42
+ fetchBulkParams,
43
+ refreshTableData,
44
+ };
45
+
46
+ const smartProxiesResponse = {
47
+ data: {
48
+ results: [{ id: 1, name: 'proxy1.example.com' }],
49
+ },
50
+ };
27
51
 
52
+ const renderScene = ({ contextValue = defaultContextValue } = {}) =>
53
+ renderWithStoreAndI18n(
54
+ <ForemanActionsBarContext.Provider value={contextValue}>
55
+ <BulkChangePuppetProxyScene />
56
+ </ForemanActionsBarContext.Provider>
57
+ );
58
+
59
+ const selectPuppetProxy = async () => {
60
+ await act(async () => {
61
+ await userEvent.click(await screen.findByText('Select a Puppet Proxy'));
62
+ });
63
+ await act(async () => {
64
+ await userEvent.click(screen.getByText('proxy1.example.com'));
65
+ });
66
+ };
67
+
68
+ describe('BulkChangePuppetProxyScene', () => {
28
69
  beforeEach(() => {
70
+ openBulkModal(MODAL_ID, false);
71
+ API.get.mockImplementation(() => Promise.resolve(smartProxiesResponse));
72
+ });
73
+
74
+ afterEach(() => {
29
75
  jest.clearAllMocks();
30
- openBulkModal('bulk-change-puppet-proxy', false);
31
76
  });
32
77
 
33
- it('opens with bulk modal state and passes expected props', () => {
34
- openBulkModal('bulk-change-puppet-proxy', true);
35
- const wrapper = mount(
36
- <ForemanActionsBarContext.Provider value={contextValue}>
37
- <BulkChangePuppetProxyScene />
38
- </ForemanActionsBarContext.Provider>
39
- );
78
+ it('does not show the modal when bulk modal state is closed', () => {
79
+ renderScene();
40
80
 
41
- const componentType =
42
- BulkChangeProxyCommon.default || BulkChangeProxyCommon;
43
- const props = wrapper.find(componentType).props();
81
+ expect(
82
+ screen.queryByRole('dialog', { name: 'Change Puppet Proxy' })
83
+ ).not.toBeInTheDocument();
84
+ });
44
85
 
45
- expect(props).toEqual(
86
+ it('opens the modal with Puppet Proxy content when bulk modal is open', async () => {
87
+ openBulkModal(MODAL_ID, true);
88
+ renderScene();
89
+
90
+ expect(
91
+ await screen.findByRole('dialog', { name: 'Change Puppet Proxy' })
92
+ ).toBeInTheDocument();
93
+ expect(
94
+ screen.getByText(/Changing the Puppet proxy will affect/)
95
+ ).toBeInTheDocument();
96
+ expect(screen.getByText('2')).toBeInTheDocument();
97
+ expect(
98
+ await screen.findByText('Select a Puppet Proxy')
99
+ ).toBeInTheDocument();
100
+ expect(screen.queryByText('Select a Puppet CA Proxy')).not.toBeInTheDocument();
101
+ expect(screen.queryByText('Change Puppet CA Proxy')).not.toBeInTheDocument();
102
+ expect(
103
+ await screen.findByRole('button', { name: 'Change Puppet Proxy' })
104
+ ).toBeDisabled();
105
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
106
+ });
107
+
108
+ it('shows the all-hosts warning when select all hosts mode is enabled', async () => {
109
+ openBulkModal(MODAL_ID, true);
110
+ renderScene({
111
+ contextValue: { ...defaultContextValue, selectAllHostsMode: true },
112
+ });
113
+
114
+ await screen.findByRole('dialog', { name: 'Change Puppet Proxy' });
115
+ expect(screen.getByText('All')).toBeInTheDocument();
116
+ });
117
+
118
+ it('closes the modal when Cancel is clicked', async () => {
119
+ openBulkModal(MODAL_ID, true);
120
+ renderScene();
121
+
122
+ await screen.findByRole('dialog', { name: 'Change Puppet Proxy' });
123
+ await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
124
+
125
+ await waitFor(() => {
126
+ expect(
127
+ screen.queryByRole('dialog', { name: 'Change Puppet Proxy' })
128
+ ).not.toBeInTheDocument();
129
+ });
130
+ });
131
+
132
+ it('submits puppet proxy change request when confirm is clicked', async () => {
133
+ openBulkModal(MODAL_ID, true);
134
+ renderScene();
135
+
136
+ await screen.findByRole('dialog', { name: 'Change Puppet Proxy' });
137
+ await selectPuppetProxy();
138
+ await act(async () => {
139
+ await userEvent.click(
140
+ screen.getByRole('button', { name: 'Change Puppet Proxy' })
141
+ );
142
+ });
143
+
144
+ expect(fetchBulkParams).toHaveBeenCalledTimes(1);
145
+ expect(APIActions.put).toHaveBeenCalledWith(
46
146
  expect.objectContaining({
47
- isCAProxy: false,
48
- fetchBulkParams,
49
- selectedCount: 2,
50
- selectedResults: [1, 2],
51
- selectAllHostsMode: false,
52
- isOpen: true,
53
- closeModal: expect.any(Function),
54
- selectMessage: 'Select a Puppet Proxy',
55
- handleErrorMessage: 'Failed to change Puppet Proxy',
56
- changeMessage: 'Change Puppet Proxy',
57
- allHostsMessage:
58
- 'Changing the Puppet proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet proxy.',
59
- someHostsMessage:
60
- 'Changing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet proxy.',
147
+ key: BULK_CHANGE_PUPPET_PROXY_KEY,
148
+ params: {
149
+ included: {
150
+ search: 'id ^ (1,2)',
151
+ },
152
+ proxy_id: '1',
153
+ ca_proxy: false,
154
+ },
61
155
  })
62
156
  );
157
+ });
158
+
159
+ it('refreshes table data after successful change', async () => {
160
+ openBulkModal(MODAL_ID, true);
161
+ renderScene();
162
+
163
+ await screen.findByRole('dialog', { name: 'Change Puppet Proxy' });
164
+ await selectPuppetProxy();
165
+ await act(async () => {
166
+ await userEvent.click(
167
+ screen.getByRole('button', { name: 'Change Puppet Proxy' })
168
+ );
169
+ });
170
+
171
+ const { handleSuccess } = APIActions.put.mock.calls[0][0];
172
+
173
+ act(() => {
174
+ handleSuccess({ data: { message: 'Change started' } });
175
+ });
63
176
 
64
- wrapper.unmount();
177
+ expect(refreshTableData).toHaveBeenCalledTimes(1);
178
+ expect(
179
+ screen.queryByRole('dialog', { name: 'Change Puppet Proxy' })
180
+ ).not.toBeInTheDocument();
65
181
  });
66
182
  });
@@ -11,6 +11,7 @@ const BulkChangePuppetProxyScene = () => {
11
11
  selectedCount,
12
12
  selectedResults,
13
13
  fetchBulkParams,
14
+ refreshTableData,
14
15
  } = useContext(ForemanActionsBarContext);
15
16
  const { isOpen, close: closeModal } = useBulkModalOpen(
16
17
  'bulk-change-puppet-proxy'
@@ -24,6 +25,7 @@ const BulkChangePuppetProxyScene = () => {
24
25
  selectAllHostsMode={selectAllHostsMode}
25
26
  isOpen={isOpen}
26
27
  closeModal={closeModal}
28
+ onSuccess={refreshTableData}
27
29
  selectMessage={__('Select a Puppet Proxy')}
28
30
  handleErrorMessage={__('Failed to change Puppet Proxy')}
29
31
  changeMessage={__('Change Puppet Proxy')}
@@ -7,12 +7,6 @@ import {
7
7
  BULK_REMOVE_PUPPET_CA_PROXY_KEY,
8
8
  } from '../actions';
9
9
 
10
- jest.mock('foremanReact/redux/API', () => ({
11
- APIActions: {
12
- put: jest.fn(),
13
- },
14
- }));
15
-
16
10
  describe('BulkRemoveProxyCommon actions', () => {
17
11
  const url = foremanUrl('/api/v2/hosts/bulk/remove_puppet_proxy');
18
12
 
@@ -5,12 +5,6 @@ import { useDispatch } from 'react-redux';
5
5
  import { Modal, Button, TextContent, Text } from '@patternfly/react-core';
6
6
  import { addToast } from 'foremanReact/components/ToastsList/slice';
7
7
  import { translate as __ } from 'foremanReact/common/I18n';
8
- import { foremanUrl } from 'foremanReact/common/helpers';
9
- import { APIActions } from 'foremanReact/redux/API';
10
- import {
11
- HOSTS_API_PATH,
12
- API_REQUEST_KEY,
13
- } from 'foremanReact/routes/Hosts/constants';
14
8
 
15
9
  import {
16
10
  BULK_REMOVE_PUPPET_PROXY_KEY,
@@ -30,6 +24,7 @@ const BulkRemoveProxyCommon = ({
30
24
  removeMessage,
31
25
  allHostsMessage,
32
26
  someHostsMessage,
27
+ onSuccess: onSuccessCallback,
33
28
  }) => {
34
29
  const actionKey = isCAProxy
35
30
  ? BULK_REMOVE_PUPPET_CA_PROXY_KEY
@@ -57,13 +52,11 @@ const BulkRemoveProxyCommon = ({
57
52
  message: response.data.message,
58
53
  })
59
54
  );
60
- dispatch(
61
- APIActions.get({
62
- key: API_REQUEST_KEY,
63
- url: foremanUrl(HOSTS_API_PATH),
64
- })
65
- );
66
- handleModalClose();
55
+ try {
56
+ if (onSuccessCallback) onSuccessCallback();
57
+ } finally {
58
+ handleModalClose();
59
+ }
67
60
  };
68
61
 
69
62
  const handleConfirm = () => {
@@ -153,12 +146,14 @@ BulkRemoveProxyCommon.propTypes = {
153
146
  removeMessage: PropTypes.string,
154
147
  allHostsMessage: PropTypes.string.isRequired,
155
148
  someHostsMessage: PropTypes.string.isRequired,
149
+ onSuccess: PropTypes.func,
156
150
  };
157
151
 
158
152
  BulkRemoveProxyCommon.defaultProps = {
159
153
  isOpen: false,
160
154
  closeModal: () => {},
161
155
  removeMessage: 'Remove Puppet (CA) Proxy',
156
+ onSuccess: undefined,
162
157
  };
163
158
 
164
159
  export default BulkRemoveProxyCommon;
@@ -1,65 +1,165 @@
1
1
  import React from 'react';
2
- import { mount } from '@theforeman/test';
2
+ import { act, screen, within, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import '@testing-library/jest-dom';
3
5
 
6
+ import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers';
4
7
  import { openBulkModal } from 'foremanReact/common/BulkModalStateHelper';
5
8
  import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
9
+ import { APIActions } from 'foremanReact/redux/API';
10
+ import API from 'foremanReact/redux/API/API';
6
11
 
7
12
  import BulkRemovePuppetCAProxyScene from '../index';
8
- import BulkRemoveProxyCommon from '../../BulkRemoveProxyCommon';
13
+ import { BULK_REMOVE_PUPPET_CA_PROXY_KEY } from '../../BulkRemoveProxyCommon/actions';
9
14
 
10
- jest.mock('foremanReact/components/HostDetails/ActionsBar', () => ({
11
- ForemanActionsBarContext: jest.requireActual('react').createContext(),
12
- }));
13
-
14
- jest.mock('../../BulkRemoveProxyCommon', () => ({
15
- __esModule: true,
16
- default: jest.fn(() => null),
17
- }));
15
+ const { renderWithStoreAndI18n } = rtlHelpers;
18
16
 
19
17
  describe('BulkRemovePuppetCAProxyScene', () => {
20
- const fetchBulkParams = jest.fn();
21
- const contextValue = {
18
+ const fetchBulkParams = jest.fn(() => 'id ^ (1,2)');
19
+ const refreshTableData = jest.fn();
20
+ const defaultContextValue = {
22
21
  selectAllHostsMode: false,
23
22
  selectedCount: 2,
24
23
  selectedResults: [1, 2],
25
24
  fetchBulkParams,
25
+ refreshTableData,
26
26
  };
27
+ let renderResult;
27
28
 
28
- beforeEach(() => {
29
- jest.clearAllMocks();
30
- openBulkModal('bulk-remove-puppet-ca-proxy', false);
31
- });
29
+ const renderScene = (contextOverrides = {}, isOpen = true) => {
30
+ openBulkModal('bulk-remove-puppet-ca-proxy', isOpen);
32
31
 
33
- it('opens with bulk modal state and passes expected CA proxy props', () => {
34
- openBulkModal('bulk-remove-puppet-ca-proxy', true);
35
- const wrapper = mount(
36
- <ForemanActionsBarContext.Provider value={contextValue}>
32
+ renderResult = renderWithStoreAndI18n(
33
+ <ForemanActionsBarContext.Provider
34
+ value={{ ...defaultContextValue, ...contextOverrides }}
35
+ >
37
36
  <BulkRemovePuppetCAProxyScene />
38
37
  </ForemanActionsBarContext.Provider>
39
38
  );
40
39
 
41
- const componentType =
42
- BulkRemoveProxyCommon.default || BulkRemoveProxyCommon;
43
- const props = wrapper.find(componentType).props();
40
+ return renderResult;
41
+ };
42
+
43
+ beforeEach(() => {
44
+ openBulkModal('bulk-remove-puppet-ca-proxy', false);
45
+ APIActions.put.mockImplementation(params => ({
46
+ type: 'API_PUT',
47
+ payload: params,
48
+ }));
49
+ });
50
+
51
+ afterEach(() => {
52
+ renderResult?.unmount();
53
+ jest.clearAllMocks();
54
+ });
55
+
56
+ it('does not show the remove modal when bulk modal is closed', () => {
57
+ renderScene({}, false);
58
+
59
+ expect(
60
+ screen.queryByRole('dialog', { name: 'Remove Puppet CA Proxy' })
61
+ ).not.toBeInTheDocument();
62
+ });
63
+
64
+ it('shows the remove modal with warning for selected hosts when opened', async () => {
65
+ renderScene();
66
+
67
+ const dialog = await screen.findByRole('dialog', {
68
+ name: 'Remove Puppet CA Proxy',
69
+ });
44
70
 
45
- expect(props).toEqual(
71
+ expect(dialog).toBeInTheDocument();
72
+ expect(
73
+ within(dialog).getByText(/Removing the Puppet CA proxy will affect/)
74
+ ).toBeInTheDocument();
75
+ expect(within(dialog).getByText('2', { selector: 'strong' })).toBeInTheDocument();
76
+ expect(within(dialog).getByText(/selected hosts/)).toBeInTheDocument();
77
+ expect(
78
+ within(dialog).getByText(
79
+ /Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!/
80
+ )
81
+ ).toBeInTheDocument();
82
+ expect(
83
+ within(dialog).getByRole('button', { name: 'Remove Puppet CA Proxy' })
84
+ ).toBeInTheDocument();
85
+ expect(
86
+ within(dialog).getByRole('button', { name: 'Cancel' })
87
+ ).toBeInTheDocument();
88
+ });
89
+
90
+ it('shows all hosts warning message when select all hosts mode is enabled', async () => {
91
+ renderScene({ selectAllHostsMode: true });
92
+
93
+ const dialog = await screen.findByRole('dialog', {
94
+ name: 'Remove Puppet CA Proxy',
95
+ });
96
+
97
+ expect(
98
+ within(dialog).getByText(/Removing the Puppet CA proxy will affect/)
99
+ ).toBeInTheDocument();
100
+ expect(within(dialog).getByText('All', { selector: 'strong' })).toBeInTheDocument();
101
+ expect(within(dialog).getByText(/selected hosts/)).toBeInTheDocument();
102
+ expect(
103
+ within(dialog).getByText(
104
+ /Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!/
105
+ )
106
+ ).toBeInTheDocument();
107
+ });
108
+
109
+ it('closes the modal when cancel is clicked', async () => {
110
+ renderScene();
111
+
112
+ await screen.findByRole('dialog', { name: 'Remove Puppet CA Proxy' });
113
+ await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
114
+
115
+ expect(
116
+ screen.queryByRole('dialog', { name: 'Remove Puppet CA Proxy' })
117
+ ).not.toBeInTheDocument();
118
+ });
119
+
120
+ it('submits CA proxy removal request when confirm is clicked', async () => {
121
+ renderScene();
122
+
123
+ await screen.findByRole('dialog', { name: 'Remove Puppet CA Proxy' });
124
+ await act(async () => {
125
+ await userEvent.click(
126
+ screen.getByRole('button', { name: 'Remove Puppet CA Proxy' })
127
+ );
128
+ });
129
+
130
+ expect(fetchBulkParams).toHaveBeenCalledTimes(1);
131
+ expect(APIActions.put).toHaveBeenCalledWith(
46
132
  expect.objectContaining({
47
- isCAProxy: true,
48
- selectAllHostsMode: false,
49
- selectedCount: 2,
50
- selectedResults: [1, 2],
51
- fetchBulkParams,
52
- isOpen: true,
53
- closeModal: expect.any(Function),
54
- handleErrorMessage: 'Failed to remove Puppet CA Proxy',
55
- allHostsMessage:
56
- 'Removing the Puppet CA proxy will affect {boldCount} selected hosts. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!',
57
- someHostsMessage:
58
- 'Removing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!',
59
- removeMessage: 'Remove Puppet CA Proxy',
133
+ key: BULK_REMOVE_PUPPET_CA_PROXY_KEY,
134
+ params: {
135
+ included: {
136
+ search: 'id ^ (1,2)',
137
+ },
138
+ ca_proxy: true,
139
+ },
60
140
  })
61
141
  );
142
+ });
143
+
144
+ it('refreshes table data after successful removal', async () => {
145
+ API.put.mockImplementation(() =>
146
+ Promise.resolve({ data: { message: 'Removal started' } })
147
+ );
148
+
149
+ renderScene();
150
+
151
+ await screen.findByRole('dialog', { name: 'Remove Puppet CA Proxy' });
152
+ await act(async () => {
153
+ await userEvent.click(
154
+ screen.getByRole('button', { name: 'Remove Puppet CA Proxy' })
155
+ );
156
+ });
62
157
 
63
- wrapper.unmount();
158
+ await waitFor(() => {
159
+ expect(refreshTableData).toHaveBeenCalledTimes(1);
160
+ });
161
+ expect(
162
+ screen.queryByRole('dialog', { name: 'Remove Puppet CA Proxy' })
163
+ ).not.toBeInTheDocument();
64
164
  });
65
165
  });
@@ -10,6 +10,7 @@ const BulkRemovePuppetCAProxyScene = () => {
10
10
  selectedCount,
11
11
  selectedResults,
12
12
  fetchBulkParams,
13
+ refreshTableData,
13
14
  } = useContext(ForemanActionsBarContext);
14
15
  const { isOpen, close: closeModal } = useBulkModalOpen(
15
16
  'bulk-remove-puppet-ca-proxy'
@@ -24,6 +25,7 @@ const BulkRemovePuppetCAProxyScene = () => {
24
25
  fetchBulkParams={fetchBulkParams}
25
26
  isOpen={isOpen}
26
27
  closeModal={closeModal}
28
+ onSuccess={refreshTableData}
27
29
  handleErrorMessage={__('Failed to remove Puppet CA Proxy')}
28
30
  allHostsMessage={__(
29
31
  'Removing the Puppet CA proxy will affect {boldCount} selected hosts. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!'