Skip to content

Commit 0b73626

Browse files
committed
app: fix actions links
1 parent 2f74ad1 commit 0b73626

14 files changed

Lines changed: 142 additions & 612 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: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { fireEvent, render, screen } from '@testing-library/react'
22
import { describe, expect, it, vi } from 'vitest'
3-
import { UserProvider } from '@/contexts/UserContext'
4-
import { createFakeButtonGridItem } from '@/types/buttonGrid'
3+
import { UserContext } from '@/contexts/UserContext'
4+
import { createFakeDashboardLink } from '@/types/dashboardLink'
55
import { ButtonGridCard } from './index'
66

77
// Mock user context
8-
const _mockUserContext = {
8+
const mockUserContext = {
99
user: {
1010
id: 1,
1111
email: 'test@example.com',
@@ -23,10 +23,14 @@ const _mockUserContext = {
2323
}
2424

2525
const MockUserProvider = ({ children }: { children: React.ReactNode }) => {
26-
return <UserProvider>{children}</UserProvider>
26+
return (
27+
<UserContext.Provider value={mockUserContext}>
28+
{children}
29+
</UserContext.Provider>
30+
)
2731
}
2832

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

3135
const mockHandleClick = vi.fn()
3236

@@ -62,24 +66,28 @@ describe('ButtonGridCard', () => {
6266
expect(screen.getByText(mockData[1].title)).toBeInTheDocument()
6367
})
6468

65-
it('deve chamar a função handleClick quando um item é selecionado e confirmado', async () => {
69+
it('deve chamar a função handleClick diretamente quando o usuário é staff', () => {
70+
const mockUserContextWithStaff = {
71+
...mockUserContext,
72+
user: {
73+
...mockUserContext.user,
74+
is_staff: true,
75+
},
76+
}
77+
6678
render(
67-
<MockUserProvider>
79+
<UserContext.Provider value={mockUserContextWithStaff}>
6880
<ButtonGridCard
6981
header="Test Header"
7082
data={mockData}
7183
handleClick={mockHandleClick}
7284
/>
73-
</MockUserProvider>,
85+
</UserContext.Provider>,
7486
)
7587

7688
const button1 = screen.getByText(mockData[0].title)
7789
fireEvent.click(button1)
7890

79-
// Wait for modal to appear and click confirm
80-
const confirmButton = await screen.findByText('Confirmar')
81-
fireEvent.click(confirmButton)
82-
8391
expect(mockHandleClick).toHaveBeenCalledTimes(1)
8492
expect(mockHandleClick).toHaveBeenCalledWith(mockData[0])
8593
})

app/src/components/ButtonGridCard/index.tsx

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
'use client'
22

3-
import {
4-
AlertDialog,
5-
AlertDialogAction,
6-
AlertDialogCancel,
7-
AlertDialogContent,
8-
AlertDialogDescription,
9-
AlertDialogFooter,
10-
AlertDialogHeader,
11-
AlertDialogTitle,
12-
AlertDialogTrigger,
13-
} from '@/components/ui/alert-dialog'
143
import { Button } from '@/components/ui/button'
154
import {
165
Card,
@@ -19,15 +8,13 @@ import {
198
CardHeader,
209
CardTitle,
2110
} from '@/components/ui/card'
22-
import { useUser } from '@/hooks/useUser'
23-
24-
import type { DocumentRequest } from '@/types/documentRequest'
11+
import type { DashboardLink } from '@/types/dashboardLink'
2512

2613
interface ButtonGridCardProps {
2714
header: string
2815
description?: string
29-
data: DocumentRequest[]
30-
handleClick: (item: DocumentRequest) => void
16+
data: DashboardLink[]
17+
handleClick: (item: DashboardLink) => void
3118
className?: string
3219
}
3320

@@ -38,11 +25,6 @@ export function ButtonGridCard({
3825
handleClick,
3926
className,
4027
}: ButtonGridCardProps) {
41-
const { data: userInfo } = useUser()
42-
43-
// Check if user is staff (which includes superuser in Django) to determine if confirmation dialog should be shown
44-
const shouldShowConfirmation = !userInfo?.is_staff
45-
4628
return (
4729
<Card className={`w-full ${className}`}>
4830
<CardHeader>
@@ -54,50 +36,14 @@ export function ButtonGridCard({
5436
<CardContent>
5537
<ul className="grid grid-cols-2 gap-2">
5638
{data.map((item) => (
57-
<li key={item.id}>
58-
{shouldShowConfirmation ? (
59-
<AlertDialog>
60-
<AlertDialogTrigger asChild>
61-
<Button
62-
variant="outline"
63-
className="w-full text-blue-500 hover:bg-blue-100"
64-
>
65-
{item.title}
66-
</Button>
67-
</AlertDialogTrigger>
68-
<AlertDialogContent>
69-
<AlertDialogHeader>
70-
<AlertDialogTitle>
71-
Confirmar ação
72-
</AlertDialogTitle>
73-
<AlertDialogDescription>
74-
Você deseja realmente selecionar{' '}
75-
<strong>{item.title}</strong>?
76-
</AlertDialogDescription>
77-
</AlertDialogHeader>
78-
<AlertDialogFooter>
79-
<AlertDialogCancel>
80-
Cancelar
81-
</AlertDialogCancel>
82-
<AlertDialogAction
83-
onClick={() =>
84-
handleClick(item)
85-
}
86-
>
87-
Confirmar
88-
</AlertDialogAction>
89-
</AlertDialogFooter>
90-
</AlertDialogContent>
91-
</AlertDialog>
92-
) : (
93-
<Button
94-
variant="outline"
95-
className="w-full text-blue-500 hover:bg-blue-100"
96-
onClick={() => handleClick(item)}
97-
>
98-
{item.title}
99-
</Button>
100-
)}
39+
<li key={item.url}>
40+
<Button
41+
variant="outline"
42+
className="w-full text-blue-500 hover:bg-blue-100"
43+
onClick={() => handleClick(item)}
44+
>
45+
{item.title}
46+
</Button>
10147
</li>
10248
))}
10349
</ul>

0 commit comments

Comments
 (0)