@@ -2,10 +2,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react'
22import { toast } from 'sonner'
33import { describe , expect , it , vi } from 'vitest'
44import { useUser } from '@/hooks/useUser'
5- import { createFakeGuardian } from '@/types/guardian'
6- import { createFakeProfessor } from '@/types/professor'
7- import { createFakeStudent } from '@/types/student'
8- import { createFakeUser , UserRole } from '@/types/user'
5+ import { FakeUser , UserRole } from '@/types/user'
96import DashboardPage from './page'
107
118vi . mock ( '@/components/Header1' , ( ) => ( {
@@ -107,12 +104,7 @@ describe('DashboardPage', () => {
107104 } )
108105
109106 it ( 'deve renderizar informações do aluno e cards específicos para aluno' , async ( ) => {
110- const mockStudentProfile = createFakeStudent ( )
111- const mockUser = {
112- ...createFakeUser ( ) ,
113- role : UserRole . STUDENT ,
114- profile_details : mockStudentProfile ,
115- }
107+ const mockUser = { ...FakeUser , role : UserRole . STUDENT }
116108 ; ( useUser as vi . Mock ) . mockReturnValue ( {
117109 data : mockUser ,
118110 loading : false ,
@@ -123,15 +115,17 @@ describe('DashboardPage', () => {
123115
124116 expect ( screen . getByText ( 'Dashboard' ) ) . toBeInTheDocument ( )
125117 expect (
126- screen . getByText ( `Bem-vindo(a), ${ mockStudentProfile . full_name } ` ) ,
118+ screen . getByText (
119+ `Bem-vindo(a), ${ FakeUser . profile_details ?. full_name } ` ,
120+ ) ,
127121 ) . toBeInTheDocument ( )
128122 expect (
129- screen . getByText ( `User Info: ${ mockUser . name } ` ) ,
123+ screen . getByText ( `User Info: ${ FakeUser . name } ` ) ,
130124 ) . toBeInTheDocument ( )
131125 expect ( screen . getByText ( 'Requisitar Documentos' ) ) . toBeInTheDocument ( )
132126 expect (
133127 screen . getByText (
134- `Grades Table: ${ mockStudentProfile . grades_details . length } subjects` ,
128+ `Grades Table: ${ FakeUser . profile_details ?. grades_details ? .length } subjects` ,
135129 ) ,
136130 ) . toBeInTheDocument ( )
137131
@@ -170,14 +164,22 @@ describe('DashboardPage', () => {
170164 } )
171165
172166 it ( 'deve renderizar informações do professor e não cards específicos de aluno' , ( ) => {
173- const mockProfessorProfile = createFakeProfessor ( )
174- const mockUser = {
175- ...createFakeUser ( ) ,
167+ const mockProfessorUser = {
168+ ...FakeUser ,
176169 role : UserRole . PROFESSOR ,
177- profile_details : mockProfessorProfile ,
170+ profile_details : {
171+ id : 2 ,
172+ full_name : 'Test Professor' ,
173+ phone_number : '11987654321' ,
174+ photoUrl : 'https://example.com/professor.jpg' ,
175+ user : 2 ,
176+ created_at : '2023-01-01T00:00:00Z' ,
177+ email : 'professor@example.com' ,
178+ address : '456 Professor Avenue' ,
179+ } ,
178180 }
179181 ; ( useUser as vi . Mock ) . mockReturnValue ( {
180- data : mockUser ,
182+ data : mockProfessorUser ,
181183 loading : false ,
182184 error : undefined ,
183185 } )
@@ -186,10 +188,12 @@ describe('DashboardPage', () => {
186188
187189 expect ( screen . getByText ( 'Dashboard' ) ) . toBeInTheDocument ( )
188190 expect (
189- screen . getByText ( `Bem-vindo(a), ${ mockProfessorProfile . full_name } ` ) ,
191+ screen . getByText (
192+ `Bem-vindo(a), ${ mockProfessorUser . profile_details . full_name } ` ,
193+ ) ,
190194 ) . toBeInTheDocument ( )
191195 expect (
192- screen . getByText ( `User Info: ${ mockUser . name } ` ) ,
196+ screen . getByText ( `User Info: ${ mockProfessorUser . name } ` ) ,
193197 ) . toBeInTheDocument ( )
194198 expect (
195199 screen . queryByText ( 'Requisitar Documentos' ) ,
@@ -198,14 +202,22 @@ describe('DashboardPage', () => {
198202 } )
199203
200204 it ( 'deve renderizar informações do responsável e não cards específicos de aluno' , ( ) => {
201- const mockGuardianProfile = createFakeGuardian ( )
202- const mockUser = {
203- ...createFakeUser ( ) ,
205+ const mockGuardianUser = {
206+ ...FakeUser ,
204207 role : UserRole . GUARDIAN ,
205- profile_details : mockGuardianProfile ,
208+ profile_details : {
209+ id : 3 ,
210+ full_name : 'Test Guardian' ,
211+ phone_number : '11987654321' ,
212+ photoUrl : 'https://example.com/guardian.jpg' ,
213+ user : 3 ,
214+ created_at : '2023-01-01T00:00:00Z' ,
215+ email : 'guardian@example.com' ,
216+ address : '789 Guardian Road' ,
217+ } ,
206218 }
207219 ; ( useUser as vi . Mock ) . mockReturnValue ( {
208- data : mockUser ,
220+ data : mockGuardianUser ,
209221 loading : false ,
210222 error : undefined ,
211223 } )
@@ -214,10 +226,12 @@ describe('DashboardPage', () => {
214226
215227 expect ( screen . getByText ( 'Dashboard' ) ) . toBeInTheDocument ( )
216228 expect (
217- screen . getByText ( `Bem-vindo(a), ${ mockGuardianProfile . full_name } ` ) ,
229+ screen . getByText (
230+ `Bem-vindo(a), ${ mockGuardianUser . profile_details . full_name } ` ,
231+ ) ,
218232 ) . toBeInTheDocument ( )
219233 expect (
220- screen . getByText ( `User Info: ${ mockUser . name } ` ) ,
234+ screen . getByText ( `User Info: ${ mockGuardianUser . name } ` ) ,
221235 ) . toBeInTheDocument ( )
222236 expect (
223237 screen . queryByText ( 'Requisitar Documentos' ) ,
0 commit comments