@@ -7,7 +7,6 @@ import * as IndexModule from './index';
77import * as ReactUtils from 'fxa-react/lib/utils' ;
88import * as cache from '../../lib/cache' ;
99
10- import React from 'react' ;
1110import { waitFor } from '@testing-library/react' ;
1211import { LocationProvider } from '@reach/router' ;
1312import { useValidatedQueryParams } from '../../lib/hooks/useValidate' ;
@@ -971,6 +970,75 @@ describe('IndexContainer', () => {
971970 expect ( currentIndexProps ?. errorBannerMessage ) . toBeDefined ( ) ;
972971 } ) ;
973972 } ) ;
973+
974+ describe ( 'useFxAStatusResult.supportsCanLinkAccountUid and processEmailSubmission' , ( ) => {
975+ beforeEach ( ( ) => {
976+ jest . spyOn ( cache , 'currentAccount' ) . mockReturnValue ( {
977+ uid : 'abc123' ,
978+ email : MOCK_EMAIL ,
979+ lastLogin : Date . now ( ) ,
980+ } ) ;
981+ } ) ;
982+
983+ it ( 'shows loading spinner and does not call fxaCanLinkAccount when supportsCanLinkAccountUid is undefined' , async ( ) => {
984+ mockUseFxAStatusResult = mockUseFxAStatus ( {
985+ supportsCanLinkAccountUid : undefined ,
986+ } ) ;
987+
988+ const { getByText } = renderWithLocalizationProvider (
989+ < LocationProvider >
990+ < IndexContainer
991+ integration = { integration }
992+ serviceName = { MozServices . FirefoxSync }
993+ useFxAStatusResult = { mockUseFxAStatusResult }
994+ />
995+ </ LocationProvider >
996+ ) ;
997+
998+ expect ( getByText ( 'LoadingSpinner' ) ) . toBeInTheDocument ( ) ;
999+ expect ( firefox . fxaCanLinkAccount ) . not . toHaveBeenCalled ( ) ;
1000+ } ) ;
1001+
1002+ it ( 'does not call fxaCanLinkAccount when supportsCanLinkAccountUid is true' , async ( ) => {
1003+ mockUseFxAStatusResult = mockUseFxAStatus ( {
1004+ supportsCanLinkAccountUid : true ,
1005+ } ) ;
1006+
1007+ renderWithLocalizationProvider (
1008+ < LocationProvider >
1009+ < IndexContainer
1010+ integration = { integration }
1011+ serviceName = { MozServices . FirefoxSync }
1012+ useFxAStatusResult = { mockUseFxAStatusResult }
1013+ />
1014+ </ LocationProvider >
1015+ ) ;
1016+
1017+ await waitFor ( ( ) => {
1018+ expect ( firefox . fxaCanLinkAccount ) . not . toHaveBeenCalled ( ) ;
1019+ } ) ;
1020+ } ) ;
1021+
1022+ it ( 'calls fxaCanLinkAccount when supportsCanLinkAccountUid is false' , async ( ) => {
1023+ mockUseFxAStatusResult = mockUseFxAStatus ( {
1024+ supportsCanLinkAccountUid : false ,
1025+ } ) ;
1026+
1027+ renderWithLocalizationProvider (
1028+ < LocationProvider >
1029+ < IndexContainer
1030+ integration = { integration }
1031+ serviceName = { MozServices . FirefoxSync }
1032+ useFxAStatusResult = { mockUseFxAStatusResult }
1033+ />
1034+ </ LocationProvider >
1035+ ) ;
1036+
1037+ await waitFor ( ( ) => {
1038+ expect ( firefox . fxaCanLinkAccount ) . toHaveBeenCalled ( ) ;
1039+ } ) ;
1040+ } ) ;
1041+ } ) ;
9741042 } ) ;
9751043 } ) ;
9761044} ) ;
0 commit comments