foreman_puppet 11.0.0 → 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.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
- data/app/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller.rb +75 -1
- data/app/services/concerns/foreman_puppet/extensions/bulk_hosts_manager.rb +18 -0
- data/config/api_routes.rb +1 -0
- data/db/seeds.d/111_puppet_proxy_feature.rb +1 -1
- data/lib/foreman_puppet/register.rb +1 -0
- data/lib/foreman_puppet/version.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller_test.rb +93 -0
- data/test/services/foreman_puppet/bulk_hosts_manager_test.rb +45 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +8 -0
- data/webpack/global_index.js +18 -1
- data/webpack/src/Extends/Hosts/ActionsBar/index.js +20 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/__tests__/actions.test.js +0 -7
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/BulkChangePuppetEnvironmentModal.js +239 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/BulkChangePuppetEnvironmentModal.test.js +155 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/actions.test.js +49 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/index.test.js +66 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/actions.js +37 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/index.js +30 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/__tests__/index.test.js +160 -47
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/__tests__/actions.test.js +0 -6
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/__tests__/index.test.js +136 -39
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/BulkRemovePuppetEnvironmentModal.js +148 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/BulkRemovePuppetEnvironmentModal.test.js +80 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/index.test.js +66 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/index.js +30 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/__tests__/index.test.js +123 -34
- data/webpack/src/Router/routes.fixtures.js +13 -0
- data/webpack/src/Router/routes.test.js +68 -8
- data/webpack/src/foreman_puppet_host_form.test.js +3 -1
- data/webpack/test_setup.js +1 -0
- metadata +14 -3
- data/webpack/src/Router/__snapshots__/routes.test.js.snap +0 -3
|
@@ -1,68 +1,165 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
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
|
|
13
|
+
import { BULK_REMOVE_PUPPET_CA_PROXY_KEY } from '../../BulkRemoveProxyCommon/actions';
|
|
9
14
|
|
|
10
|
-
|
|
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();
|
|
18
|
+
const fetchBulkParams = jest.fn(() => 'id ^ (1,2)');
|
|
21
19
|
const refreshTableData = jest.fn();
|
|
22
|
-
const
|
|
20
|
+
const defaultContextValue = {
|
|
23
21
|
selectAllHostsMode: false,
|
|
24
22
|
selectedCount: 2,
|
|
25
23
|
selectedResults: [1, 2],
|
|
26
24
|
fetchBulkParams,
|
|
27
25
|
refreshTableData,
|
|
28
26
|
};
|
|
27
|
+
let renderResult;
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
openBulkModal('bulk-remove-puppet-ca-proxy', false);
|
|
33
|
-
});
|
|
29
|
+
const renderScene = (contextOverrides = {}, isOpen = true) => {
|
|
30
|
+
openBulkModal('bulk-remove-puppet-ca-proxy', isOpen);
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
renderResult = renderWithStoreAndI18n(
|
|
33
|
+
<ForemanActionsBarContext.Provider
|
|
34
|
+
value={{ ...defaultContextValue, ...contextOverrides }}
|
|
35
|
+
>
|
|
39
36
|
<BulkRemovePuppetCAProxyScene />
|
|
40
37
|
</ForemanActionsBarContext.Provider>
|
|
41
38
|
);
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
});
|
|
46
70
|
|
|
47
|
-
expect(
|
|
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(
|
|
48
132
|
expect.objectContaining({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onSuccess: refreshTableData,
|
|
57
|
-
handleErrorMessage: 'Failed to remove Puppet CA Proxy',
|
|
58
|
-
allHostsMessage:
|
|
59
|
-
'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!',
|
|
60
|
-
someHostsMessage:
|
|
61
|
-
'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!',
|
|
62
|
-
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
|
+
},
|
|
63
140
|
})
|
|
64
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
|
+
});
|
|
65
157
|
|
|
66
|
-
|
|
158
|
+
await waitFor(() => {
|
|
159
|
+
expect(refreshTableData).toHaveBeenCalledTimes(1);
|
|
160
|
+
});
|
|
161
|
+
expect(
|
|
162
|
+
screen.queryByRole('dialog', { name: 'Remove Puppet CA Proxy' })
|
|
163
|
+
).not.toBeInTheDocument();
|
|
67
164
|
});
|
|
68
165
|
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { FormattedMessage } from 'react-intl';
|
|
4
|
+
import { useDispatch } from 'react-redux';
|
|
5
|
+
import { Modal, Button, TextContent, Text } from '@patternfly/react-core';
|
|
6
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
|
7
|
+
import { addToast } from 'foremanReact/components/ToastsList/slice';
|
|
8
|
+
import { useForemanOrganization } from 'foremanReact/Root/Context/ForemanContext';
|
|
9
|
+
import { bulkActionErrorToastParams } from '../toastHelpers';
|
|
10
|
+
import {
|
|
11
|
+
bulkChangePuppetEnvironment,
|
|
12
|
+
BULK_CHANGE_PUPPET_ENVIRONMENT_KEY,
|
|
13
|
+
} from '../BulkChangePuppetEnvironment/actions';
|
|
14
|
+
|
|
15
|
+
const BulkRemovePuppetEnvironmentModal = ({
|
|
16
|
+
isOpen,
|
|
17
|
+
closeModal,
|
|
18
|
+
selectAllHostsMode,
|
|
19
|
+
selectedCount,
|
|
20
|
+
fetchBulkParams,
|
|
21
|
+
onSuccess: onSuccessCallback,
|
|
22
|
+
}) => {
|
|
23
|
+
const dispatch = useDispatch();
|
|
24
|
+
const currentOrganization = useForemanOrganization();
|
|
25
|
+
|
|
26
|
+
const handleModalClose = () => {
|
|
27
|
+
closeModal();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handleError = response => {
|
|
31
|
+
handleModalClose();
|
|
32
|
+
dispatch(
|
|
33
|
+
addToast(
|
|
34
|
+
bulkActionErrorToastParams(
|
|
35
|
+
response,
|
|
36
|
+
__('Failed to remove Puppet Environment'),
|
|
37
|
+
BULK_CHANGE_PUPPET_ENVIRONMENT_KEY
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleSuccess = response => {
|
|
44
|
+
dispatch(
|
|
45
|
+
addToast({
|
|
46
|
+
type: 'success',
|
|
47
|
+
message: response.data.message,
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
try {
|
|
51
|
+
if (onSuccessCallback) onSuccessCallback();
|
|
52
|
+
} finally {
|
|
53
|
+
handleModalClose();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleConfirm = () => {
|
|
58
|
+
const requestBody = {
|
|
59
|
+
included: {
|
|
60
|
+
search: fetchBulkParams(),
|
|
61
|
+
},
|
|
62
|
+
environment_id: null,
|
|
63
|
+
organization_id: currentOrganization?.id,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
dispatch(
|
|
67
|
+
bulkChangePuppetEnvironment(requestBody, handleSuccess, handleError)
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const modalActions = [
|
|
72
|
+
<Button
|
|
73
|
+
key="remove"
|
|
74
|
+
ouiaId="bulk-remove-puppet-environment-modal-remove-button"
|
|
75
|
+
variant="primary"
|
|
76
|
+
onClick={handleConfirm}
|
|
77
|
+
>
|
|
78
|
+
{__('Remove Puppet Environment')}
|
|
79
|
+
</Button>,
|
|
80
|
+
<Button
|
|
81
|
+
key="cancel"
|
|
82
|
+
ouiaId="bulk-remove-puppet-environment-modal-cancel-button"
|
|
83
|
+
variant="link"
|
|
84
|
+
onClick={handleModalClose}
|
|
85
|
+
>
|
|
86
|
+
{__('Cancel')}
|
|
87
|
+
</Button>,
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Modal
|
|
92
|
+
isOpen={isOpen}
|
|
93
|
+
onClose={handleModalClose}
|
|
94
|
+
onEscapePress={handleModalClose}
|
|
95
|
+
title={__('Remove Puppet Environment')}
|
|
96
|
+
width="50%"
|
|
97
|
+
position="top"
|
|
98
|
+
actions={modalActions}
|
|
99
|
+
id="bulk-remove-puppet-environment"
|
|
100
|
+
key="bulk-remove-puppet-environment"
|
|
101
|
+
ouiaId="bulk-remove-puppet-environment"
|
|
102
|
+
>
|
|
103
|
+
<TextContent>
|
|
104
|
+
<Text ouiaId="bulk-remove-puppet-environment-options">
|
|
105
|
+
{selectAllHostsMode ? (
|
|
106
|
+
<FormattedMessage
|
|
107
|
+
id="bulk-remove-puppet-environment-warning-message-all"
|
|
108
|
+
defaultMessage={__(
|
|
109
|
+
'Removing the Puppet environment will affect {boldCount} selected hosts.'
|
|
110
|
+
)}
|
|
111
|
+
values={{
|
|
112
|
+
boldCount: <strong>{__('All')}</strong>,
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
) : (
|
|
116
|
+
<FormattedMessage
|
|
117
|
+
id="bulk-remove-puppet-environment-warning-message"
|
|
118
|
+
defaultMessage={__(
|
|
119
|
+
'Removing the Puppet environment will affect {boldCount} selected {count, plural, one {host} other {hosts}}.'
|
|
120
|
+
)}
|
|
121
|
+
values={{
|
|
122
|
+
count: selectedCount,
|
|
123
|
+
boldCount: <strong>{selectedCount}</strong>,
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
)}
|
|
127
|
+
</Text>
|
|
128
|
+
</TextContent>
|
|
129
|
+
</Modal>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
BulkRemovePuppetEnvironmentModal.propTypes = {
|
|
134
|
+
isOpen: PropTypes.bool,
|
|
135
|
+
closeModal: PropTypes.func,
|
|
136
|
+
fetchBulkParams: PropTypes.func.isRequired,
|
|
137
|
+
onSuccess: PropTypes.func,
|
|
138
|
+
selectedCount: PropTypes.number.isRequired,
|
|
139
|
+
selectAllHostsMode: PropTypes.bool.isRequired,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
BulkRemovePuppetEnvironmentModal.defaultProps = {
|
|
143
|
+
isOpen: false,
|
|
144
|
+
closeModal: () => {},
|
|
145
|
+
onSuccess: undefined,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export default BulkRemovePuppetEnvironmentModal;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { IntlProvider } from 'react-intl';
|
|
5
|
+
import { useDispatch } from 'react-redux';
|
|
6
|
+
|
|
7
|
+
import BulkRemovePuppetEnvironmentModal from '../BulkRemovePuppetEnvironmentModal';
|
|
8
|
+
import { bulkChangePuppetEnvironment } from '../../BulkChangePuppetEnvironment/actions';
|
|
9
|
+
|
|
10
|
+
jest.mock('react-redux', () => ({
|
|
11
|
+
...jest.requireActual('react-redux'),
|
|
12
|
+
useDispatch: jest.fn(),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock('foremanReact/Root/Context/ForemanContext', () => ({
|
|
16
|
+
useForemanOrganization: jest.fn(() => ({ id: 23 })),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
jest.mock('../../BulkChangePuppetEnvironment/actions', () => ({
|
|
20
|
+
bulkChangePuppetEnvironment: jest.fn(() => ({
|
|
21
|
+
type: 'BULK_CHANGE_PUPPET_ENVIRONMENT',
|
|
22
|
+
})),
|
|
23
|
+
BULK_CHANGE_PUPPET_ENVIRONMENT_KEY: 'BULK_CHANGE_PUPPET_ENVIRONMENT',
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
describe('BulkRemovePuppetEnvironmentModal', () => {
|
|
27
|
+
const dispatch = jest.fn();
|
|
28
|
+
|
|
29
|
+
const renderComponent = (fetchBulkParams = jest.fn()) =>
|
|
30
|
+
render(
|
|
31
|
+
<IntlProvider locale="en">
|
|
32
|
+
<BulkRemovePuppetEnvironmentModal
|
|
33
|
+
isOpen
|
|
34
|
+
closeModal={jest.fn()}
|
|
35
|
+
fetchBulkParams={fetchBulkParams}
|
|
36
|
+
selectedCount={2}
|
|
37
|
+
selectAllHostsMode={false}
|
|
38
|
+
/>
|
|
39
|
+
</IntlProvider>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
jest.clearAllMocks();
|
|
44
|
+
useDispatch.mockReturnValue(dispatch);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders the removal warning', () => {
|
|
48
|
+
renderComponent();
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
screen.getAllByText('Remove Puppet Environment')[0]
|
|
52
|
+
).toBeInTheDocument();
|
|
53
|
+
expect(
|
|
54
|
+
screen.getByText(/Removing the Puppet environment will affect/)
|
|
55
|
+
).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('submits organization scope with the bulk remove request', () => {
|
|
59
|
+
const fetchBulkParams = jest.fn(
|
|
60
|
+
() => 'organization = "Default Organization"'
|
|
61
|
+
);
|
|
62
|
+
renderComponent(fetchBulkParams);
|
|
63
|
+
|
|
64
|
+
fireEvent.click(
|
|
65
|
+
screen.getByRole('button', { name: 'Remove Puppet Environment' })
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(bulkChangePuppetEnvironment).toHaveBeenCalledWith(
|
|
69
|
+
{
|
|
70
|
+
included: {
|
|
71
|
+
search: 'organization = "Default Organization"',
|
|
72
|
+
},
|
|
73
|
+
environment_id: null,
|
|
74
|
+
organization_id: 23,
|
|
75
|
+
},
|
|
76
|
+
expect.any(Function),
|
|
77
|
+
expect.any(Function)
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
});
|
data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/index.test.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import { useBulkModalOpen } from 'foremanReact/common/BulkModalStateHelper';
|
|
5
|
+
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
|
|
6
|
+
|
|
7
|
+
import BulkRemovePuppetEnvironmentScene from '../index';
|
|
8
|
+
import BulkRemovePuppetEnvironmentModal from '../BulkRemovePuppetEnvironmentModal';
|
|
9
|
+
|
|
10
|
+
jest.mock('foremanReact/common/BulkModalStateHelper', () => ({
|
|
11
|
+
useBulkModalOpen: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('../BulkRemovePuppetEnvironmentModal', () => ({
|
|
15
|
+
__esModule: true,
|
|
16
|
+
default: jest.fn(() => null),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('BulkRemovePuppetEnvironmentScene', () => {
|
|
20
|
+
const fetchBulkParams = jest.fn();
|
|
21
|
+
const refreshTableData = jest.fn();
|
|
22
|
+
const contextValue = {
|
|
23
|
+
selectAllHostsMode: false,
|
|
24
|
+
selectedCount: 2,
|
|
25
|
+
selectedResults: [1, 2],
|
|
26
|
+
fetchBulkParams,
|
|
27
|
+
refreshTableData,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
useBulkModalOpen.mockReturnValue({
|
|
33
|
+
isOpen: true,
|
|
34
|
+
close: jest.fn(),
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('opens with bulk modal state and passes expected props', () => {
|
|
39
|
+
let component;
|
|
40
|
+
act(() => {
|
|
41
|
+
component = renderer.create(
|
|
42
|
+
<ForemanActionsBarContext.Provider value={contextValue}>
|
|
43
|
+
<BulkRemovePuppetEnvironmentScene />
|
|
44
|
+
</ForemanActionsBarContext.Provider>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const componentType =
|
|
49
|
+
BulkRemovePuppetEnvironmentModal.default ||
|
|
50
|
+
BulkRemovePuppetEnvironmentModal;
|
|
51
|
+
const { props } = component.root.findByType(componentType);
|
|
52
|
+
|
|
53
|
+
expect(props).toEqual(
|
|
54
|
+
expect.objectContaining({
|
|
55
|
+
fetchBulkParams,
|
|
56
|
+
selectedCount: 2,
|
|
57
|
+
selectAllHostsMode: false,
|
|
58
|
+
isOpen: true,
|
|
59
|
+
closeModal: expect.any(Function),
|
|
60
|
+
onSuccess: refreshTableData,
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
component.unmount();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -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 BulkRemovePuppetEnvironmentModal from './BulkRemovePuppetEnvironmentModal';
|
|
5
|
+
|
|
6
|
+
const BulkRemovePuppetEnvironmentScene = () => {
|
|
7
|
+
const {
|
|
8
|
+
selectAllHostsMode,
|
|
9
|
+
selectedCount,
|
|
10
|
+
fetchBulkParams,
|
|
11
|
+
refreshTableData,
|
|
12
|
+
} = useContext(ForemanActionsBarContext);
|
|
13
|
+
const { isOpen, close: closeModal } = useBulkModalOpen(
|
|
14
|
+
'bulk-remove-puppet-environment'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<BulkRemovePuppetEnvironmentModal
|
|
19
|
+
fetchBulkParams={fetchBulkParams}
|
|
20
|
+
selectedCount={selectedCount}
|
|
21
|
+
selectAllHostsMode={selectAllHostsMode}
|
|
22
|
+
isOpen={isOpen}
|
|
23
|
+
closeModal={closeModal}
|
|
24
|
+
onSuccess={refreshTableData}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { BulkRemovePuppetEnvironmentModal };
|
|
30
|
+
export default BulkRemovePuppetEnvironmentScene;
|