Skip to content

Commit 43dff13

Browse files
committed
app: fix actions links
1 parent 2f74ad1 commit 43dff13

13 files changed

Lines changed: 125 additions & 536 deletions

File tree

app/src/app/(account)/dashboard/page.test.tsx

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
2-
import { toast } from 'sonner'
1+
import { render, screen } from '@testing-library/react'
32
import { describe, expect, it, vi } from 'vitest'
43
import { useUser } from '@/hooks/useUser'
54
import { FakeUser, UserRole } from '@/types/user'
@@ -122,45 +121,12 @@ describe('DashboardPage', () => {
122121
expect(
123122
screen.getByText(`User Info: ${FakeUser.name}`),
124123
).toBeInTheDocument()
125-
expect(screen.getByText('Requisitar Documentos')).toBeInTheDocument()
124+
expect(screen.getByText('Ações do Estudante')).toBeInTheDocument()
126125
expect(
127126
screen.getByText(
128127
`Grades Table: ${FakeUser.profile_details?.grades_details?.length} subjects`,
129128
),
130129
).toBeInTheDocument()
131-
132-
// Mock window.open to prevent jsdom error
133-
Object.defineProperty(window, 'open', {
134-
value: vi.fn(),
135-
writable: true,
136-
})
137-
138-
// Mock window.location to prevent navigation error
139-
const originalLocation = window.location
140-
Object.defineProperty(window, 'location', {
141-
value: {
142-
...originalLocation,
143-
href: '',
144-
assign: vi.fn(),
145-
replace: vi.fn(),
146-
},
147-
writable: true,
148-
})
149-
150-
// Test handleClick for ButtonGridCard
151-
const bulletinButton = screen.getByRole('button', { name: /Boletim/i })
152-
fireEvent.click(bulletinButton)
153-
await waitFor(() => {
154-
expect(toast.success).toHaveBeenCalledWith(
155-
'Requisição de Boletim enviada com sucesso!',
156-
)
157-
})
158-
159-
// Restore original location
160-
Object.defineProperty(window, 'location', {
161-
value: originalLocation,
162-
writable: true,
163-
})
164130
})
165131

166132
it('deve renderizar informações do professor e não cards específicos de aluno', () => {
@@ -195,9 +161,7 @@ describe('DashboardPage', () => {
195161
expect(
196162
screen.getByText(`User Info: ${mockProfessorUser.name}`),
197163
).toBeInTheDocument()
198-
expect(
199-
screen.queryByText('Requisitar Documentos'),
200-
).not.toBeInTheDocument()
164+
expect(screen.queryByText('Ações do Estudante')).not.toBeInTheDocument()
201165
expect(screen.queryByText(/Grades Table/i)).not.toBeInTheDocument()
202166
})
203167

@@ -233,9 +197,7 @@ describe('DashboardPage', () => {
233197
expect(
234198
screen.getByText(`User Info: ${mockGuardianUser.name}`),
235199
).toBeInTheDocument()
236-
expect(
237-
screen.queryByText('Requisitar Documentos'),
238-
).not.toBeInTheDocument()
200+
expect(screen.queryByText('Ações do Estudante')).not.toBeInTheDocument()
239201
expect(screen.queryByText(/Grades Table/i)).not.toBeInTheDocument()
240202
})
241203
})

app/src/app/(account)/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { useRouter } from 'next/navigation'
44
import { useEffect, useState } from 'react'
55
import { LoginForm } from '@/components/LoginForm'
6+
import { NAVIGATION } from '@/config'
67
import { useUser } from '@/contexts/UserContext'
78
import { login } from '@/services/auth'
8-
import { NAVIGATION } from '@/config'
99

1010
export default function LoginPage() {
1111
const router = useRouter()

app/src/app/(marketing)/about/page.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,40 @@ export default function About() {
3232

3333
<section className="mb-12 grid grid-cols-1 md:grid-cols-3 gap-8">
3434
<Link
35-
href={NAVIGATION.STUDENTS}
35+
href={NAVIGATION.DASHBOARD}
3636
className="btn text-2xl text-center"
3737
>
38-
Consultar Alunos
38+
Consultar Dashboard
3939
</Link>
4040
<Link
41-
href={NAVIGATION.PROFESSORS}
41+
href={NAVIGATION.AGENDA}
4242
className="btn text-2xl text-center"
4343
>
44-
Consultar Professores
44+
Consultar Agenda
4545
</Link>
4646
<Link
47-
href={NAVIGATION.GROUPS}
47+
href={NAVIGATION.LESSONS}
4848
className="btn text-2xl text-center"
4949
>
50-
Ver Turmas
50+
Ver Aulas
5151
</Link>
5252
<Link
53-
href={NAVIGATION.SUBJECTS}
53+
href={NAVIGATION.PROFILE}
5454
className="btn text-2xl text-center"
5555
>
56-
Disciplinas Oferecidas
56+
Consultar Meu Perfil
5757
</Link>
5858
<Link
59-
href={NAVIGATION.ITINERARIES}
59+
href={NAVIGATION.EVENTS}
6060
className="btn text-2xl text-center"
6161
>
62-
Itinerários Formativos
62+
Consultar Eventos
6363
</Link>
6464
<Link
65-
href={NAVIGATION.LESSONS}
65+
href={NAVIGATION.RESOURCES}
6666
className="btn text-2xl text-center"
6767
>
68-
Horários de Aula
68+
Recursos da Escola
6969
</Link>
7070
</section>
7171
</div>

app/src/components/ButtonGridCard/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fireEvent, render, screen } from '@testing-library/react'
22
import { describe, expect, it, vi } from 'vitest'
33
import { UserProvider } from '@/contexts/UserContext'
4-
import { createFakeButtonGridItem } from '@/types/buttonGrid'
4+
import { createFakeDashboardLink } from '@/types/dashboardLink'
55
import { ButtonGridCard } from './index'
66

77
// Mock user context
@@ -26,7 +26,7 @@ const MockUserProvider = ({ children }: { children: React.ReactNode }) => {
2626
return <UserProvider>{children}</UserProvider>
2727
}
2828

29-
const mockData = [createFakeButtonGridItem(), createFakeButtonGridItem()]
29+
const mockData = [createFakeDashboardLink(), createFakeDashboardLink()]
3030

3131
const mockHandleClick = vi.fn()
3232

app/src/components/ButtonGridCard/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import {
2020
CardTitle,
2121
} from '@/components/ui/card'
2222
import { useUser } from '@/hooks/useUser'
23-
24-
import type { DocumentRequest } from '@/types/documentRequest'
23+
import type { DashboardLink } from '@/types/dashboardLink'
2524

2625
interface ButtonGridCardProps {
2726
header: string
2827
description?: string
29-
data: DocumentRequest[]
30-
handleClick: (item: DocumentRequest) => void
28+
data: DashboardLink[]
29+
handleClick: (item: DashboardLink) => void
3130
className?: string
3231
}
3332

@@ -54,7 +53,7 @@ export function ButtonGridCard({
5453
<CardContent>
5554
<ul className="grid grid-cols-2 gap-2">
5655
{data.map((item) => (
57-
<li key={item.id}>
56+
<li key={item.url}>
5857
{shouldShowConfirmation ? (
5958
<AlertDialog>
6059
<AlertDialogTrigger asChild>

app/src/components/RolePanelCards/components/GuardianPanelCard.tsx

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,32 @@ import { toast } from 'sonner'
22
import { ButtonGridCard } from '@/components/ButtonGridCard'
33
import { NAVIGATION } from '@/config'
44
import { useUser } from '@/hooks/useUser'
5-
import type { DocumentRequest } from '@/types/documentRequest'
5+
import type { DashboardLink } from '@/types/dashboardLink'
66
import type { GuardianProps } from '@/types/guardian'
77
import { RolePanelCardLayout } from './RolePanelCardLayout'
88

9-
const guardianActions: DocumentRequest[] = [
10-
{ id: 1, title: 'Acompanhar Boletim', type: 'MONITOR_BULLETIN' },
11-
{ id: 2, title: 'Ver Frequência', type: 'CHECK_ATTENDANCE' },
12-
{ id: 3, title: 'Comunicados da Escola', type: 'SCHOOL_COMMUNICATIONS' },
13-
{ id: 4, title: 'Relatório do Aluno', type: 'STUDENT_REPORT' },
14-
{
15-
id: 5,
16-
title: 'Acompanhar Desempenho do Aluno',
17-
type: 'MONITOR_PERFORMANCE',
18-
},
19-
{
20-
id: 6,
21-
title: 'Consultar Frequência do Aluno',
22-
type: 'CHECK_CHILD_ATTENDANCE',
23-
},
24-
{ id: 7, title: 'Receber Notificações', type: 'MANAGE_NOTIFICATIONS' },
25-
{ id: 8, title: 'Solicitar Documentos', type: 'REQUEST_DOCUMENTS' },
26-
{ id: 9, title: 'Contatar Professor', type: 'CONTACT_TEACHER' },
27-
{ id: 10, title: 'Ver Calendário Escolar', type: 'VIEW_CALENDAR' },
28-
{ id: 11, title: 'Acompanhar Tarefas Escolares', type: 'MONITOR_HOMEWORK' },
29-
{ id: 12, title: 'Gerenciar Dados de Contato', type: 'UPDATE_CONTACT' },
9+
const guardianActions: DashboardLink[] = [
10+
{ title: 'Crianças Matriculadas', url: NAVIGATION.PROFILE },
11+
{ title: 'Notas das Crianças', url: NAVIGATION.AGENDA },
12+
{ title: 'Frequência das Crianças', url: NAVIGATION.AGENDA },
13+
{ title: 'Aulas das Crianças', url: NAVIGATION.AGENDA },
14+
{ title: 'Comunicados', url: NAVIGATION.EVENTS },
15+
{ title: 'Recursos de Aprendizagem', url: NAVIGATION.RESOURCES_LEARNING },
16+
{ title: 'Contatos dos Professores', url: NAVIGATION.INBOX },
17+
{ title: 'Agenda Acadêmica', url: NAVIGATION.ACADEMIC_SCHEDULE },
18+
{ title: 'Mensagens Recebidas', url: NAVIGATION.INBOX },
3019
]
3120

3221
export function GuardianPanelCard() {
3322
const { data: userInfo } = useUser()
3423
const profile = userInfo?.profile_details as GuardianProps | undefined
3524

36-
const handleClick = (item: DocumentRequest) => {
25+
const handleClick = (item: DashboardLink) => {
3726
if (!userInfo) {
3827
toast.error('Não foi possível acessar as informações do usuário')
3928
return
4029
}
41-
42-
if (userInfo.is_staff || userInfo.is_superuser) {
43-
switch (item.type) {
44-
case 'MONITOR_BULLETIN':
45-
window.location.href = NAVIGATION.ADMIN_STUDENTS_GRADE
46-
break
47-
case 'CHECK_ATTENDANCE':
48-
window.location.href = NAVIGATION.ADMIN_STUDENTS_ATTENDANCE
49-
break
50-
case 'SCHOOL_COMMUNICATIONS':
51-
window.location.href = NAVIGATION.ADMIN_SCHOOL_ANNOUNCEMENT
52-
break
53-
case 'STUDENT_REPORT':
54-
window.location.href = NAVIGATION.ADMIN_STUDENTS_STUDENT
55-
break
56-
case 'MONITOR_PERFORMANCE':
57-
case 'CHECK_CHILD_ATTENDANCE':
58-
case 'MANAGE_NOTIFICATIONS':
59-
case 'REQUEST_DOCUMENTS':
60-
case 'CONTACT_TEACHER':
61-
case 'VIEW_CALENDAR':
62-
case 'MONITOR_HOMEWORK':
63-
case 'UPDATE_CONTACT':
64-
window.location.href = NAVIGATION.ADMIN
65-
break
66-
default:
67-
toast.success(`Ação selecionada: ${item.title}`)
68-
}
69-
} else {
70-
switch (item.type) {
71-
case 'MONITOR_BULLETIN':
72-
window.location.href = NAVIGATION.STUDENT_GRADES
73-
break
74-
case 'CHECK_ATTENDANCE':
75-
window.location.href = NAVIGATION.STUDENT_ATTENDANCE
76-
break
77-
case 'SCHOOL_COMMUNICATIONS':
78-
window.location.href = NAVIGATION.EVENTS
79-
break
80-
case 'STUDENT_REPORT':
81-
window.location.href = NAVIGATION.PROFILE
82-
break
83-
case 'MONITOR_PERFORMANCE':
84-
window.location.href = NAVIGATION.STUDENT_GRADES
85-
break
86-
case 'CHECK_CHILD_ATTENDANCE':
87-
window.location.href = NAVIGATION.STUDENT_ATTENDANCE
88-
break
89-
case 'MANAGE_NOTIFICATIONS':
90-
window.location.href = NAVIGATION.INBOX
91-
break
92-
case 'REQUEST_DOCUMENTS':
93-
window.location.href = NAVIGATION.PROFILE
94-
break
95-
case 'CONTACT_TEACHER':
96-
window.location.href = NAVIGATION.PROFESSOR_COMMUNICATION
97-
break
98-
case 'VIEW_CALENDAR':
99-
window.location.href = NAVIGATION.CALENDAR
100-
break
101-
case 'MONITOR_HOMEWORK':
102-
window.location.href = NAVIGATION.GUARDIAN_HOMEWORK
103-
break
104-
case 'UPDATE_CONTACT':
105-
window.location.href = NAVIGATION.PROFILE
106-
break
107-
default:
108-
toast.success(`Ação selecionada: ${item.title}`)
109-
}
110-
}
30+
window.location.href = item.url
11131
}
11232

11333
if (!profile) {

0 commit comments

Comments
 (0)