create-huenei-template 0.2.16 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates/frontend/pre-sales/.cursor/agents/pre-sales-builder.agent.md +92 -77
- package/dist/templates/frontend/pre-sales/.cursor/agents/pre-sales-demo-runner.agent.md +36 -0
- package/dist/templates/frontend/pre-sales/.cursor/agents/pre-sales-deploy.agent.md +87 -80
- package/dist/templates/frontend/pre-sales/.cursor/agents/qa-test-expert.agent.md +48 -49
- package/dist/templates/frontend/pre-sales/.cursor/commands/deploy-demo.md +73 -0
- package/dist/templates/frontend/pre-sales/.cursor/commands/new-component.md +192 -232
- package/dist/templates/frontend/pre-sales/.cursor/commands/prepare-deploy.md +135 -134
- package/dist/templates/frontend/pre-sales/.cursor/commands/ver-demo.md +58 -0
- package/dist/templates/frontend/pre-sales/.cursor/context/pre-sales.md +2 -0
- package/dist/templates/frontend/pre-sales/.cursor/hooks/injectPreSalesContext.ts +24 -1
- package/dist/templates/frontend/pre-sales/.cursor/hooks.json +23 -26
- package/dist/templates/frontend/pre-sales/.cursor/mcp.json +1 -5
- package/dist/templates/frontend/pre-sales/.cursor/rules/architech.mdc +199 -206
- package/dist/templates/frontend/pre-sales/.cursor/rules/component-patterns.mdc +4 -0
- package/dist/templates/frontend/pre-sales/.cursor/rules/deployment-ready.mdc +52 -52
- package/dist/templates/frontend/pre-sales/.cursor/rules/domain-business-bootstrap.mdc +74 -0
- package/dist/templates/frontend/pre-sales/.cursor/rules/pre-sales-mode.mdc +104 -60
- package/dist/templates/frontend/pre-sales/.cursor/rules/separation-of-concerns.mdc +41 -42
- package/dist/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/SKILL.md +296 -0
- package/dist/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/resources/deploy-codex.sh +301 -0
- package/dist/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/resources/deploy.sh +301 -0
- package/dist/templates/frontend/pre-sales/.impeccable.md +26 -0
- package/dist/templates/frontend/pre-sales/index.html +11 -2
- package/dist/templates/frontend/pre-sales/src/__tests__/components/layout/navbar.test.tsx +0 -1
- package/dist/templates/frontend/pre-sales/src/__tests__/components/layout/sidebar.test.tsx +58 -68
- package/dist/templates/frontend/pre-sales/src/__tests__/hooks/useAuth.test.tsx +2 -1
- package/dist/templates/frontend/pre-sales/src/__tests__/lib/auth.test.ts +102 -102
- package/dist/templates/frontend/pre-sales/src/__tests__/routes/__root.test.tsx +72 -72
- package/dist/templates/frontend/pre-sales/src/__tests__/routes/_authenticated.test.tsx +57 -58
- package/dist/templates/frontend/pre-sales/src/__tests__/routes/index.test.tsx +8 -43
- package/dist/templates/frontend/pre-sales/src/components/layout/navbar.tsx +121 -75
- package/dist/templates/frontend/pre-sales/src/components/layout/sidebar.tsx +42 -30
- package/dist/templates/frontend/pre-sales/src/components/providers/auth-provider.tsx +60 -0
- package/dist/templates/frontend/pre-sales/src/components/ui/button.tsx +1 -1
- package/dist/templates/frontend/pre-sales/src/components/ui/card.tsx +1 -1
- package/dist/templates/frontend/pre-sales/src/components/ui/combobox.tsx +308 -308
- package/dist/templates/frontend/pre-sales/src/components/ui/command.tsx +179 -182
- package/dist/templates/frontend/pre-sales/src/components/ui/input.tsx +2 -0
- package/dist/templates/frontend/pre-sales/src/components/ui/textarea.tsx +2 -0
- package/dist/templates/frontend/pre-sales/src/components/ui/theme-toggle.tsx +35 -0
- package/dist/templates/frontend/pre-sales/src/data/dashboard.ts +249 -255
- package/dist/templates/frontend/pre-sales/src/hooks/useAuth.ts +13 -0
- package/dist/templates/frontend/pre-sales/src/hooks/useTheme.ts +73 -0
- package/dist/templates/frontend/pre-sales/src/index.css +282 -134
- package/dist/templates/frontend/pre-sales/src/main.tsx +3 -2
- package/dist/templates/frontend/pre-sales/src/routes/__root.tsx +62 -54
- package/dist/templates/frontend/pre-sales/src/routes/_authenticated/app.tsx +20 -0
- package/dist/templates/frontend/pre-sales/src/routes/_authenticated.tsx +5 -4
- package/dist/templates/frontend/pre-sales/src/routes/auth/iniciar-sesion.tsx +173 -163
- package/dist/templates/frontend/pre-sales/src/routes/index.tsx +53 -198
- package/dist/templates/frontend/pre-sales/src/test/utils.tsx +2 -1
- package/dist/templates/frontend/pre-sales/src/vite-env.d.ts +11 -0
- package/package.json +1 -1
- package/templates/frontend/pre-sales/.cursor/agents/pre-sales-builder.agent.md +92 -77
- package/templates/frontend/pre-sales/.cursor/agents/pre-sales-demo-runner.agent.md +36 -0
- package/templates/frontend/pre-sales/.cursor/agents/pre-sales-deploy.agent.md +87 -80
- package/templates/frontend/pre-sales/.cursor/agents/qa-test-expert.agent.md +48 -49
- package/templates/frontend/pre-sales/.cursor/commands/deploy-demo.md +73 -0
- package/templates/frontend/pre-sales/.cursor/commands/new-component.md +192 -232
- package/templates/frontend/pre-sales/.cursor/commands/prepare-deploy.md +135 -134
- package/templates/frontend/pre-sales/.cursor/commands/ver-demo.md +58 -0
- package/templates/frontend/pre-sales/.cursor/context/pre-sales.md +2 -0
- package/templates/frontend/pre-sales/.cursor/hooks/injectPreSalesContext.ts +24 -1
- package/templates/frontend/pre-sales/.cursor/hooks.json +23 -26
- package/templates/frontend/pre-sales/.cursor/mcp.json +1 -5
- package/templates/frontend/pre-sales/.cursor/rules/architech.mdc +199 -206
- package/templates/frontend/pre-sales/.cursor/rules/component-patterns.mdc +4 -0
- package/templates/frontend/pre-sales/.cursor/rules/deployment-ready.mdc +52 -52
- package/templates/frontend/pre-sales/.cursor/rules/domain-business-bootstrap.mdc +74 -0
- package/templates/frontend/pre-sales/.cursor/rules/pre-sales-mode.mdc +104 -60
- package/templates/frontend/pre-sales/.cursor/rules/separation-of-concerns.mdc +41 -42
- package/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/SKILL.md +296 -0
- package/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/resources/deploy-codex.sh +301 -0
- package/templates/frontend/pre-sales/.cursor/skills/deploy-to-vercel/resources/deploy.sh +301 -0
- package/templates/frontend/pre-sales/.impeccable.md +26 -0
- package/templates/frontend/pre-sales/index.html +11 -2
- package/templates/frontend/pre-sales/pnpm-lock.yaml +6448 -0
- package/templates/frontend/pre-sales/skills-lock.json +10 -0
- package/templates/frontend/pre-sales/src/__tests__/components/layout/navbar.test.tsx +0 -1
- package/templates/frontend/pre-sales/src/__tests__/components/layout/sidebar.test.tsx +58 -68
- package/templates/frontend/pre-sales/src/__tests__/hooks/useAuth.test.tsx +2 -1
- package/templates/frontend/pre-sales/src/__tests__/lib/auth.test.ts +102 -102
- package/templates/frontend/pre-sales/src/__tests__/routes/__root.test.tsx +72 -72
- package/templates/frontend/pre-sales/src/__tests__/routes/_authenticated.test.tsx +57 -58
- package/templates/frontend/pre-sales/src/__tests__/routes/index.test.tsx +8 -43
- package/templates/frontend/pre-sales/src/components/layout/navbar.tsx +121 -75
- package/templates/frontend/pre-sales/src/components/layout/sidebar.tsx +42 -30
- package/templates/frontend/pre-sales/src/components/providers/auth-provider.tsx +60 -0
- package/templates/frontend/pre-sales/src/components/ui/button.tsx +1 -1
- package/templates/frontend/pre-sales/src/components/ui/card.tsx +1 -1
- package/templates/frontend/pre-sales/src/components/ui/combobox.tsx +308 -308
- package/templates/frontend/pre-sales/src/components/ui/command.tsx +179 -182
- package/templates/frontend/pre-sales/src/components/ui/input.tsx +2 -0
- package/templates/frontend/pre-sales/src/components/ui/textarea.tsx +2 -0
- package/templates/frontend/pre-sales/src/components/ui/theme-toggle.tsx +35 -0
- package/templates/frontend/pre-sales/src/data/dashboard.ts +249 -255
- package/templates/frontend/pre-sales/src/hooks/useAuth.ts +13 -0
- package/templates/frontend/pre-sales/src/hooks/useTheme.ts +73 -0
- package/templates/frontend/pre-sales/src/index.css +282 -134
- package/templates/frontend/pre-sales/src/main.tsx +3 -2
- package/templates/frontend/pre-sales/src/routes/__root.tsx +62 -54
- package/templates/frontend/pre-sales/src/routes/_authenticated/app.tsx +20 -0
- package/templates/frontend/pre-sales/src/routes/_authenticated.tsx +5 -4
- package/templates/frontend/pre-sales/src/routes/auth/iniciar-sesion.tsx +173 -163
- package/templates/frontend/pre-sales/src/routes/index.tsx +53 -198
- package/templates/frontend/pre-sales/src/test/utils.tsx +2 -1
- package/templates/frontend/pre-sales/src/vite-env.d.ts +11 -0
|
@@ -48,7 +48,6 @@ describe('Navbar', () => {
|
|
|
48
48
|
render(<Navbar />)
|
|
49
49
|
expect(screen.getByText('Inicio')).toBeInTheDocument()
|
|
50
50
|
expect(screen.getByText('Proyectos')).toBeInTheDocument()
|
|
51
|
-
expect(screen.getByText('Documentación')).toBeInTheDocument()
|
|
52
51
|
expect(screen.getByText('Contacto')).toBeInTheDocument()
|
|
53
52
|
})
|
|
54
53
|
|
|
@@ -1,68 +1,58 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { render, screen } from '@testing-library/react'
|
|
3
|
-
import userEvent from '@testing-library/user-event'
|
|
4
|
-
import { Sidebar } from '@/components/layout/sidebar'
|
|
5
|
-
|
|
6
|
-
vi.mock('@tanstack/react-router', () => ({
|
|
7
|
-
Link: ({ children, to, onClick, className, ...props }: { children: React.ReactNode; to: string; onClick?: () => void; className?: string }) => (
|
|
8
|
-
<a href={to} onClick={onClick} className={className} {...props}>{children}</a>
|
|
9
|
-
),
|
|
10
|
-
useLocation: () => ({ pathname: '/dashboard' }),
|
|
11
|
-
}))
|
|
12
|
-
|
|
13
|
-
describe('Sidebar', () => {
|
|
14
|
-
it('deberia renderizar
|
|
15
|
-
render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
16
|
-
expect(screen.getByText('
|
|
17
|
-
expect(screen.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('deberia aplicar clase translate-x cuando
|
|
53
|
-
const { container } = render(<Sidebar open={
|
|
54
|
-
const aside = container.querySelector('aside')
|
|
55
|
-
expect(aside).toHaveClass('
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const { container } = render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
60
|
-
const aside = container.querySelector('aside')
|
|
61
|
-
expect(aside).toHaveClass('translate-x-0')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('deberia mostrar seccion de ayuda', () => {
|
|
65
|
-
render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
66
|
-
expect(screen.getByText('¿Necesitás ayuda?')).toBeInTheDocument()
|
|
67
|
-
})
|
|
68
|
-
})
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
import { Sidebar } from '@/components/layout/sidebar'
|
|
5
|
+
|
|
6
|
+
vi.mock('@tanstack/react-router', () => ({
|
|
7
|
+
Link: ({ children, to, onClick, className, ...props }: { children: React.ReactNode; to: string; onClick?: () => void; className?: string }) => (
|
|
8
|
+
<a href={to} onClick={onClick} className={className} {...props}>{children}</a>
|
|
9
|
+
),
|
|
10
|
+
useLocation: () => ({ pathname: '/dashboard' }),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
describe('Sidebar', () => {
|
|
14
|
+
it('deberia renderizar estado sin vistas de ejemplo', () => {
|
|
15
|
+
render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
16
|
+
expect(screen.getByText('Sin vistas creadas')).toBeInTheDocument()
|
|
17
|
+
expect(screen.queryByText('Dashboard')).not.toBeInTheDocument()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('deberia mostrar logo Huenei', () => {
|
|
21
|
+
render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
22
|
+
expect(screen.getByText('Huenei')).toBeInTheDocument()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('deberia llamar onClose al hacer click en boton X', async () => {
|
|
26
|
+
const onClose = vi.fn()
|
|
27
|
+
const user = userEvent.setup()
|
|
28
|
+
render(<Sidebar open={true} onClose={onClose} />)
|
|
29
|
+
|
|
30
|
+
await user.click(screen.getByLabelText('Cerrar menú'))
|
|
31
|
+
expect(onClose).toHaveBeenCalledOnce()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('deberia llamar onClose al hacer click en overlay', async () => {
|
|
35
|
+
const onClose = vi.fn()
|
|
36
|
+
const user = userEvent.setup()
|
|
37
|
+
const { container } = render(<Sidebar open={true} onClose={onClose} />)
|
|
38
|
+
|
|
39
|
+
const overlay = container.querySelector('[aria-hidden="true"]')
|
|
40
|
+
if (overlay) {
|
|
41
|
+
await user.click(overlay)
|
|
42
|
+
expect(onClose).toHaveBeenCalledOnce()
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('deberia aplicar clase translate-x cuando cerrado', () => {
|
|
47
|
+
const { container } = render(<Sidebar open={false} onClose={vi.fn()} />)
|
|
48
|
+
const aside = container.querySelector('aside')
|
|
49
|
+
expect(aside).toHaveClass('-translate-x-full')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('deberia aplicar clase translate-x-0 cuando abierto', () => {
|
|
53
|
+
const { container } = render(<Sidebar open={true} onClose={vi.fn()} />)
|
|
54
|
+
const aside = container.querySelector('aside')
|
|
55
|
+
expect(aside).toHaveClass('translate-x-0')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
2
|
import { render, screen, act, renderHook, waitFor } from '@testing-library/react'
|
|
3
|
-
import { AuthProvider
|
|
3
|
+
import { AuthProvider } from '@/components/providers/auth-provider'
|
|
4
|
+
import { useAuth } from '@/hooks/useAuth'
|
|
4
5
|
import * as authLib from '@/lib/auth'
|
|
5
6
|
|
|
6
7
|
vi.mock('@/lib/auth', async (importOriginal) => {
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach
|
|
2
|
-
import { authenticate, getSession, clearSession } from '@/lib/auth'
|
|
3
|
-
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
document.cookie.split(';').forEach((c) => {
|
|
6
|
-
document.cookie = c.trim().split('=')[0] + '=;max-age=0;path=/'
|
|
7
|
-
})
|
|
8
|
-
sessionStorage.clear()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
describe('authenticate', () => {
|
|
12
|
-
it('deberia retornar session con credenciales validas', async () => {
|
|
13
|
-
const session = await authenticate('huenei', '123')
|
|
14
|
-
expect(session).not.toBeNull()
|
|
15
|
-
expect(session!.user.username).toBe('huenei')
|
|
16
|
-
expect(session!.token).toBeTruthy()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('deberia retornar null con usuario incorrecto', async () => {
|
|
20
|
-
const session = await authenticate('noexiste', '123')
|
|
21
|
-
expect(session).toBeNull()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('deberia retornar null con password incorrecto', async () => {
|
|
25
|
-
const session = await authenticate('huenei', 'wrong')
|
|
26
|
-
expect(session).toBeNull()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('deberia ser case-insensitive para username', async () => {
|
|
30
|
-
const session = await authenticate('HUENEI', '123')
|
|
31
|
-
expect(session).not.toBeNull()
|
|
32
|
-
expect(session!.user.username).toBe('huenei')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('deberia setear cookie al autenticar', async () => {
|
|
36
|
-
await authenticate('huenei', '123')
|
|
37
|
-
expect(document.cookie).toContain('huenei_session')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('deberia almacenar session en sessionStorage', async () => {
|
|
41
|
-
await authenticate('huenei', '123')
|
|
42
|
-
const stored = sessionStorage.getItem('huenei_session_data')
|
|
43
|
-
expect(stored).not.toBeNull()
|
|
44
|
-
const parsed = JSON.parse(stored!)
|
|
45
|
-
expect(parsed.user.username).toBe('huenei')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('deberia generar token unico en cada login', async () => {
|
|
49
|
-
const s1 = await authenticate('huenei', '123')
|
|
50
|
-
clearSession()
|
|
51
|
-
const s2 = await authenticate('huenei', '123')
|
|
52
|
-
expect(s1!.token).not.toBe(s2!.token)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('getSession', () => {
|
|
57
|
-
it('deberia retornar session valida', async () => {
|
|
58
|
-
await authenticate('huenei', '123')
|
|
59
|
-
const session = getSession()
|
|
60
|
-
expect(session).not.toBeNull()
|
|
61
|
-
expect(session!.user.username).toBe('huenei')
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('deberia retornar null sin cookie', () => {
|
|
65
|
-
sessionStorage.setItem('huenei_session_data', JSON.stringify({ token: 'abc', user: { username: 'test' } }))
|
|
66
|
-
const session = getSession()
|
|
67
|
-
expect(session).toBeNull()
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('deberia retornar null cuando token no coincide', async () => {
|
|
71
|
-
await authenticate('huenei', '123')
|
|
72
|
-
document.cookie = 'huenei_session=different_token;path=/'
|
|
73
|
-
const session = getSession()
|
|
74
|
-
expect(session).toBeNull()
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('deberia limpiar datos cuando sessionStorage esta corrupto', () => {
|
|
78
|
-
document.cookie = 'huenei_session=sometoken;path=/'
|
|
79
|
-
sessionStorage.setItem('huenei_session_data', 'not-valid-json')
|
|
80
|
-
const session = getSession()
|
|
81
|
-
expect(session).toBeNull()
|
|
82
|
-
expect(sessionStorage.getItem('huenei_session_data')).toBeNull()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('deberia limpiar datos cuando no hay sessionStorage', () => {
|
|
86
|
-
document.cookie = 'huenei_session=sometoken;path=/'
|
|
87
|
-
const session = getSession()
|
|
88
|
-
expect(session).toBeNull()
|
|
89
|
-
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
describe('clearSession', () => {
|
|
93
|
-
it('deberia eliminar cookie y sessionStorage', async () => {
|
|
94
|
-
await authenticate('huenei', '123')
|
|
95
|
-
expect(getSession()).not.toBeNull()
|
|
96
|
-
|
|
97
|
-
clearSession()
|
|
98
|
-
|
|
99
|
-
expect(getSession()).toBeNull()
|
|
100
|
-
expect(sessionStorage.getItem('huenei_session_data')).toBeNull()
|
|
101
|
-
})
|
|
102
|
-
})
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { authenticate, getSession, clearSession } from '@/lib/auth'
|
|
3
|
+
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
document.cookie.split(';').forEach((c) => {
|
|
6
|
+
document.cookie = c.trim().split('=')[0] + '=;max-age=0;path=/'
|
|
7
|
+
})
|
|
8
|
+
sessionStorage.clear()
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
describe('authenticate', () => {
|
|
12
|
+
it('deberia retornar session con credenciales validas', async () => {
|
|
13
|
+
const session = await authenticate('huenei', '123')
|
|
14
|
+
expect(session).not.toBeNull()
|
|
15
|
+
expect(session!.user.username).toBe('huenei')
|
|
16
|
+
expect(session!.token).toBeTruthy()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('deberia retornar null con usuario incorrecto', async () => {
|
|
20
|
+
const session = await authenticate('noexiste', '123')
|
|
21
|
+
expect(session).toBeNull()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('deberia retornar null con password incorrecto', async () => {
|
|
25
|
+
const session = await authenticate('huenei', 'wrong')
|
|
26
|
+
expect(session).toBeNull()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('deberia ser case-insensitive para username', async () => {
|
|
30
|
+
const session = await authenticate('HUENEI', '123')
|
|
31
|
+
expect(session).not.toBeNull()
|
|
32
|
+
expect(session!.user.username).toBe('huenei')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('deberia setear cookie al autenticar', async () => {
|
|
36
|
+
await authenticate('huenei', '123')
|
|
37
|
+
expect(document.cookie).toContain('huenei_session')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('deberia almacenar session en sessionStorage', async () => {
|
|
41
|
+
await authenticate('huenei', '123')
|
|
42
|
+
const stored = sessionStorage.getItem('huenei_session_data')
|
|
43
|
+
expect(stored).not.toBeNull()
|
|
44
|
+
const parsed = JSON.parse(stored!)
|
|
45
|
+
expect(parsed.user.username).toBe('huenei')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('deberia generar token unico en cada login', async () => {
|
|
49
|
+
const s1 = await authenticate('huenei', '123')
|
|
50
|
+
clearSession()
|
|
51
|
+
const s2 = await authenticate('huenei', '123')
|
|
52
|
+
expect(s1!.token).not.toBe(s2!.token)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('getSession', () => {
|
|
57
|
+
it('deberia retornar session valida', async () => {
|
|
58
|
+
await authenticate('huenei', '123')
|
|
59
|
+
const session = getSession()
|
|
60
|
+
expect(session).not.toBeNull()
|
|
61
|
+
expect(session!.user.username).toBe('huenei')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('deberia retornar null sin cookie', () => {
|
|
65
|
+
sessionStorage.setItem('huenei_session_data', JSON.stringify({ token: 'abc', user: { username: 'test' } }))
|
|
66
|
+
const session = getSession()
|
|
67
|
+
expect(session).toBeNull()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('deberia retornar null cuando token no coincide', async () => {
|
|
71
|
+
await authenticate('huenei', '123')
|
|
72
|
+
document.cookie = 'huenei_session=different_token;path=/'
|
|
73
|
+
const session = getSession()
|
|
74
|
+
expect(session).toBeNull()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('deberia limpiar datos cuando sessionStorage esta corrupto', () => {
|
|
78
|
+
document.cookie = 'huenei_session=sometoken;path=/'
|
|
79
|
+
sessionStorage.setItem('huenei_session_data', 'not-valid-json')
|
|
80
|
+
const session = getSession()
|
|
81
|
+
expect(session).toBeNull()
|
|
82
|
+
expect(sessionStorage.getItem('huenei_session_data')).toBeNull()
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('deberia limpiar datos cuando no hay sessionStorage', () => {
|
|
86
|
+
document.cookie = 'huenei_session=sometoken;path=/'
|
|
87
|
+
const session = getSession()
|
|
88
|
+
expect(session).toBeNull()
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
describe('clearSession', () => {
|
|
93
|
+
it('deberia eliminar cookie y sessionStorage', async () => {
|
|
94
|
+
await authenticate('huenei', '123')
|
|
95
|
+
expect(getSession()).not.toBeNull()
|
|
96
|
+
|
|
97
|
+
clearSession()
|
|
98
|
+
|
|
99
|
+
expect(getSession()).toBeNull()
|
|
100
|
+
expect(sessionStorage.getItem('huenei_session_data')).toBeNull()
|
|
101
|
+
})
|
|
102
|
+
})
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { render, screen } from '@testing-library/react'
|
|
3
|
-
|
|
4
|
-
let mockPathname = '/'
|
|
5
|
-
|
|
6
|
-
vi.mock('@tanstack/react-router', () => ({
|
|
7
|
-
createRootRouteWithContext: () => (config: Record<string, unknown>) => {
|
|
8
|
-
return config
|
|
9
|
-
},
|
|
10
|
-
Link: ({ children, to, ...props }: { children: React.ReactNode; to: string }) => (
|
|
11
|
-
<a href={to} {...props}>{children}</a>
|
|
12
|
-
),
|
|
13
|
-
Outlet: () => <div data-testid="outlet">Page Content</div>,
|
|
14
|
-
useLocation: () => ({ pathname: mockPathname }),
|
|
15
|
-
}))
|
|
16
|
-
|
|
17
|
-
vi.mock('@/components/layout/navbar', () => ({
|
|
18
|
-
Navbar: () => <nav data-testid="navbar">Navbar</nav>,
|
|
19
|
-
}))
|
|
20
|
-
|
|
21
|
-
const { Route } = await import('@/routes/__root')
|
|
22
|
-
|
|
23
|
-
const RootComponent = (Route as Record<string, unknown>).component as React.ComponentType
|
|
24
|
-
const NotFoundComponent = (Route as Record<string, unknown>).notFoundComponent as React.ComponentType
|
|
25
|
-
|
|
26
|
-
describe('RootComponent', () => {
|
|
27
|
-
it('deberia renderizar Navbar, Outlet y footer en ruta normal', () => {
|
|
28
|
-
mockPathname = '/'
|
|
29
|
-
render(<RootComponent />)
|
|
30
|
-
expect(screen.getByTestId('navbar')).toBeInTheDocument()
|
|
31
|
-
expect(screen.getByTestId('outlet')).toBeInTheDocument()
|
|
32
|
-
expect(screen.getByText(/Huenei\. Todos los derechos reservados/)).toBeInTheDocument()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('deberia ocultar Navbar y footer en rutas auth', () => {
|
|
36
|
-
mockPathname = '/auth/iniciar-sesion'
|
|
37
|
-
render(<RootComponent />)
|
|
38
|
-
expect(screen.queryByTestId('navbar')).not.toBeInTheDocument()
|
|
39
|
-
expect(screen.queryByText(/Todos los derechos reservados/)).not.toBeInTheDocument()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('deberia mostrar el año actual en el footer', () => {
|
|
43
|
-
mockPathname = '/'
|
|
44
|
-
render(<RootComponent />)
|
|
45
|
-
const year = new Date().getFullYear().toString()
|
|
46
|
-
expect(screen.getByText(new RegExp(year))).toBeInTheDocument()
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('deberia mostrar texto del template en el footer', () => {
|
|
50
|
-
mockPathname = '/'
|
|
51
|
-
render(<RootComponent />)
|
|
52
|
-
expect(screen.getByText('Template base para proyectos de frontend')).toBeInTheDocument()
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
describe('NotFoundComponent', () => {
|
|
57
|
-
it('deberia mostrar titulo 404', () => {
|
|
58
|
-
render(<NotFoundComponent />)
|
|
59
|
-
expect(screen.getByText('404 - Página no encontrada')).toBeInTheDocument()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('deberia mostrar descripcion', () => {
|
|
63
|
-
render(<NotFoundComponent />)
|
|
64
|
-
expect(screen.getByText('La página que buscas no existe o ha sido movida.')).toBeInTheDocument()
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('deberia tener link a inicio', () => {
|
|
68
|
-
render(<NotFoundComponent />)
|
|
69
|
-
const link = screen.getByText('Volver al inicio')
|
|
70
|
-
expect(link.closest('a')).toHaveAttribute('href', '/')
|
|
71
|
-
})
|
|
72
|
-
})
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
|
|
4
|
+
let mockPathname = '/'
|
|
5
|
+
|
|
6
|
+
vi.mock('@tanstack/react-router', () => ({
|
|
7
|
+
createRootRouteWithContext: () => (config: Record<string, unknown>) => {
|
|
8
|
+
return config
|
|
9
|
+
},
|
|
10
|
+
Link: ({ children, to, ...props }: { children: React.ReactNode; to: string }) => (
|
|
11
|
+
<a href={to} {...props}>{children}</a>
|
|
12
|
+
),
|
|
13
|
+
Outlet: () => <div data-testid="outlet">Page Content</div>,
|
|
14
|
+
useLocation: () => ({ pathname: mockPathname }),
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
vi.mock('@/components/layout/navbar', () => ({
|
|
18
|
+
Navbar: () => <nav data-testid="navbar">Navbar</nav>,
|
|
19
|
+
}))
|
|
20
|
+
|
|
21
|
+
const { Route } = await import('@/routes/__root')
|
|
22
|
+
|
|
23
|
+
const RootComponent = (Route as unknown as Record<string, unknown>).component as React.ComponentType
|
|
24
|
+
const NotFoundComponent = (Route as unknown as Record<string, unknown>).notFoundComponent as React.ComponentType
|
|
25
|
+
|
|
26
|
+
describe('RootComponent', () => {
|
|
27
|
+
it('deberia renderizar Navbar, Outlet y footer en ruta normal', () => {
|
|
28
|
+
mockPathname = '/'
|
|
29
|
+
render(<RootComponent />)
|
|
30
|
+
expect(screen.getByTestId('navbar')).toBeInTheDocument()
|
|
31
|
+
expect(screen.getByTestId('outlet')).toBeInTheDocument()
|
|
32
|
+
expect(screen.getByText(/Huenei\. Todos los derechos reservados/)).toBeInTheDocument()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('deberia ocultar Navbar y footer en rutas auth', () => {
|
|
36
|
+
mockPathname = '/auth/iniciar-sesion'
|
|
37
|
+
render(<RootComponent />)
|
|
38
|
+
expect(screen.queryByTestId('navbar')).not.toBeInTheDocument()
|
|
39
|
+
expect(screen.queryByText(/Todos los derechos reservados/)).not.toBeInTheDocument()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('deberia mostrar el año actual en el footer', () => {
|
|
43
|
+
mockPathname = '/'
|
|
44
|
+
render(<RootComponent />)
|
|
45
|
+
const year = new Date().getFullYear().toString()
|
|
46
|
+
expect(screen.getByText(new RegExp(year))).toBeInTheDocument()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('deberia mostrar texto del template en el footer', () => {
|
|
50
|
+
mockPathname = '/'
|
|
51
|
+
render(<RootComponent />)
|
|
52
|
+
expect(screen.getByText('Template base para proyectos de frontend')).toBeInTheDocument()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('NotFoundComponent', () => {
|
|
57
|
+
it('deberia mostrar titulo 404', () => {
|
|
58
|
+
render(<NotFoundComponent />)
|
|
59
|
+
expect(screen.getByText('404 - Página no encontrada')).toBeInTheDocument()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('deberia mostrar descripcion', () => {
|
|
63
|
+
render(<NotFoundComponent />)
|
|
64
|
+
expect(screen.getByText('La página que buscas no existe o ha sido movida.')).toBeInTheDocument()
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('deberia tener link a inicio', () => {
|
|
68
|
+
render(<NotFoundComponent />)
|
|
69
|
+
const link = screen.getByText('Volver al inicio')
|
|
70
|
+
expect(link.closest('a')).toHaveAttribute('href', '/')
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { render, screen } from '@testing-library/react'
|
|
3
|
-
import userEvent from '@testing-library/user-event'
|
|
4
|
-
|
|
5
|
-
vi.mock('@tanstack/react-router', () => ({
|
|
6
|
-
createFileRoute: () => (opts: unknown) => ({ options: opts }),
|
|
7
|
-
Outlet: () => <div data-testid="outlet">Authenticated Content</div>,
|
|
8
|
-
redirect: vi.fn(),
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
vi.mock('@/components/layout/sidebar', () => ({
|
|
12
|
-
Sidebar: ({ open, onClose }: { open: boolean; onClose: () => void }) => (
|
|
13
|
-
<aside data-testid="sidebar" data-open={open}>
|
|
14
|
-
<button onClick={onClose}>Close Sidebar</button>
|
|
15
|
-
</aside>
|
|
16
|
-
),
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
import { Route } from '@/routes/_authenticated'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
expect(screen.getByTestId('
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import userEvent from '@testing-library/user-event'
|
|
4
|
+
|
|
5
|
+
vi.mock('@tanstack/react-router', () => ({
|
|
6
|
+
createFileRoute: () => (opts: unknown) => ({ options: opts }),
|
|
7
|
+
Outlet: () => <div data-testid="outlet">Authenticated Content</div>,
|
|
8
|
+
redirect: vi.fn(),
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
vi.mock('@/components/layout/sidebar', () => ({
|
|
12
|
+
Sidebar: ({ open, onClose }: { open: boolean; onClose: () => void }) => (
|
|
13
|
+
<aside data-testid="sidebar" data-open={open}>
|
|
14
|
+
<button onClick={onClose}>Close Sidebar</button>
|
|
15
|
+
</aside>
|
|
16
|
+
),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
import { Route } from '@/routes/_authenticated'
|
|
20
|
+
|
|
21
|
+
const AuthenticatedLayout = Route.options.component!
|
|
22
|
+
const beforeLoad = Route.options.beforeLoad as (params: { context: { auth: { isAuthenticated: boolean } } }) => void
|
|
23
|
+
|
|
24
|
+
describe('Authenticated Layout', () => {
|
|
25
|
+
it('deberia renderizar Sidebar y Outlet', () => {
|
|
26
|
+
render(<AuthenticatedLayout />)
|
|
27
|
+
expect(screen.getByTestId('sidebar')).toBeInTheDocument()
|
|
28
|
+
expect(screen.getByTestId('outlet')).toBeInTheDocument()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('deberia tener boton de menu mobile', () => {
|
|
32
|
+
render(<AuthenticatedLayout />)
|
|
33
|
+
expect(screen.getByLabelText('Abrir menú')).toBeInTheDocument()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('deberia abrir sidebar al hacer click en menu mobile', async () => {
|
|
37
|
+
const user = userEvent.setup()
|
|
38
|
+
render(<AuthenticatedLayout />)
|
|
39
|
+
|
|
40
|
+
await user.click(screen.getByLabelText('Abrir menú'))
|
|
41
|
+
expect(screen.getByTestId('sidebar')).toHaveAttribute('data-open', 'true')
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('beforeLoad guard', () => {
|
|
46
|
+
it('deberia redirigir a login si no autenticado', () => {
|
|
47
|
+
expect(() => {
|
|
48
|
+
beforeLoad({ context: { auth: { isAuthenticated: false } } })
|
|
49
|
+
}).toThrow()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('deberia no redirigir si autenticado', () => {
|
|
53
|
+
expect(() => {
|
|
54
|
+
beforeLoad({ context: { auth: { isAuthenticated: true } } })
|
|
55
|
+
}).not.toThrow()
|
|
56
|
+
})
|
|
57
|
+
})
|