@@ -14,12 +14,15 @@ import {
1414import React from 'react' ;
1515import { getEndpointConsoleCommands } from '../../lib/console_commands_definition' ;
1616import { responseActionsHttpMocks } from '../../../../mocks/response_actions_http_mocks' ;
17- import { enterConsoleCommand } from '../../../console/mocks' ;
17+ import { enterConsoleCommand , getConsoleSelectorsAndActionMock } from '../../../console/mocks' ;
1818import { waitFor } from '@testing-library/react' ;
1919import userEvent , { type UserEvent } from '@testing-library/user-event' ;
2020import type { getEndpointAuthzInitialState } from '../../../../../../common/endpoint/service/authz' ;
2121import { getEndpointAuthzInitialStateMock } from '../../../../../../common/endpoint/service/authz/mocks' ;
22- import type { ResponseActionAgentType } from '../../../../../../common/endpoint/service/response_actions/constants' ;
22+ import type {
23+ EndpointCapabilities ,
24+ ResponseActionAgentType ,
25+ } from '../../../../../../common/endpoint/service/response_actions/constants' ;
2326import {
2427 ENDPOINT_CAPABILITIES ,
2528 RESPONSE_ACTION_AGENT_TYPE ,
@@ -58,6 +61,8 @@ describe('When using cancel action from response actions console', () => {
5861 let mockedContext : AppContextTestRender ;
5962 let user : UserEvent ;
6063 let apiMocks : ReturnType < typeof responseActionsHttpMocks > ;
64+ let endpointCapabilities : EndpointCapabilities [ ] ;
65+ let consoleMockUtils : ReturnType < typeof getConsoleSelectorsAndActionMock > ;
6166
6267 // Simplified render function with minimal setup
6368 const renderConsole = async (
@@ -71,8 +76,8 @@ describe('When using cancel action from response actions console', () => {
7176 'data-test-subj' : 'test' ,
7277 commands : getEndpointConsoleCommands ( {
7378 agentType,
79+ endpointCapabilities,
7480 endpointAgentId : 'a.b.c' ,
75- endpointCapabilities : [ ...ENDPOINT_CAPABILITIES ] ,
7681 endpointPrivileges : {
7782 ...getEndpointAuthzInitialStateMock ( ) ,
7883 loading : false ,
@@ -85,6 +90,7 @@ describe('When using cancel action from response actions console', () => {
8590 />
8691 ) ;
8792
93+ consoleMockUtils = getConsoleSelectorsAndActionMock ( renderResult , user ) ;
8894 const consoleManagerMockAccess = getConsoleManagerMockRenderResultQueriesAndActions (
8995 user ,
9096 renderResult
@@ -107,6 +113,7 @@ describe('When using cancel action from response actions console', () => {
107113 beforeEach ( ( ) => {
108114 user = userEvent . setup ( { advanceTimers : jest . advanceTimersByTime } ) ;
109115 mockedContext = createAppRootMockRenderer ( ) ;
116+ endpointCapabilities = [ ...ENDPOINT_CAPABILITIES ] ;
110117
111118 // Set default experimental flags
112119 mockedContext . setExperimentalFlag ( {
@@ -196,6 +203,22 @@ describe('When using cancel action from response actions console', () => {
196203 expect ( renderResult . getByTestId ( 'cancel-action-arg-0' ) ) . toBeTruthy ( ) ;
197204 } ) ;
198205 } ) ;
206+
207+ if ( agentType === 'endpoint' ) {
208+ it ( 'should have a --force argument available' , async ( ) => {
209+ const renderResult = await renderConsole ( agentType ) ;
210+ await enterConsoleCommand ( renderResult , user , 'cancel --help' ) ;
211+
212+ expect ( renderResult . getByTestId ( 'test-commandUsage' ) . textContent ) . toContain ( '--force' ) ;
213+ } ) ;
214+ } else {
215+ it ( 'should NOT have a --force argument available' , async ( ) => {
216+ const renderResult = await renderConsole ( agentType ) ;
217+ await enterConsoleCommand ( renderResult , user , 'cancel --help' ) ;
218+
219+ expect ( renderResult . getByTestId ( 'test-commandUsage' ) . textContent ) . not . toContain ( '--force' ) ;
220+ } ) ;
221+ }
199222 } ) ;
200223
201224 describe . each ( UNSUPPORTED_AGENT_TYPES ) ( 'Unsupported agent type: %s' , ( agentType ) => {
@@ -239,8 +262,18 @@ describe('When using cancel action from response actions console', () => {
239262 } ) ;
240263
241264 describe ( 'and agent type is endpoint' , ( ) => {
242- it ( 'should display help panel "+" button disabled if Endpoint does not support runscript' , async ( ) => {
243- //
265+ it ( 'should display help panel "+" button disabled if Endpoint does not support cancel' , async ( ) => {
266+ endpointCapabilities = ENDPOINT_CAPABILITIES . filter ( ( capability ) => capability !== 'cancel' ) ;
267+ const renderResult = await renderConsole ( 'endpoint' ) ;
268+ consoleMockUtils . openHelpPanel ( ) ;
269+
270+ expect (
271+ (
272+ renderResult . getByTestId (
273+ 'test-commandList-Responseactions-cancel-addToInput'
274+ ) as HTMLButtonElement
275+ ) . disabled
276+ ) . toBe ( true ) ;
244277 } ) ;
245278 } ) ;
246279
0 commit comments