@@ -9,9 +9,16 @@ import { Route } from '@kbn/shared-ux-router';
99import React from 'react' ;
1010import { fireEvent , act , waitFor } from '@testing-library/react' ;
1111
12+ import { sendCreateAgentlessPolicy } from '../../../../../../hooks/use_request/agentless_policy' ;
13+
1214import type { MockedFleetStartServices , TestRenderer } from '../../../../../../mock' ;
1315import { createFleetTestRendererMock } from '../../../../../../mock' ;
14- import { FLEET_ROUTING_PATHS , pagePathGetters , PLUGIN_ID } from '../../../../constants' ;
16+ import {
17+ FLEET_ROUTING_PATHS ,
18+ pagePathGetters ,
19+ PLUGIN_ID ,
20+ INTEGRATIONS_PLUGIN_ID ,
21+ } from '../../../../constants' ;
1522import type { CreatePackagePolicyRouteState } from '../../../../types' ;
1623import {
1724 sendCreatePackagePolicyForRq ,
@@ -37,6 +44,8 @@ jest.mock('../components/steps/components/use_policies', () => {
3744 } ;
3845} ) ;
3946
47+ jest . mock ( '../../../../../../hooks/use_request/agentless_policy' ) ;
48+
4049jest . mock ( '../../../../hooks' , ( ) => {
4150 return {
4251 ...jest . requireActual ( '../../../../hooks' ) ,
@@ -718,9 +727,18 @@ describe('When on the package policy create page', () => {
718727 isCloudEnabled : true ,
719728 } ,
720729 } ) ;
721- ( sendCreateAgentPolicy as jest . MockedFunction < any > ) . mockResolvedValue ( {
722- data : {
723- item : { id : 'agentless-policy-1' , name : 'Agentless policy 1' , namespace : 'default' } ,
730+ ( sendCreateAgentlessPolicy as jest . MockedFunction < any > ) . mockResolvedValue ( {
731+ item : {
732+ name : 'Nginx' ,
733+ id : 'policy-1' ,
734+ inputs : [ ] ,
735+ policy_ids : [ 'agent-policy-1' ] ,
736+ supports_agentless : true ,
737+ package : {
738+ name : 'nginx' ,
739+ title : 'Nginx' ,
740+ version : '1.3.0' ,
741+ } ,
724742 } ,
725743 } ) ;
726744
@@ -741,17 +759,19 @@ describe('When on the package policy create page', () => {
741759 fireEvent . click ( renderResult . getByText ( / S a v e a n d c o n t i n u e / ) . closest ( 'button' ) ! ) ;
742760 } ) ;
743761
744- expect ( sendCreateAgentPolicy ) . toHaveBeenCalledWith (
762+ expect ( sendCreateAgentlessPolicy ) . toHaveBeenCalledWith (
745763 expect . objectContaining ( {
746- monitoring_enabled : [ 'logs' , 'metrics' ] ,
747- name : 'Agentless policy for nginx-1' ,
764+ name : 'nginx-1' ,
748765 } ) ,
749- { withSysMonitoring : true }
766+ { format : 'legacy' }
750767 ) ;
751- expect ( sendCreatePackagePolicyForRq ) . toHaveBeenCalled ( ) ;
768+ expect ( sendCreatePackagePolicyForRq ) . not . toHaveBeenCalled ( ) ;
752769
753770 await waitFor ( ( ) => {
754- expect ( renderResult . getByText ( 'Nginx integration added' ) ) . toBeInTheDocument ( ) ;
771+ expect ( useStartServices ( ) . application . navigateToApp ) . toHaveBeenCalledWith (
772+ INTEGRATIONS_PLUGIN_ID ,
773+ { path : '/detail/nginx-1.3.0/policies?openEnrollmentFlyout=agent-policy-1' }
774+ ) ;
755775 } ) ;
756776 } ) ;
757777
@@ -766,19 +786,18 @@ describe('When on the package policy create page', () => {
766786 fireEvent . click ( renderResult . getByText ( / S a v e a n d c o n t i n u e / ) . closest ( 'button' ) ! ) ;
767787 } ) ;
768788
769- expect ( sendCreateAgentPolicy ) . toHaveBeenCalledWith (
789+ expect ( sendCreateAgentlessPolicy ) . toHaveBeenCalledWith (
770790 expect . objectContaining ( {
771- monitoring_enabled : [ 'logs' , 'metrics' ] ,
772- name : 'Agentless policy for nginx-1' ,
773- supports_agentless : true ,
791+ name : 'nginx-1' ,
774792 } ) ,
775- { withSysMonitoring : true }
793+ { format : 'legacy' }
776794 ) ;
777- expect ( sendCreatePackagePolicyForRq ) . toHaveBeenCalled ( ) ;
795+ expect ( sendCreatePackagePolicyForRq ) . not . toHaveBeenCalled ( ) ;
778796
779- await waitFor ( ( ) => {
780- expect ( renderResult . getByText ( 'Nginx integration added' ) ) . toBeInTheDocument ( ) ;
781- } ) ;
797+ expect ( useStartServices ( ) . application . navigateToApp ) . toHaveBeenCalledWith (
798+ INTEGRATIONS_PLUGIN_ID ,
799+ { path : '/detail/nginx-1.3.0/policies?openEnrollmentFlyout=agent-policy-1' }
800+ ) ;
782801 } ) ;
783802 } ) ;
784803 } ) ;
0 commit comments