@devpablocristo/modules-scheduling 0.4.0

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.
@@ -0,0 +1,241 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
4
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import { SchedulingBookingModal, type SchedulingBookingModalState } from './SchedulingBookingModal';
6
+ import type { SchedulingCalendarCopy } from './types';
7
+
8
+ const confirmActionMock = vi.hoisted(() => vi.fn(async () => true));
9
+
10
+ vi.mock('@devpablocristo/core-browser', () => ({
11
+ confirmAction: confirmActionMock,
12
+ }));
13
+
14
+ const copy = {
15
+ branchLabel: 'Sucursal',
16
+ serviceLabel: 'Servicio',
17
+ resourceLabel: 'Recurso',
18
+ anyResource: 'Cualquier recurso',
19
+ focusDateLabel: 'Fecha foco',
20
+ today: 'Hoy',
21
+ slotsTitle: 'Slots disponibles',
22
+ slotsDescription: 'Descripción',
23
+ slotsLoading: 'Cargando',
24
+ slotsEmpty: 'Vacío',
25
+ slotRemainingLabel: 'Cupos',
26
+ openBooking: 'Abrir reserva',
27
+ titleLabel: 'Título',
28
+ repeatLabel: 'Repetir',
29
+ repeatNever: 'No se repite',
30
+ repeatDaily: 'Diaria',
31
+ repeatWeekly: 'Semanal',
32
+ repeatMonthly: 'Mensual',
33
+ repeatCustom: 'Personalizada',
34
+ repeatFrequencyLabel: 'Frecuencia',
35
+ repeatIntervalLabel: 'Cada',
36
+ repeatCountLabel: 'Ocurrencias',
37
+ repeatWeekdaysLabel: 'Días',
38
+ bookingTitleCreate: 'Crear reserva',
39
+ bookingTitleDetails: 'Detalle de reserva',
40
+ bookingSubtitleCreate: 'Nueva reserva',
41
+ bookingSubtitleDetails: 'Reserva existente',
42
+ availableSlotLabel: 'Slot disponible',
43
+ availableSlotHint: 'Usa un slot valido',
44
+ availableSlotLoading: 'Buscando disponibilidad',
45
+ unavailableSlotMessage: 'No disponible',
46
+ slotSummaryTitle: 'Resumen del slot',
47
+ bookingPreviewTitle: 'Vista previa',
48
+ customerNameLabel: 'Cliente',
49
+ customerPhoneLabel: 'Teléfono',
50
+ customerEmailLabel: 'Email',
51
+ notesLabel: 'Notas',
52
+ serviceNameLabel: 'Servicio',
53
+ resourceNameLabel: 'Recurso',
54
+ slotLabel: 'Horario',
55
+ slotStartLabel: 'Inicio',
56
+ slotEndLabel: 'Fin',
57
+ durationLabel: 'Duración',
58
+ timezoneLabel: 'Zona horaria',
59
+ occupiesLabel: 'Bloquea',
60
+ conflictLabel: 'Conflictos',
61
+ referenceLabel: 'Referencia',
62
+ statusLabel: 'Estado',
63
+ create: 'Guardar',
64
+ saving: 'Guardando',
65
+ close: 'Cancelar',
66
+ confirmBooking: 'Confirmar',
67
+ cancelBooking: 'Cancelar reserva',
68
+ checkInBooking: 'Check-in',
69
+ startService: 'Iniciar',
70
+ completeBooking: 'Completar',
71
+ noShowBooking: 'No asistió',
72
+ dragRescheduleTitle: 'Reprogramar',
73
+ dragRescheduleDescription: 'Mover turno',
74
+ rescheduleBooking: 'Reprogramar reserva',
75
+ destructiveTitle: 'Acción destructiva',
76
+ cancelActionDescription: 'Cancelar turno',
77
+ noShowActionDescription: 'Marcar no show',
78
+ closeDirtyTitle: 'Descartar borrador',
79
+ closeDirtyDescription: 'Hay datos cargados sin guardar en esta reserva.',
80
+ keepEditing: 'Seguir editando',
81
+ discard: 'Descartar',
82
+ resizeLockedMessage: 'Duración fija',
83
+ searchPlaceholder: 'Buscar',
84
+ dashboardBookings: 'Reservas',
85
+ dashboardConfirmed: 'Confirmadas',
86
+ dashboardQueues: 'Colas',
87
+ dashboardWaiting: 'Esperando',
88
+ timelineTitle: 'Agenda',
89
+ timelineDescription: 'Descripción',
90
+ queueTitle: 'Colas',
91
+ queueDescription: 'Descripción',
92
+ queueSearchLabel: 'Buscar cola',
93
+ queueSearchPlaceholder: 'Buscar',
94
+ queueEmpty: 'Vacío',
95
+ queueCreateTicket: 'Crear ticket',
96
+ queuePause: 'Pausar',
97
+ queueResume: 'Reanudar',
98
+ queueClose: 'Cerrar',
99
+ queueCallNext: 'Llamar siguiente',
100
+ queuePriorityLabel: 'Prioridad',
101
+ queueCustomerNameLabel: 'Cliente',
102
+ queueCustomerPhoneLabel: 'Teléfono',
103
+ queueCustomerEmailLabel: 'Email',
104
+ statuses: {
105
+ hold: 'Hold',
106
+ pending_confirmation: 'Pendiente',
107
+ confirmed: 'Confirmada',
108
+ checked_in: 'Check-in',
109
+ in_service: 'En servicio',
110
+ completed: 'Completada',
111
+ cancelled: 'Cancelada',
112
+ no_show: 'No asistió',
113
+ expired: 'Expirada',
114
+ },
115
+ } as unknown as SchedulingCalendarCopy;
116
+
117
+ const createState: SchedulingBookingModalState = {
118
+ open: true,
119
+ mode: 'create',
120
+ slot: {
121
+ resource_id: 'resource-1',
122
+ resource_name: 'Demo Professional',
123
+ start_at: '2099-04-05T10:00:00Z',
124
+ end_at: '2099-04-05T10:30:00Z',
125
+ occupies_from: '2099-04-05T10:00:00Z',
126
+ occupies_until: '2099-04-05T10:30:00Z',
127
+ timezone: 'America/Argentina/Tucuman',
128
+ remaining: 1,
129
+ conflict_count: 0,
130
+ granularity_minutes: 30,
131
+ },
132
+ slotOptions: [
133
+ {
134
+ resource_id: 'resource-1',
135
+ resource_name: 'Demo Professional',
136
+ start_at: '2099-04-05T10:00:00Z',
137
+ end_at: '2099-04-05T10:30:00Z',
138
+ occupies_from: '2099-04-05T10:00:00Z',
139
+ occupies_until: '2099-04-05T10:30:00Z',
140
+ timezone: 'America/Argentina/Tucuman',
141
+ remaining: 1,
142
+ conflict_count: 0,
143
+ granularity_minutes: 30,
144
+ },
145
+ ],
146
+ resourceOptions: [
147
+ {
148
+ id: 'resource-1',
149
+ name: 'Demo Professional',
150
+ timezone: 'America/Argentina/Tucuman',
151
+ },
152
+ ],
153
+ editor: {
154
+ date: '2099-04-05',
155
+ startTime: '10:00',
156
+ endTime: '10:30',
157
+ resourceId: 'resource-1',
158
+ },
159
+ validationMessage: null,
160
+ draft: {
161
+ title: '',
162
+ customerName: '',
163
+ customerPhone: '',
164
+ customerEmail: '',
165
+ notes: '',
166
+ recurrence: {
167
+ mode: 'none',
168
+ frequency: 'weekly',
169
+ interval: '1',
170
+ count: '8',
171
+ byWeekday: [0],
172
+ },
173
+ },
174
+ };
175
+
176
+ describe('SchedulingBookingModal', () => {
177
+ beforeEach(() => {
178
+ cleanup();
179
+ });
180
+
181
+ it('muestra confirmación al cerrar con Escape si hay cambios sin guardar', async () => {
182
+ const onClose = vi.fn();
183
+ confirmActionMock.mockResolvedValue(false);
184
+
185
+ render(
186
+ <SchedulingBookingModal
187
+ state={createState}
188
+ copy={copy}
189
+ onClose={onClose}
190
+ onEditorChange={vi.fn()}
191
+ onCreate={vi.fn()}
192
+ onAction={vi.fn()}
193
+ />,
194
+ );
195
+
196
+ fireEvent.change(screen.getByLabelText('Cliente'), { target: { value: 'Cliente editado' } });
197
+ fireEvent.keyDown(window, { key: 'Escape' });
198
+
199
+ await waitFor(() => {
200
+ expect(confirmActionMock).toHaveBeenCalledWith(
201
+ expect.objectContaining({
202
+ title: 'Descartar borrador',
203
+ confirmLabel: 'Descartar',
204
+ cancelLabel: 'Seguir editando',
205
+ }),
206
+ );
207
+ });
208
+
209
+ expect(onClose).not.toHaveBeenCalled();
210
+ });
211
+
212
+ it('muestra solo el formulario editable del creador', async () => {
213
+ render(
214
+ <SchedulingBookingModal
215
+ state={createState}
216
+ copy={copy}
217
+ onClose={vi.fn()}
218
+ onEditorChange={vi.fn()}
219
+ onCreate={vi.fn()}
220
+ onAction={vi.fn()}
221
+ />,
222
+ );
223
+
224
+ expect(screen.queryByText('Resumen del slot')).toBeNull();
225
+ expect(screen.queryByText('Vista previa')).toBeNull();
226
+ expect(screen.queryByText('Nueva reserva')).toBeNull();
227
+ expect(screen.queryByText('Crear reserva')).toBeNull();
228
+ expect(screen.getByLabelText('Fecha foco')).toBeTruthy();
229
+ expect(screen.getByLabelText('Inicio')).toBeTruthy();
230
+ expect(screen.getByLabelText('Fin')).toBeTruthy();
231
+ expect(screen.getByLabelText('Recurso')).toBeTruthy();
232
+ expect(screen.getByLabelText('Título')).toBeTruthy();
233
+ expect(screen.getByLabelText('Repetir')).toBeTruthy();
234
+
235
+ fireEvent.change(screen.getByLabelText('Cliente'), { target: { value: 'Ada Lovelace' } });
236
+
237
+ await waitFor(() => {
238
+ expect(screen.getByDisplayValue('Ada Lovelace')).toBeTruthy();
239
+ });
240
+ });
241
+ });