@@ -3,10 +3,14 @@ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
33import { beforeEach , describe , expect , it , vi } from "vitest" ;
44
55const mockRegister = vi . fn ( ) ;
6+ const mockGetGoogleAuthUrl = vi . fn ( ) ;
7+ const mockGetGithubAuthUrl = vi . fn ( ) ;
68const mockGetLinkedinAuthUrl = vi . fn ( ) ;
79
810vi . mock ( "@/services/authService" , ( ) => ( {
911 register : ( ...args : any [ ] ) => mockRegister ( ...args ) ,
12+ getGoogleAuthUrl : ( ...args : any [ ] ) => mockGetGoogleAuthUrl ( ...args ) ,
13+ getGithubAuthUrl : ( ...args : any [ ] ) => mockGetGithubAuthUrl ( ...args ) ,
1014 getLinkedinAuthUrl : ( ...args : any [ ] ) => mockGetLinkedinAuthUrl ( ...args ) ,
1115} ) ) ;
1216
@@ -40,6 +44,8 @@ describe("RegisterSide", () => {
4044
4145 beforeEach ( ( ) => {
4246 mockRegister . mockReset ( ) ;
47+ mockGetGoogleAuthUrl . mockReset ( ) ;
48+ mockGetGithubAuthUrl . mockReset ( ) ;
4349 mockGetLinkedinAuthUrl . mockReset ( ) ;
4450 Object . defineProperty ( window , "location" , {
4551 configurable : true ,
@@ -153,6 +159,37 @@ describe("RegisterSide", () => {
153159 } ) ;
154160 } ) ;
155161
162+ it ( "redireciona para GitHub OAuth ao clicar no botao GitHub" , async ( ) => {
163+ mockGetGithubAuthUrl . mockResolvedValueOnce (
164+ "https://github.com/login/oauth/authorize?state=abc"
165+ ) ;
166+
167+ render ( < RegisterSide /> ) ;
168+
169+ const buttons = screen . getAllByRole ( "button" ) ;
170+ const githubButton = buttons . find ( btn => btn . querySelector ( 'svg.fill-gray-900' ) ) ;
171+ fireEvent . click ( githubButton ! ) ;
172+
173+ await waitFor ( ( ) => {
174+ expect ( mockGetGithubAuthUrl ) . toHaveBeenCalled ( ) ;
175+ expect ( window . location . href ) . toBe (
176+ "https://github.com/login/oauth/authorize?state=abc"
177+ ) ;
178+ } ) ;
179+ } ) ;
180+
181+ it ( "exibe erro quando GitHub OAuth falha" , async ( ) => {
182+ mockGetGithubAuthUrl . mockRejectedValueOnce ( new Error ( "Github indisponível" ) ) ;
183+
184+ render ( < RegisterSide /> ) ;
185+
186+ const buttons = screen . getAllByRole ( "button" ) ;
187+ const githubButton = buttons . find ( btn => btn . querySelector ( 'svg.fill-gray-900' ) ) ;
188+ fireEvent . click ( githubButton ! ) ;
189+
190+ expect ( await screen . findByText ( / G i t h u b i n d i s p o n í v e l / i) ) . toBeInTheDocument ( ) ;
191+ } ) ;
192+
156193 it ( "redireciona para LinkedIn OAuth ao clicar no botao LinkedIn" , async ( ) => {
157194 mockGetLinkedinAuthUrl . mockResolvedValueOnce (
158195 "https://www.linkedin.com/oauth/v2/authorization?state=abc"
0 commit comments