@@ -17,69 +17,28 @@ describe("SignInForm", () => {
1717 beforeEach ( ( ) => {
1818 jest . clearAllMocks ( ) ;
1919 ( useRouter as jest . Mock ) . mockReturnValue ( { push : mockPush } ) ;
20- ( useSearchParams as jest . Mock ) . mockReturnValue ( {
21- get : jest . fn ( ) . mockReturnValue ( null ) ,
22- } ) ;
23- } ) ;
24-
25- it ( "renders all input fields" , ( ) => {
26- mockUseLogin . mockReturnValue ( { handleLogin : jest . fn ( ) , loading : false , error : null } ) ;
27- render ( < SignInForm /> ) ;
28-
29- expect ( screen . getByPlaceholderText ( "Enter your email" ) ) . toBeInTheDocument ( ) ;
30- expect ( screen . getByPlaceholderText ( "Enter your password" ) ) . toBeInTheDocument ( ) ;
31- } ) ;
32-
33- it ( "updates input fields on change" , ( ) => {
34- mockUseLogin . mockReturnValue ( { handleLogin : jest . fn ( ) , loading : false , error : null } ) ;
35- render ( < SignInForm /> ) ;
36-
37- const emailInput = screen . getByPlaceholderText ( "Enter your email" ) ;
38- fireEvent . change ( emailInput , { target : { value : "amanda123@example.com" } } ) ;
39- expect ( emailInput ) . toHaveValue ( "amanda123@example.com" ) ;
40-
41- const passwordInput = screen . getByPlaceholderText ( "Enter your password" ) ;
42- fireEvent . change ( passwordInput , { target : { value : "amanda@job" } } ) ;
43- expect ( passwordInput ) . toHaveValue ( "amanda@job" ) ;
20+ ( useSearchParams as jest . Mock ) . mockReturnValue ( { get : jest . fn ( ) . mockReturnValue ( null ) } ) ;
4421 } ) ;
4522
4623 it ( "calls handleLogin and redirects on successful login" , async ( ) => {
47- const mockHandleLogin = jest . fn ( ) . mockResolvedValue ( { } ) ;
24+ const mockHandleLogin = jest . fn ( ) . mockResolvedValue ( {
25+ user_type : "user" ,
26+ token : "abc" ,
27+ user_id : 1 ,
28+ } ) ;
4829 mockUseLogin . mockReturnValue ( { handleLogin : mockHandleLogin , loading : false , error : null } ) ;
4930
5031 render ( < SignInForm /> ) ;
51-
5232 fireEvent . change ( screen . getByPlaceholderText ( "Enter your email" ) , {
5333 target : { value : "amanda123@example.com" } ,
5434 } ) ;
5535 fireEvent . change ( screen . getByPlaceholderText ( "Enter your password" ) , {
5636 target : { value : "amanda@job" } ,
5737 } ) ;
58-
5938 fireEvent . click ( screen . getByRole ( "button" , { name : / s i g n i n | s i g n i n g i n / i } ) ) ;
6039
61- await screen . findByPlaceholderText ( "Enter your email" ) ;
62- expect ( mockHandleLogin ) . toHaveBeenCalledWith (
63- "amanda123@example.com" ,
64- "amanda@job" ,
65- undefined
66- ) ;
67- expect ( mockPush ) . toHaveBeenCalledWith ( "/institution" ) ;
68- } ) ;
69-
70- it ( "shows error message if login fails" , ( ) => {
71- mockUseLogin . mockReturnValue ( { handleLogin : jest . fn ( ) , loading : false , error : "Login failed" } ) ;
72- render ( < SignInForm /> ) ;
73-
74- const errorMessage = screen . getByText ( / l o g i n f a i l e d / i) ;
75- expect ( errorMessage ) . toBeInTheDocument ( ) ;
76- } ) ;
77-
78- it ( "disables submit button while loading" , ( ) => {
79- mockUseLogin . mockReturnValue ( { handleLogin : jest . fn ( ) , loading : true , error : null } ) ;
80- render ( < SignInForm /> ) ;
81-
82- const button = screen . getByRole ( "button" , { name : / s i g n i n | s i g n i n g i n / i } ) ;
83- expect ( button ) . toBeDisabled ( ) ;
40+ await screen . findByPlaceholderText ( "Enter your email" ) ;
41+ expect ( mockHandleLogin ) . toHaveBeenCalledWith ( "amanda123@example.com" , "amanda@job" , undefined ) ;
42+ expect ( mockPush ) . toHaveBeenCalledWith ( "/institution" ) ;
8443 } ) ;
8544} ) ;
0 commit comments