[Cloud Security] do not show confirmation modal when updating integration from agentless policy (#176154)

## Summary

Skipping confirmation modal when saving integration with agentless
policy, the same way as in
- https://github.com/elastic/kibana/pull/174741

but for Edit Integration which was missed in the PR mentioned above

Closes:
- https://github.com/elastic/kibana/issues/174600


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Maxim Kholod 2024-02-05 11:51:20 +01:00 committed by GitHub
parent 65291c6493
commit ca38ad5a31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -13,6 +13,7 @@ import { createFleetTestRendererMock } from '../../../../../mock';
import {
useUIExtension,
sendGetAgentStatus,
sendGetOneAgentPolicy,
sendGetOnePackagePolicy,
sendUpgradePackagePolicyDryRun,
@ -176,6 +177,11 @@ const mockPackagePolicyNewVersion = {
package: { name: 'nginx', title: 'Nginx', version: '1.4.0' },
};
const mockPackagePolicyAgentless = {
...mockPackagePolicy,
policy_id: 'agentless',
};
const TestComponent = async () => {
return {
default: () => {
@ -416,4 +422,36 @@ describe('edit package policy page', () => {
expect(renderResult.getByText('Review field conflicts')).toBeInTheDocument();
});
});
it('should not show confirmation modal if package is on agentless policy', async () => {
(sendGetAgentStatus as MockFn).mockResolvedValue({ data: { results: { total: 1 } } });
(useGetOnePackagePolicy as MockFn).mockReturnValue({
data: {
item: mockPackagePolicyAgentless,
},
});
(sendGetOnePackagePolicy as MockFn).mockResolvedValue({
data: {
item: mockPackagePolicyAgentless,
},
});
(sendGetOneAgentPolicy as MockFn).mockResolvedValue({
data: { item: { id: 'agentless', name: 'Agentless policy', namespace: 'default' } },
});
render();
await waitFor(() => {
expect(renderResult.getByText('Collect logs from Nginx instances')).toBeInTheDocument();
});
act(() => {
fireEvent.click(renderResult.getByRole('switch'));
});
await act(async () => {
fireEvent.click(renderResult.getByText('Save integration').closest('button')!);
});
expect(sendUpdatePackagePolicy).toHaveBeenCalled();
});
});

View file

@ -46,6 +46,7 @@ import {
StepConfigurePackagePolicy,
StepDefinePackagePolicy,
} from '../create_package_policy_page/components';
import { AGENTLESS_POLICY_ID } from '../create_package_policy_page/single_page_layout/hooks/setup_technology';
import { HIDDEN_API_REFERENCE_PACKAGES } from '../../../../../../common/constants';
import type { PackagePolicyEditExtensionComponentProps } from '../../../types';
@ -187,7 +188,7 @@ export const EditPackagePolicyForm = memo<{
setFormState('INVALID');
return;
}
if (agentCount !== 0 && formState !== 'CONFIRM') {
if (agentCount !== 0 && policyId !== AGENTLESS_POLICY_ID && formState !== 'CONFIRM') {
setFormState('CONFIRM');
return;
}