@@ -421,9 +421,58 @@ describe('LoginForm', () => {
421421 expect ( window . location . href ) . toBe ( currentURL ) ;
422422 expect ( coreStartMock . notifications . toasts . addError ) . toHaveBeenCalledWith ( failureReason , {
423423 title : 'Could not perform login.' ,
424+ toastMessage : 'Oh no!' ,
424425 } ) ;
425426 } ) ;
426427
428+ it ( 'shows error with message in the `body`' , async ( ) => {
429+ const currentURL = `https://some-host/login?next=${ encodeURIComponent (
430+ '/some-base-path/app/kibana#/home?_g=()'
431+ ) } `;
432+
433+ const coreStartMock = coreMock . createStart ( { basePath : '/some-base-path' } ) ;
434+ coreStartMock . http . post . mockRejectedValue ( {
435+ body : { message : 'Oh no! But with much more details!' } ,
436+ message : 'Oh no!' ,
437+ } ) ;
438+
439+ window . location . href = currentURL ;
440+ const wrapper = mountWithIntl (
441+ < LoginForm
442+ http = { coreStartMock . http }
443+ notifications = { coreStartMock . notifications }
444+ loginAssistanceMessage = ""
445+ selector = { {
446+ enabled : true ,
447+ providers : [
448+ { type : 'basic' , name : 'basic' , usesLoginForm : true } ,
449+ { type : 'saml' , name : 'saml1' , usesLoginForm : false } ,
450+ ] ,
451+ } }
452+ />
453+ ) ;
454+
455+ expectPageMode ( wrapper , PageMode . Selector ) ;
456+
457+ wrapper . findWhere ( ( node ) => node . key ( ) === 'saml1' ) . simulate ( 'click' ) ;
458+
459+ await act ( async ( ) => {
460+ await nextTick ( ) ;
461+ wrapper . update ( ) ;
462+ } ) ;
463+
464+ expect ( coreStartMock . http . post ) . toHaveBeenCalledTimes ( 1 ) ;
465+ expect ( coreStartMock . http . post ) . toHaveBeenCalledWith ( '/internal/security/login' , {
466+ body : JSON . stringify ( { providerType : 'saml' , providerName : 'saml1' , currentURL } ) ,
467+ } ) ;
468+
469+ expect ( window . location . href ) . toBe ( currentURL ) ;
470+ expect ( coreStartMock . notifications . toasts . addError ) . toHaveBeenCalledWith (
471+ new Error ( 'Oh no! But with much more details!' ) ,
472+ { title : 'Could not perform login.' , toastMessage : 'Oh no!' }
473+ ) ;
474+ } ) ;
475+
427476 it ( 'properly switches to login form' , async ( ) => {
428477 const currentURL = `https://some-host/login?next=${ encodeURIComponent (
429478 '/some-base-path/app/kibana#/home?_g=()'
0 commit comments