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