Etapa 7 ya estaba completamente ejecutada en esta sesión. Todo está en su lugar:
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled

Fix A1 — isProfileLoaded en AuthContext 

useState(false) inicial
setIsProfileLoaded(true) si onAuthStateChange devuelve null (no hay usuario que sincronizar)
setIsProfileLoaded(false) en SIGNED_IN (resetea para el nuevo sync)
setIsProfileLoaded(true) en el finally del sync effect (después de syncProfileFromDB, éxito o error)
Fix A2 — Guard en LibraryPage 

if (!user || !isProfileLoaded) devuelve skeleton animado antes de cualquier contenido rol-dependiente
Fix A3 — Campo "cliente" read-only para client_editor 

GlobalSettingsPanel.tsx: <p> estático en lugar de <Input> cuando isClientRole
WorkspacePage.tsx: topbar muestra el valor sin input ni lápiz para client_editor
Fix B — Migración 016 + aplicada a DB 

Archivo supabase/migrations/016_add_simulations_update_policy.sql creado
Policy simulations_update confirmada activa en DB (pg_policies devuelve las 4 policies de simulations)
Fix adicional — 403 en POST /processes  (ejecutado en el turno inmediato anterior)

updateEditable() en process-repo.ts usa .update() en lugar de .upsert() para todos los paths de edición
Tests: 586 verdes, build limpio.

Lo que falta según el checklist del prompt es la validación visual del director (msebem@gmail.com en la app real). Eso requiere tu OK después de verificar en el navegador.

domain/types.ts — orgId: string | null agregado a Process (campo de DB ya existente, ahora mapeado en el dominio).

process-repo.ts — fromRow incluye orgId: (row.org_id as string | null) ?? null. Ambas queries (getById y getAll) usan select('*'), por lo que el campo viene gratis.

WorkspacePage.tsx:

Import supabase para el fetch de org name
Estado orgName + useEffect que hace SELECT name FROM organizations WHERE id = orgId cuando cambia currentProcess?.orgId
Variable isClientRole (solo client_editor — client_viewer ya fue redirigido)
backLabel: "Procesos" para client_editor, nombre de org (o "Volver" mientras carga) si hay orgId, "Biblioteca" si no hay
handleBack(): navega a /?org=<orgId> para admin con proceso de cliente, a / para el resto
El Home button + Tooltip fueron reemplazados por <Button variant="ghost" size="sm"> con ArrowLeft + backLabel
LibraryPage.tsx:

Import useSearch
Lee orgParam = useSearch({ from: '/' }) as { org?: string }
useEffect que, cuando orgParam está presente y la carga terminó, busca el proceso con p.orgId === orgParam, obtiene su groupId, y hace scrollIntoView al elemento group-{groupId}
Los GroupCards en el grid están ahora envueltos en <div id="group-{group.id}"> para ser alcanzables por el scroll
Tests — workspace-back-button.test.ts con 6 casos: admin+orgName, admin+orgName loading, admin sin org, member sin org, client_editor, client_viewer. Fixtures actualizados en 13 archivos con orgId: null. Mock de useSearch agregado en library-ui.test.tsx.
This commit is contained in:
2026-07-07 14:12:10 -03:00
parent cad8fbca4f
commit ee356e5de6
23 changed files with 414 additions and 35 deletions

View File

@@ -36,6 +36,7 @@ const { authUserRef, libStoreRef } = vi.hoisted(() => {
clientName: null,
overhead: 0,
isShared: false,
orgId: null,
}
const sampleGroup = {
id: 'grp-1',
@@ -72,6 +73,7 @@ vi.mock('@/components/AppHeader', () => ({ AppHeader: () => null }))
vi.mock('@tanstack/react-router', () => ({
useNavigate: () => vi.fn(),
useSearch: () => ({}),
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}))

View File

@@ -229,7 +229,7 @@ describe('MethodologyFooter', () => {
id: 'p1', name: 'Proceso Test', clientName: '',
bpmnXml: '<def/>', currency: 'USD',
overheadPercentage: 0.2, annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user',
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user', orgId: null,
}
expect(() => render(<MethodologyFooter process={proc} />)).not.toThrow()
})
@@ -239,7 +239,7 @@ describe('MethodologyFooter', () => {
id: 'p1', name: 'Proc', clientName: '',
bpmnXml: '', currency: 'USD',
overheadPercentage: 0.25, annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user',
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user', orgId: null,
}
render(<MethodologyFooter process={proc} />)
const text = document.body.textContent ?? ''
@@ -251,7 +251,7 @@ describe('MethodologyFooter', () => {
id: 'p1', name: 'Proc', clientName: '',
bpmnXml: '', currency: 'USD',
overheadPercentage: 0.2, annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user',
createdAt: 0, updatedAt: 0, groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user', orgId: null,
}
render(<MethodologyFooter process={proc} />)
const text = document.body.textContent ?? ''
@@ -342,7 +342,7 @@ describe('ReportPage — con datos completos', () => {
updatedAt: Date.now() - 1000 * 60 * 30,
groupId: null,
tags: [],
ownerId: 'test-user', updatedBy: 'test-user',
ownerId: 'test-user', updatedBy: 'test-user', orgId: null,
}
const mockSimulation = {

View File

@@ -600,7 +600,7 @@ const mockProcessBase = {
currency: 'USD', overheadPercentage: 0.2,
annualFrequency: 1200, analysisHorizonYears: 3, automationInvestment: 50_000,
createdAt: Date.now() - 3600_000, updatedAt: Date.now() - 3600_000,
groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user',
groupId: null, tags: [], ownerId: 'test-user', updatedBy: 'test-user', orgId: null,
}
const mockSimulationBase = {

View File

@@ -0,0 +1,60 @@
/**
* Tests del back button contextual en el workspace header.
* Verifica que backLabel y backTo se calculen correctamente según rol y orgId del proceso.
*/
import { describe, it, expect } from 'vitest'
type PlatformRole = 'platform_admin' | 'member' | 'client_editor' | 'client_viewer' | 'guest'
function resolveBackButton(
platformRole: PlatformRole | undefined,
orgId: string | null,
orgName: string | null,
): { backLabel: string; backTo: string } {
const isClientRole = platformRole === 'client_editor' || platformRole === 'client_viewer'
const backLabel = isClientRole
? 'Procesos'
: orgId
? (orgName ?? 'Volver')
: 'Biblioteca'
const backTo = orgId && !isClientRole ? `/?org=${orgId}` : '/'
return { backLabel, backTo }
}
describe('workspace back button — lógica de backLabel y backTo', () => {
it('1. admin con proceso de cliente → muestra nombre de org y navega a /?org=uuid', () => {
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', 'Solar Banco')
expect(backLabel).toBe('Solar Banco')
expect(backTo).toBe('/?org=org-uuid-123')
})
it('2. admin con proceso de cliente mientras orgName carga → muestra "Volver" como fallback', () => {
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', null)
expect(backLabel).toBe('Volver')
expect(backTo).toBe('/?org=org-uuid-123')
})
it('3. admin sin org asignada → muestra "Biblioteca" y navega a /', () => {
const { backLabel, backTo } = resolveBackButton('platform_admin', null, null)
expect(backLabel).toBe('Biblioteca')
expect(backTo).toBe('/')
})
it('4. member sin org → igual que platform_admin', () => {
const { backLabel, backTo } = resolveBackButton('member', null, null)
expect(backLabel).toBe('Biblioteca')
expect(backTo).toBe('/')
})
it('5. client_editor con proceso de cliente → muestra "Procesos" y navega a /', () => {
const { backLabel, backTo } = resolveBackButton('client_editor', 'org-uuid-123', 'Solar Banco')
expect(backLabel).toBe('Procesos')
expect(backTo).toBe('/')
})
it('6. client_viewer con proceso de cliente → muestra "Procesos" y navega a /', () => {
const { backLabel, backTo } = resolveBackButton('client_viewer', 'org-uuid-123', 'Solar Banco')
expect(backLabel).toBe('Procesos')
expect(backTo).toBe('/')
})
})