@@ -17,6 +17,7 @@ import { setupApplicationTest } from 'desktop/tests/helpers';
1717import WindowMockIPC from '../../../helpers/window-mock-ipc' ;
1818import setupStubs from 'api/test-support/handlers/cache-daemon-search' ;
1919import { setRunOptions } from 'ember-a11y-testing/test-support' ;
20+ import { TYPE_TARGET_RDP } from 'api/models/target' ;
2021
2122module ( 'Acceptance | projects | targets | target' , function ( hooks ) {
2223 setupApplicationTest ( hooks ) ;
@@ -25,6 +26,7 @@ module('Acceptance | projects | targets | target', function (hooks) {
2526 const TARGET_RESOURCE_LINK = ( id ) => `[data-test-visit-target="${ id } "]` ;
2627 const TARGET_TABLE_CONNECT_BUTTON = ( id ) =>
2728 `[data-test-targets-connect-button="${ id } "]` ;
29+ const TARGET_OPEN_BUTTON = `[data-test-target-detail-open-button]` ;
2830 const TARGET_CONNECT_BUTTON = '[data-test-target-detail-connect-button]' ;
2931 const TARGET_HOST_SOURCE_CONNECT_BUTTON = ( id ) =>
3032 `[data-test-target-connect-button=${ id } ]` ;
@@ -570,6 +572,7 @@ module('Acceptance | projects | targets | target', function (hooks) {
570572 assert . strictEqual ( currentURL ( ) , urls . targetWithOneHost ) ;
571573 assert . dom ( '.aliases' ) . exists ( ) ;
572574 } ) ;
575+
573576 test ( 'user can connect to a target without read permissions for host-set' , async function ( assert ) {
574577 setRunOptions ( {
575578 rules : {
@@ -625,4 +628,99 @@ module('Acceptance | projects | targets | target', function (hooks) {
625628
626629 assert . dom ( APP_STATE_TITLE ) . hasText ( 'Connected' ) ;
627630 } ) ;
631+
632+ test ( 'shows `Open` and `Connect` button for RDP target with preferred client' , async function ( assert ) {
633+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
634+ rdpService . preferredRdpClient = 'windows-app' ;
635+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
636+
637+ this . stubCacheDaemonSearch ( ) ;
638+
639+ await visit ( urls . target ) ;
640+
641+ assert . dom ( TARGET_OPEN_BUTTON ) . exists ( ) ;
642+ assert . dom ( TARGET_OPEN_BUTTON ) . hasText ( 'Open' ) ;
643+ assert . dom ( TARGET_CONNECT_BUTTON ) . exists ( ) ;
644+ assert . dom ( TARGET_CONNECT_BUTTON ) . hasText ( 'Connect' ) ;
645+ } ) ;
646+
647+ test ( 'shows "Connect" button for RDP target without preferred client' , async function ( assert ) {
648+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
649+ rdpService . preferredRdpClient = null ;
650+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
651+
652+ this . stubCacheDaemonSearch ( ) ;
653+
654+ await visit ( urls . target ) ;
655+
656+ assert . dom ( TARGET_CONNECT_BUTTON ) . exists ( ) ;
657+ assert . dom ( TARGET_CONNECT_BUTTON ) . hasText ( 'Connect' ) ;
658+ } ) ;
659+
660+ test ( 'clicking `open` button for RDP target triggers launchRdpClient' , async function ( assert ) {
661+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
662+ rdpService . preferredRdpClient = 'windows-app' ;
663+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
664+
665+ this . ipcStub . withArgs ( 'cliExists' ) . returns ( true ) ;
666+ this . ipcStub . withArgs ( 'connect' ) . returns ( {
667+ session_id : instances . session . id ,
668+ address : 'a_123' ,
669+ port : 'p_123' ,
670+ protocol : 'rdp' ,
671+ } ) ;
672+ this . stubCacheDaemonSearch ( ) ;
673+ this . ipcStub . withArgs ( 'launchRdpClient' ) . resolves ( ) ;
674+
675+ const confirmService = this . owner . lookup ( 'service:confirm' ) ;
676+ confirmService . enabled = true ;
677+
678+ await visit ( urls . target ) ;
679+
680+ await click ( TARGET_OPEN_BUTTON ) ;
681+
682+ assert . ok ( this . ipcStub . calledWith ( 'launchRdpClient' , instances . session . id ) ) ;
683+ } ) ;
684+
685+ test ( 'shows `Connect` button for rdp target without preferred client' , async function ( assert ) {
686+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
687+ rdpService . preferredRdpClient = null ;
688+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
689+
690+ this . stubCacheDaemonSearch ( ) ;
691+ this . ipcStub . withArgs ( 'cliExists' ) . returns ( true ) ;
692+ this . ipcStub . withArgs ( 'connect' ) . returns ( {
693+ session_id : instances . session . id ,
694+ address : 'a_123' ,
695+ port : 'p_123' ,
696+ protocol : 'rdp' ,
697+ } ) ;
698+ await visit ( urls . target ) ;
699+
700+ assert . dom ( TARGET_CONNECT_BUTTON ) . exists ( ) ;
701+ assert . dom ( TARGET_CONNECT_BUTTON ) . hasText ( 'Connect' ) ;
702+ assert . dom ( TARGET_OPEN_BUTTON ) . doesNotExist ( ) ;
703+
704+ await click ( TARGET_CONNECT_BUTTON ) ;
705+
706+ assert . ok ( this . ipcStub . calledWith ( 'connect' ) ) ;
707+ assert . notOk ( this . ipcStub . calledWith ( 'launchRdpClient' ) ) ;
708+ } ) ;
709+
710+ test ( 'shows confirm modal when quickConnectAndLaunchRdp fails' , async function ( assert ) {
711+ let rdpService = this . owner . lookup ( 'service:rdp' ) ;
712+ rdpService . preferredRdpClient = 'windows-app' ;
713+ instances . target . update ( { type : TYPE_TARGET_RDP } ) ;
714+ this . stubCacheDaemonSearch ( ) ;
715+
716+ const confirmService = this . owner . lookup ( 'service:confirm' ) ;
717+ confirmService . enabled = true ;
718+
719+ await visit ( urls . target ) ;
720+
721+ await click ( '[data-test-target-detail-open-button]' ) ;
722+
723+ // The modal should be visible because cliExists was not stubbed, and the connection failed
724+ assert . dom ( HDS_DIALOG_MODAL ) . isVisible ( ) ;
725+ } ) ;
628726} ) ;
0 commit comments