Antes de la última revisión de etapa 4. Sprint 1. Previo al ajuste de look n feel de app, reportes, nombre y colores.
This commit is contained in:
216
tests/lib/export/csv-export-roi.test.ts
Normal file
216
tests/lib/export/csv-export-roi.test.ts
Normal file
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* Tests del export CSV para el tab "Comparación + ROI" (Sprint 1 — Etapa 4).
|
||||
* Verifica las 16 columnas, la metadata extendida, sufijos de archivo y
|
||||
* compatibilidad con el comportamiento anterior (tabs actual y automatizado).
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { generateCsvContent } from '@/lib/export/csv-export'
|
||||
import type { Process, Simulation, Activity, SimulationResult } from '@/domain/types'
|
||||
|
||||
// ─── Fixtures ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function makeProcess(extras: Partial<Process> = {}): Process {
|
||||
return {
|
||||
id: 'p1', name: 'Proceso de Crédito', clientName: 'Banco XYZ',
|
||||
bpmnXml: '', currency: 'USD', overheadPercentage: 0.2,
|
||||
annualFrequency: 1200, analysisHorizonYears: 3, automationInvestment: 50_000,
|
||||
createdAt: 0, updatedAt: 0, ...extras,
|
||||
}
|
||||
}
|
||||
|
||||
const perActivityActual: SimulationResult['perActivity'] = [
|
||||
{
|
||||
activityId: 'a1', bpmnElementId: 'task_recv', activityName: 'Recibir solicitud',
|
||||
expectedDirectCost: 200, expectedIndirectCost: 40, expectedTotalCost: 240,
|
||||
percentOfTotal: 60, executionProbability: 1.0, expectedExecutions: 1.0,
|
||||
executionTimeMinutes: 60, resourceCostBreakdown: [],
|
||||
},
|
||||
{
|
||||
activityId: 'a2', bpmnElementId: 'task_valid', activityName: 'Validar datos',
|
||||
expectedDirectCost: 100, expectedIndirectCost: 20, expectedTotalCost: 120,
|
||||
percentOfTotal: 40, executionProbability: 0.8, expectedExecutions: 0.8,
|
||||
executionTimeMinutes: 30, resourceCostBreakdown: [],
|
||||
},
|
||||
]
|
||||
|
||||
const perActivityAutomated: SimulationResult['perActivity'] = [
|
||||
{
|
||||
activityId: 'a1', bpmnElementId: 'task_recv', activityName: 'Recibir solicitud',
|
||||
expectedDirectCost: 20, expectedIndirectCost: 4, expectedTotalCost: 24,
|
||||
percentOfTotal: 40, executionProbability: 1.0, expectedExecutions: 1.0,
|
||||
executionTimeMinutes: 5, resourceCostBreakdown: [],
|
||||
},
|
||||
{
|
||||
activityId: 'a2', bpmnElementId: 'task_valid', activityName: 'Validar datos',
|
||||
expectedDirectCost: 100, expectedIndirectCost: 20, expectedTotalCost: 120,
|
||||
percentOfTotal: 60, executionProbability: 0.8, expectedExecutions: 0.8,
|
||||
executionTimeMinutes: 30, resourceCostBreakdown: [],
|
||||
},
|
||||
]
|
||||
|
||||
const mockSimulation: Simulation = {
|
||||
id: 'sim1', processId: 'p1',
|
||||
executedAt: new Date('2026-05-13T10:00:00Z').getTime(),
|
||||
result: {
|
||||
totalCost: 360, totalDirectCost: 300, totalIndirectCost: 60, totalTimeMinutes: 84,
|
||||
perActivity: perActivityActual, perResource: [], warnings: [],
|
||||
},
|
||||
resultAutomated: {
|
||||
totalCost: 144, totalDirectCost: 120, totalIndirectCost: 24, totalTimeMinutes: 8,
|
||||
perActivity: perActivityAutomated, perResource: [], warnings: [],
|
||||
},
|
||||
}
|
||||
|
||||
const mockActivities: Activity[] = [
|
||||
{
|
||||
id: 'a1', processId: 'p1', bpmnElementId: 'task_recv', name: 'Recibir solicitud', type: 'task',
|
||||
directCostFixed: 200, executionTimeMinutes: 60, assignedResources: [],
|
||||
automatable: true, automatedCostFixed: 20, automatedTimeMinutes: 5,
|
||||
},
|
||||
{
|
||||
id: 'a2', processId: 'p1', bpmnElementId: 'task_valid', name: 'Validar datos', type: 'task',
|
||||
directCostFixed: 100, executionTimeMinutes: 30, assignedResources: [],
|
||||
automatable: false, automatedCostFixed: 0, automatedTimeMinutes: 0,
|
||||
},
|
||||
]
|
||||
|
||||
// ─── CSV ROI: estructura de columnas ──────────────────────────────────────────
|
||||
|
||||
describe('CSV tab=roi — 16 columnas', () => {
|
||||
it('tiene exactamente 16 columnas en el header', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const headerLine = csvNoBom.split('\r\n').find((l) => !l.startsWith('#') && l.trim())!
|
||||
// Papa.unparse envuelve en comillas — contar separadores + 1
|
||||
const cols = headerLine.split('","').length
|
||||
expect(cols).toBe(16)
|
||||
})
|
||||
|
||||
it('tiene los headers esperados (muestra)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('ID BPMN')
|
||||
expect(csv).toContain('Automatizable')
|
||||
expect(csv).toContain('Costo actual total')
|
||||
expect(csv).toContain('Costo automatizado total')
|
||||
expect(csv).toContain('Ahorro')
|
||||
expect(csv).toContain('Tiempo automatizado')
|
||||
expect(csv).toContain('Recursos asignados')
|
||||
})
|
||||
})
|
||||
|
||||
describe('CSV tab=roi — metadata extendida', () => {
|
||||
it('contiene campos de ROI en la metadata', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('# Ahorro por ejecución')
|
||||
expect(csv).toContain('# Ahorro anual')
|
||||
expect(csv).toContain('# Payback (meses)')
|
||||
expect(csv).toContain('# ROI anualizado')
|
||||
expect(csv).toContain('# Frecuencia anual')
|
||||
expect(csv).toContain('# Horizonte de análisis')
|
||||
expect(csv).toContain('# Inversión en automatización')
|
||||
})
|
||||
|
||||
it('costo total actual y automatizado están en la metadata', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('# Costo total actual')
|
||||
expect(csv).toContain('# Costo total automatizado')
|
||||
// Valores concretos del fixture: 360 y 144
|
||||
expect(csv).toContain('360.00')
|
||||
expect(csv).toContain('144.00')
|
||||
})
|
||||
|
||||
it('metadata incluye el horizonte y frecuencia configurados', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('# Frecuencia anual: 1200')
|
||||
expect(csv).toContain('# Horizonte de análisis: 3 años')
|
||||
})
|
||||
})
|
||||
|
||||
describe('CSV tab=roi — datos de actividades', () => {
|
||||
it('actividad automatable tiene "true" en la columna Automatizable', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
// task_recv es automatable=true
|
||||
expect(csv).toContain('"true"')
|
||||
})
|
||||
|
||||
it('actividad NO automatable tiene "false" en la columna Automatizable', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('"false"')
|
||||
})
|
||||
|
||||
it('ahorro de task_recv: 240 - 24 = 216 aparece en los datos', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv).toContain('216.00')
|
||||
})
|
||||
|
||||
it('actividad no automatable tiene ahorro 0 (costos iguales)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
// task_valid: 120 - 120 = 0
|
||||
expect(csv).toContain('0.00')
|
||||
})
|
||||
|
||||
it('N+1 filas (N actividades + 1 header)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const dataLines = csvNoBom.split('\r\n').filter((l) => l.trim() && !l.startsWith('#'))
|
||||
expect(dataLines).toHaveLength(perActivityActual.length + 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('CSV tab=roi — separadores y BOM', () => {
|
||||
it('BOM UTF-8 presente', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
expect(csv.charCodeAt(0)).toBe(0xFEFF)
|
||||
})
|
||||
|
||||
it('USD: separador coma', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess({ currency: 'USD' }), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const headerLine = csvNoBom.split('\r\n').find((l) => !l.startsWith('#') && l.trim())!
|
||||
expect(headerLine).toContain('","')
|
||||
})
|
||||
|
||||
it('PYG: separador punto y coma', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess({ currency: 'PYG' }), simulation: mockSimulation, resources: [], tab: 'roi', activities: mockActivities })
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const headerLine = csvNoBom.split('\r\n').find((l) => !l.startsWith('#') && l.trim())!
|
||||
expect(headerLine).toContain('";"')
|
||||
})
|
||||
})
|
||||
|
||||
// ─── CSV tab=automatizado ─────────────────────────────────────────────────────
|
||||
|
||||
describe('CSV tab=automatizado', () => {
|
||||
it('usa los datos del escenario automatizado (totalCost=144)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'automatizado' })
|
||||
expect(csv).toContain('# Escenario: Automatizado')
|
||||
expect(csv).toContain('144.00')
|
||||
})
|
||||
|
||||
it('tiene 10 columnas (mismo formato que actual)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'automatizado' })
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const headerLine = csvNoBom.split('\r\n').find((l) => !l.startsWith('#') && l.trim())!
|
||||
const cols = headerLine.split('","').length
|
||||
expect(cols).toBe(10)
|
||||
})
|
||||
})
|
||||
|
||||
// ─── CSV tab=actual — regresión ───────────────────────────────────────────────
|
||||
|
||||
describe('CSV tab=actual (regresión)', () => {
|
||||
it('tab=actual funciona igual que antes (escenario actual, 10 cols)', () => {
|
||||
const csv = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'actual' })
|
||||
expect(csv).toContain('# Escenario: Actual')
|
||||
expect(csv).toContain('360.00')
|
||||
const csvNoBom = csv.startsWith('') ? csv.slice(1) : csv
|
||||
const headerLine = csvNoBom.split('\r\n').find((l) => !l.startsWith('#') && l.trim())!
|
||||
expect(headerLine.split('","').length).toBe(10)
|
||||
})
|
||||
|
||||
it('tab=undefined → igual que tab=actual', () => {
|
||||
const csvDefault = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [] })
|
||||
const csvActual = generateCsvContent({ process: makeProcess(), simulation: mockSimulation, resources: [], tab: 'actual' })
|
||||
expect(csvDefault).toBe(csvActual)
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,7 @@ function makeProcess(currency: string, extras: Partial<Process> = {}): Process {
|
||||
return {
|
||||
id: 'p1', name: 'Proceso de Ventas', clientName: 'Empresa ABC',
|
||||
bpmnXml: '', currency, overheadPercentage: 0.2,
|
||||
annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
|
||||
createdAt: 0, updatedAt: 0, ...extras,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ function buildInput(xml: string, directCost: number): SimulationInput {
|
||||
actEls.map((el) => [el.bpmnElementId, {
|
||||
id: uuidv4(), processId, bpmnElementId: el.bpmnElementId, name: el.name,
|
||||
type: el.type, directCostFixed: directCost, executionTimeMinutes: 30, assignedResources: [],
|
||||
automatable: false, automatedCostFixed: 0, automatedTimeMinutes: 0,
|
||||
}])
|
||||
)
|
||||
|
||||
@@ -63,6 +64,7 @@ describe('Medición de tamaños de CSV — 3 sample BPMNs', () => {
|
||||
const process: Process = {
|
||||
id: 'p1', name: bpmn.name, clientName: bpmn.client,
|
||||
bpmnXml: xml, currency: 'USD', overheadPercentage: 0.2,
|
||||
annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
|
||||
createdAt: 0, updatedAt: 0,
|
||||
}
|
||||
|
||||
|
||||
206
tests/lib/export/pdf-export-roi.test.ts
Normal file
206
tests/lib/export/pdf-export-roi.test.ts
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Tests del export PDF para el tab "Comparación + ROI" (Sprint 1 — Etapa 4).
|
||||
* También verifica sufijos de nombre de archivo para los 3 tabs.
|
||||
* jsPDF y autotable se mockean.
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
// ─── Mock de jsPDF ────────────────────────────────────────────────────────────
|
||||
|
||||
const mockDoc = {
|
||||
setProperties: vi.fn(),
|
||||
setFont: vi.fn(),
|
||||
setFontSize: vi.fn(),
|
||||
setTextColor: vi.fn(),
|
||||
setFillColor: vi.fn(),
|
||||
setDrawColor: vi.fn(),
|
||||
setLineWidth: vi.fn(),
|
||||
text: vi.fn(),
|
||||
rect: vi.fn(),
|
||||
roundedRect: vi.fn(),
|
||||
line: vi.fn(),
|
||||
addImage: vi.fn(),
|
||||
addPage: vi.fn(),
|
||||
setPage: vi.fn(),
|
||||
save: vi.fn(),
|
||||
splitTextToSize: vi.fn().mockImplementation((text: string) => [text]),
|
||||
internal: { getNumberOfPages: vi.fn().mockReturnValue(4) },
|
||||
}
|
||||
|
||||
vi.mock('jspdf', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function MockJsPDF(this: any) { return mockDoc }
|
||||
return { jsPDF: MockJsPDF }
|
||||
})
|
||||
|
||||
const mockAutoTable = vi.fn()
|
||||
vi.mock('jspdf-autotable', () => ({ default: mockAutoTable }))
|
||||
|
||||
// ─── Fixtures ─────────────────────────────────────────────────────────────────
|
||||
|
||||
import type { Process, Simulation, Activity } from '@/domain/types'
|
||||
|
||||
const mockProcess: Process = {
|
||||
id: 'p1', name: 'Proceso de Aprobación de Crédito', clientName: 'Banco XYZ',
|
||||
bpmnXml: '', currency: 'USD', overheadPercentage: 0.2,
|
||||
annualFrequency: 1200, analysisHorizonYears: 3, automationInvestment: 50_000,
|
||||
createdAt: 0, updatedAt: 0,
|
||||
}
|
||||
|
||||
const perActivityActual = [
|
||||
{
|
||||
activityId: 'a1', bpmnElementId: 'task_recv', activityName: 'Recibir solicitud',
|
||||
expectedDirectCost: 200, expectedIndirectCost: 40, expectedTotalCost: 240,
|
||||
percentOfTotal: 60, executionProbability: 1.0, expectedExecutions: 1.0,
|
||||
executionTimeMinutes: 60, resourceCostBreakdown: [],
|
||||
},
|
||||
{
|
||||
activityId: 'a2', bpmnElementId: 'task_valid', activityName: 'Validar datos',
|
||||
expectedDirectCost: 100, expectedIndirectCost: 20, expectedTotalCost: 120,
|
||||
percentOfTotal: 40, executionProbability: 0.8, expectedExecutions: 0.8,
|
||||
executionTimeMinutes: 30, resourceCostBreakdown: [],
|
||||
},
|
||||
]
|
||||
|
||||
const perActivityAutomated = [
|
||||
{
|
||||
activityId: 'a1', bpmnElementId: 'task_recv', activityName: 'Recibir solicitud',
|
||||
expectedDirectCost: 20, expectedIndirectCost: 4, expectedTotalCost: 24,
|
||||
percentOfTotal: 40, executionProbability: 1.0, expectedExecutions: 1.0,
|
||||
executionTimeMinutes: 5, resourceCostBreakdown: [],
|
||||
},
|
||||
{
|
||||
activityId: 'a2', bpmnElementId: 'task_valid', activityName: 'Validar datos',
|
||||
expectedDirectCost: 100, expectedIndirectCost: 20, expectedTotalCost: 120,
|
||||
percentOfTotal: 60, executionProbability: 0.8, expectedExecutions: 0.8,
|
||||
executionTimeMinutes: 30, resourceCostBreakdown: [],
|
||||
},
|
||||
]
|
||||
|
||||
const mockSimulation: Simulation = {
|
||||
id: 'sim1', processId: 'p1',
|
||||
executedAt: new Date('2026-05-13T10:00:00Z').getTime(),
|
||||
result: {
|
||||
totalCost: 360, totalDirectCost: 300, totalIndirectCost: 60, totalTimeMinutes: 84,
|
||||
perActivity: perActivityActual, perResource: [], warnings: [],
|
||||
},
|
||||
resultAutomated: {
|
||||
totalCost: 144, totalDirectCost: 120, totalIndirectCost: 24, totalTimeMinutes: 8,
|
||||
perActivity: perActivityAutomated, perResource: [], warnings: [],
|
||||
},
|
||||
}
|
||||
|
||||
const mockActivities: Activity[] = [
|
||||
{
|
||||
id: 'a1', processId: 'p1', bpmnElementId: 'task_recv', name: 'Recibir solicitud', type: 'task',
|
||||
directCostFixed: 200, executionTimeMinutes: 60, assignedResources: [],
|
||||
automatable: true, automatedCostFixed: 20, automatedTimeMinutes: 5,
|
||||
},
|
||||
{
|
||||
id: 'a2', processId: 'p1', bpmnElementId: 'task_valid', name: 'Validar datos', type: 'task',
|
||||
directCostFixed: 100, executionTimeMinutes: 30, assignedResources: [],
|
||||
automatable: false, automatedCostFixed: 0, automatedTimeMinutes: 0,
|
||||
},
|
||||
]
|
||||
|
||||
// ─── Tests ────────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('exportToPdf — tab=roi', () => {
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
|
||||
it('no lanza error con tab=roi y parámetros válidos', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await expect(
|
||||
exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
).resolves.not.toThrow()
|
||||
})
|
||||
|
||||
it('tab=roi: llama a addPage al menos 3 veces (4 páginas)', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
expect(mockDoc.addPage.mock.calls.length).toBeGreaterThanOrEqual(3)
|
||||
})
|
||||
|
||||
it('tab=roi: autoTable llamado con 6 columnas en el head (tabla comparativa)', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
// autoTable puede llamarse múltiples veces; la tabla de comparación tiene 6 cols en head
|
||||
const roiTableCall = mockAutoTable.mock.calls.find((call) => {
|
||||
const head = call[1]?.head
|
||||
return Array.isArray(head) && Array.isArray(head[0]) && head[0].length === 6
|
||||
})
|
||||
expect(roiTableCall).toBeDefined()
|
||||
})
|
||||
|
||||
it('tab=roi: nombre de archivo termina en _roi.pdf', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
const saveName = mockDoc.save.mock.calls[0][0] as string
|
||||
expect(saveName).toMatch(/_roi\.pdf$/)
|
||||
})
|
||||
|
||||
it('tab=roi: setProperties incluye "retorno de inversión" en subject', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
expect(mockDoc.setProperties).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ subject: expect.stringContaining('retorno') })
|
||||
)
|
||||
})
|
||||
|
||||
it('tab=roi: NO llama a addImage (el tab ROI no tiene heatmap)', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
const fakeDataUrl = 'data:image/jpeg;base64,/9j/fake'
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: fakeDataUrl, tab: 'roi', activities: mockActivities })
|
||||
// El ROI PDF no embebe heatmap aunque se pase imageData
|
||||
expect(mockDoc.addImage).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('tab=roi sin resultAutomated: no lanza error (usa result como fallback)', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
const simSinAuto = { ...mockSimulation, resultAutomated: undefined }
|
||||
await expect(
|
||||
exportToPdf({ process: mockProcess, simulation: simSinAuto, resources: [], heatmapImageData: null, tab: 'roi', activities: mockActivities })
|
||||
).resolves.not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('exportToPdf — tab=actual', () => {
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
|
||||
it('tab=actual: nombre de archivo termina en _actual.pdf', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'actual' })
|
||||
expect(mockDoc.save.mock.calls[0][0]).toMatch(/_actual\.pdf$/)
|
||||
})
|
||||
|
||||
it('tab=actual: contiene el proceso en el título (setProperties)', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'actual' })
|
||||
expect(mockDoc.setProperties).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ title: expect.stringContaining('Proceso de Aprobación de Crédito') })
|
||||
)
|
||||
})
|
||||
|
||||
it('tab=undefined (default): se comporta como actual', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null })
|
||||
expect(mockDoc.save.mock.calls[0][0]).toMatch(/_actual\.pdf$/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('exportToPdf — tab=automatizado', () => {
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
|
||||
it('tab=automatizado: nombre de archivo termina en _automatizado.pdf', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'automatizado' })
|
||||
expect(mockDoc.save.mock.calls[0][0]).toMatch(/_automatizado\.pdf$/)
|
||||
})
|
||||
|
||||
it('tab=automatizado: no lanza error', async () => {
|
||||
const { exportToPdf } = await import('@/lib/export/pdf-export')
|
||||
await expect(
|
||||
exportToPdf({ process: mockProcess, simulation: mockSimulation, resources: [], heatmapImageData: null, tab: 'automatizado' })
|
||||
).resolves.not.toThrow()
|
||||
})
|
||||
})
|
||||
@@ -46,6 +46,7 @@ const mockProcess: Process = {
|
||||
clientName: 'Banco XYZ',
|
||||
bpmnXml: '', currency: 'USD',
|
||||
overheadPercentage: 0.2,
|
||||
annualFrequency: 1000, analysisHorizonYears: 3, automationInvestment: 0,
|
||||
createdAt: 0, updatedAt: 0,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user