@@ -22,6 +22,7 @@ import {
2222 STATUS_SESSION_ACTIVE ,
2323 STATUS_SESSION_TERMINATED ,
2424} from 'api/models/session' ;
25+ import { TYPE_TARGET_RDP } from 'api/models/target' ;
2526
2627module ( 'Acceptance | projects | targets | index' , function ( hooks ) {
2728 setupApplicationTest ( hooks ) ;
@@ -43,7 +44,9 @@ module('Acceptance | projects | targets | index', function (hooks) {
4344 '[data-test-targets-sessions-flyout] .hds-flyout__title' ;
4445 const SESSIONS_FLYOUT_CLOSE_BUTTON =
4546 '[data-test-targets-sessions-flyout] .hds-flyout__dismiss' ;
46-
47+ const TARGET_OPEN_BUTTON = ( id ) => `[data-test-targets-open-button="${ id } "]` ;
48+ const TARGET_CONNECT_BUTTON = ( id ) =>
49+ `[data-test-targets-connect-button="${ id } "]` ;
4750 const instances = {
4851 scopes : {
4952 global : null ,
@@ -700,4 +703,111 @@ module('Acceptance | projects | targets | index', function (hooks) {
700703 . dom ( activeSessionFlyoutButtonSelector ( instances . session . targetId ) )
701704 . doesNotExist ( ) ;
702705 } ) ;
706+
707+ test ( 'shows `Open` button for RDP target with preferred client' , async function ( assert ) {
708+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
709+ rdpService . preferredRdpClient = 'windows-app' ;
710+ instances . target . update ( {
711+ type : TYPE_TARGET_RDP ,
712+ } ) ;
713+ await visit ( urls . targets ) ;
714+
715+ assert . dom ( TARGET_OPEN_BUTTON ( instances . target . id ) ) . exists ( ) ;
716+ assert . dom ( TARGET_OPEN_BUTTON ( instances . target . id ) ) . hasText ( 'Open' ) ;
717+ assert . dom ( '[data-test-icon=external-link]' ) . exists ( ) ;
718+ } ) ;
719+
720+ test ( 'shows `Connect` button for RDP target with no preferred client' , async function ( assert ) {
721+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
722+ rdpService . preferredRdpClient = 'none' ;
723+ instances . target . update ( {
724+ type : TYPE_TARGET_RDP ,
725+ } ) ;
726+ await visit ( urls . targets ) ;
727+
728+ assert . dom ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) . exists ( ) ;
729+ assert . dom ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) . hasText ( 'Connect' ) ;
730+ assert . dom ( '[data-test-icon=external-link]' ) . doesNotExist ( ) ;
731+ } ) ;
732+
733+ test ( 'shows `Connect` button for non-RDP target' , async function ( assert ) {
734+ await visit ( urls . targets ) ;
735+
736+ assert . dom ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) . exists ( ) ;
737+ assert . dom ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) . hasText ( 'Connect' ) ;
738+ } ) ;
739+
740+ test ( 'clicking `Open` button for RDP target calls launchRdpClient IPC' , async function ( assert ) {
741+ this . ipcStub . withArgs ( 'cliExists' ) . returns ( true ) ;
742+
743+ const rdpService = this . owner . lookup ( 'service:rdp' ) ;
744+ rdpService . preferredRdpClient = 'windows-app' ;
745+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
746+
747+ this . ipcStub . withArgs ( 'connect' ) . returns ( {
748+ session_id : instances . session . id ,
749+ address : 'a_123' ,
750+ port : 'p_123' ,
751+ protocol : 'rdp' ,
752+ } ) ;
753+ this . ipcStub . withArgs ( 'launchRdpClient' ) . resolves ( ) ;
754+
755+ // visit targets page
756+ await visit ( urls . targets ) ;
757+
758+ assert . dom ( TARGET_OPEN_BUTTON ( instances . target . id ) ) . exists ( ) ;
759+
760+ await click ( TARGET_OPEN_BUTTON ( instances . target . id ) ) ;
761+
762+ assert . ok ( this . ipcStub . calledWith ( 'launchRdpClient' , instances . session . id ) ) ;
763+ } ) ;
764+
765+ test ( 'clicking `Connect` button for RDP target without preferred client calls connect IPC' , async function ( assert ) {
766+ this . ipcStub . withArgs ( 'cliExists' ) . returns ( true ) ;
767+
768+ const rdpService = this . owner . lookup ( 'service:rdp' ) ;
769+ rdpService . preferredRdpClient = 'none' ;
770+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
771+
772+ this . ipcStub . withArgs ( 'connect' ) . returns ( {
773+ session_id : instances . session . id ,
774+ address : 'a_123' ,
775+ port : 'p_123' ,
776+ protocol : 'rdp' ,
777+ } ) ;
778+
779+ // visit targets page
780+ await visit ( urls . targets ) ;
781+
782+ assert . dom ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) . exists ( ) ;
783+
784+ await click ( TARGET_CONNECT_BUTTON ( instances . target . id ) ) ;
785+
786+ assert . ok ( this . ipcStub . calledWith ( 'connect' ) ) ;
787+ } ) ;
788+
789+ test ( 'shows confirm modal when connection error occurs on launching rdp client' , async function ( assert ) {
790+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
791+ rdpService . preferredRdpClient = 'windows-app' ;
792+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
793+
794+ this . ipcStub . withArgs ( 'cliExists' ) . returns ( true ) ;
795+ // target quick connection is a success but launching RDP client fails
796+ this . ipcStub . withArgs ( 'connect' ) . returns ( {
797+ session_id : instances . session . id ,
798+ address : 'a_123' ,
799+ port : 'p_123' ,
800+ protocol : 'rdp' ,
801+ } ) ;
802+ this . ipcStub . withArgs ( 'launchRdpClient' ) . rejects ( ) ;
803+
804+ const confirmService = this . owner . lookup ( 'service:confirm' ) ;
805+ confirmService . enabled = true ;
806+
807+ await visit ( urls . targets ) ;
808+ await click ( `[data-test-targets-open-button="${ instances . target . id } "]` ) ;
809+
810+ // Assert that the confirm modal appears
811+ assert . dom ( HDS_DIALOG_MODAL ) . isVisible ( ) ;
812+ } ) ;
703813} ) ;
0 commit comments