import { disableAutoSignInMessage , disableAutoSignInResultMessage } from '../protocol/rpc_messages' ; import { SecureChannel } from '../protocol/secure_channel' ; import { FakeProviderConnection } from '../test_utils/channels' ; import { createSpyFrame } from '../test_utils/frames' ; import { DisableAutoSignIn } from './disable_auto_sign_in' ; describe ( 'DisableAutoSignInRequest' , ( ) => { let clientChannel ; let providerChannel ; let request ; let frame ; beforeEach ( ( ) => { let connection = new FakeProviderConnection ( ) ; clientChannel = connection . clientChannel ; providerChannel = connection . providerChannel ; frame = createSpyFrame ( 'frameId' ) ; request = new DisableAutoSignIn ( frame , clientChannel ) ; spyOn ( request , 'dispose' ) . and . callThrough ( ) ; } ) ; afterEach ( ( ) => { request . dispose ( ) ; } ) ; describe ( 'dispatch' , ( ) => { it ( 'should send a RPC message to the frame' , ( ) => { spyOn ( clientChannel , 'send' ) . and . callThrough ( ) ; request . dispatch ( undefined ) ; expect ( clientChannel . send ) . toHaveBeenCalledWith ( disableAutoSignInMessage ( request . id ) ) ; } ) ; } ) ; it ( 'should resolve when result received' , async function ( done ) { let promise = request . dispatch ( undefined ) ; providerChannel . send ( disableAutoSignInResultMessage ( request . id ) ) ; try { await promise ; expect ( request . dispose ) . toHaveBeenCalled ( ) ; done ( ) ; } catch ( err ) { done . fail ( 'Promise should resolve' ) ; } } ) ; } ) ;