1- // @flow
2-
31import React , { act } from 'react' ;
42import { mount } from 'enzyme' ;
53import API from '../../../api' ;
4+ import { GetContactsByEmailFnType } from '../types' ;
65import useContactsByEmail from '../hooks/useContactsByEmail' ;
76import {
87 MOCK_CONTACTS_API_RESPONSE ,
@@ -14,12 +13,12 @@ const handleSuccess = jest.fn();
1413const handleError = jest . fn ( ) ;
1514const transformUsersSpy = jest . fn ( ) . mockReturnValue ( MOCK_CONTACTS_BY_EMAIL_CONVERTED_RESPONSE ) ;
1615
17- const createAPIMock = markerBasedUsersAPI => ( {
16+ const createAPIMock = ( markerBasedUsersAPI : Record < string , unknown > ) : { getMarkerBasedUsersAPI : jest . Mock } => ( {
1817 getMarkerBasedUsersAPI : jest . fn ( ) . mockReturnValue ( markerBasedUsersAPI ) ,
1918} ) ;
2019
21- function FakeComponent ( { api, transformUsers } : { api : API , transformUsers : Function } ) {
22- const [ getContactsByEmail , setGetContactsByEmail ] = React . useState ( null ) ;
20+ function FakeComponent ( { api, transformUsers } : { api : API ; transformUsers ? : Function } ) {
21+ const [ getContactsByEmail , setGetContactsByEmail ] = React . useState < GetContactsByEmailFnType | null > ( null ) ;
2322
2423 const updatedGetContactsByEmailFn = useContactsByEmail ( api , MOCK_ITEM_ID , {
2524 handleSuccess,
@@ -63,12 +62,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
6362
6463 const contacts = fakeComponent . find ( 'button' ) . invoke ( 'onClick' ) ( { emails : [ MOCK_EMAIL ] } ) ;
6564
66- expect ( getUsersInEnterprise ) . toHaveBeenCalledWith (
67- MOCK_ITEM_ID ,
68- expect . anything ( Function ) ,
69- expect . anything ( Function ) ,
70- { filter_term : MOCK_EMAIL } ,
71- ) ;
65+ expect ( getUsersInEnterprise ) . toHaveBeenCalledWith ( MOCK_ITEM_ID , expect . anything ( ) , expect . anything ( ) , {
66+ filter_term : MOCK_EMAIL ,
67+ } ) ;
7268 expect ( handleSuccess ) . toHaveBeenCalledWith ( MOCK_CONTACTS_API_RESPONSE ) ;
7369 expect ( transformUsersSpy ) . toHaveBeenCalledWith ( MOCK_CONTACTS_API_RESPONSE ) ;
7470 return expect ( contacts ) . resolves . toEqual ( MOCK_CONTACTS_BY_EMAIL_CONVERTED_RESPONSE ) ;
@@ -83,12 +79,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
8379
8480 const contacts = fakeComponent . find ( 'button' ) . invoke ( 'onClick' ) ( { emails : [ MOCK_EMAIL ] } ) ;
8581
86- expect ( getUsersInEnterprise ) . toHaveBeenCalledWith (
87- MOCK_ITEM_ID ,
88- expect . anything ( Function ) ,
89- expect . anything ( Function ) ,
90- { filter_term : MOCK_EMAIL } ,
91- ) ;
82+ expect ( getUsersInEnterprise ) . toHaveBeenCalledWith ( MOCK_ITEM_ID , expect . anything ( ) , expect . anything ( ) , {
83+ filter_term : MOCK_EMAIL ,
84+ } ) ;
9285 expect ( handleSuccess ) . toHaveBeenCalledWith ( MOCK_CONTACTS_API_RESPONSE ) ;
9386 expect ( transformUsersSpy ) . not . toHaveBeenCalled ( ) ;
9487 expect ( contacts ) . resolves . toEqual ( MOCK_CONTACTS_API_RESPONSE . entries ) ;
@@ -154,12 +147,9 @@ describe('elements/content-sharing/hooks/useContactsByEmail', () => {
154147
155148 const contacts = fakeComponent . find ( 'button' ) . invoke ( 'onClick' ) ( { emails : [ MOCK_EMAIL ] } ) ;
156149
157- expect ( getUsersInEnterprise ) . toHaveBeenCalledWith (
158- MOCK_ITEM_ID ,
159- expect . anything ( Function ) ,
160- expect . anything ( Function ) ,
161- { filter_term : MOCK_EMAIL } ,
162- ) ;
150+ expect ( getUsersInEnterprise ) . toHaveBeenCalledWith ( MOCK_ITEM_ID , expect . anything ( ) , expect . anything ( ) , {
151+ filter_term : MOCK_EMAIL ,
152+ } ) ;
163153 expect ( handleError ) . toHaveBeenCalled ( ) ;
164154 expect ( contacts ) . resolves . toBeFalsy ( ) ;
165155 } ) ;
0 commit comments