@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,169 @@
1
+ // @vitest-environment jsdom
2
+
3
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4
+ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import type { SchedulingClient } from './client';
7
+ import { QueueOperatorBoard } from './QueueOperatorBoard';
8
+ import type { Branch, DayAgendaItem, Queue } from './types';
9
+
10
+ const confirmActionMock = vi.hoisted(() => vi.fn(async () => true));
11
+
12
+ vi.mock('@devpablocristo/core-browser', () => ({
13
+ confirmAction: confirmActionMock,
14
+ }));
15
+
16
+ function createClient(overrides?: Partial<Record<keyof SchedulingClient, unknown>>): SchedulingClient {
17
+ const branches: Branch[] = [
18
+ {
19
+ id: 'branch-1',
20
+ org_id: 'org-1',
21
+ code: 'HQ',
22
+ name: 'Casa Central',
23
+ timezone: 'America/Argentina/Tucuman',
24
+ address: 'Main street 123',
25
+ active: true,
26
+ created_at: '2099-04-01T00:00:00Z',
27
+ updated_at: '2099-04-01T00:00:00Z',
28
+ },
29
+ ];
30
+
31
+ const queues: Queue[] = [
32
+ {
33
+ id: 'queue-1',
34
+ org_id: 'org-1',
35
+ branch_id: 'branch-1',
36
+ service_id: null,
37
+ code: 'BOX-1',
38
+ name: 'Mesa de entrada',
39
+ status: 'active',
40
+ strategy: 'fifo',
41
+ ticket_prefix: 'A',
42
+ avg_service_seconds: 180,
43
+ allow_remote_join: true,
44
+ created_at: '2099-04-01T00:00:00Z',
45
+ updated_at: '2099-04-01T00:00:00Z',
46
+ },
47
+ ];
48
+
49
+ const dayAgenda: DayAgendaItem[] = [
50
+ {
51
+ type: 'queue_ticket',
52
+ id: 'ticket-1',
53
+ branch_id: 'branch-1',
54
+ status: 'waiting',
55
+ label: 'A-17',
56
+ metadata: {
57
+ queue_id: 'queue-1',
58
+ number: 17,
59
+ },
60
+ },
61
+ ];
62
+
63
+ return {
64
+ listBranches: vi.fn(async () => branches),
65
+ listQueues: vi.fn(async () => queues),
66
+ getDayAgenda: vi.fn(async () => dayAgenda),
67
+ createQueueTicket: vi.fn(async () => ({
68
+ id: 'ticket-2',
69
+ org_id: 'org-1',
70
+ queue_id: 'queue-1',
71
+ branch_id: 'branch-1',
72
+ number: 18,
73
+ display_code: 'A-18',
74
+ customer_name: 'Ada Lovelace',
75
+ customer_phone: '+54 381 555 0404',
76
+ status: 'waiting',
77
+ source: 'reception',
78
+ priority: 2,
79
+ notes: '',
80
+ requested_at: '2099-04-05T10:00:00Z',
81
+ updated_at: '2099-04-05T10:00:00Z',
82
+ })),
83
+ closeQueue: vi.fn(async () => queues[0]),
84
+ listServices: vi.fn(),
85
+ listResources: vi.fn(),
86
+ listSlots: vi.fn(),
87
+ listBookings: vi.fn(),
88
+ getBooking: vi.fn(),
89
+ createBooking: vi.fn(),
90
+ confirmBooking: vi.fn(),
91
+ cancelBooking: vi.fn(),
92
+ checkInBooking: vi.fn(),
93
+ startService: vi.fn(),
94
+ completeBooking: vi.fn(),
95
+ markBookingNoShow: vi.fn(),
96
+ rescheduleBooking: vi.fn(),
97
+ listWaitlist: vi.fn(),
98
+ getQueuePosition: vi.fn(),
99
+ pauseQueue: vi.fn(),
100
+ reopenQueue: vi.fn(),
101
+ callNext: vi.fn(),
102
+ serveTicket: vi.fn(),
103
+ completeTicket: vi.fn(),
104
+ markTicketNoShow: vi.fn(),
105
+ cancelTicket: vi.fn(),
106
+ returnTicketToWaiting: vi.fn(),
107
+ getDashboard: vi.fn(),
108
+ ...(overrides ?? {}),
109
+ } as SchedulingClient;
110
+ }
111
+
112
+ function renderBoard(client: SchedulingClient, locale = 'es') {
113
+ cleanup();
114
+ const queryClient = new QueryClient({
115
+ defaultOptions: {
116
+ queries: { retry: false },
117
+ mutations: { retry: false },
118
+ },
119
+ });
120
+
121
+ return render(
122
+ <QueryClientProvider client={queryClient}>
123
+ <QueueOperatorBoard client={client} locale={locale} initialBranchId="branch-1" initialDate="2099-04-05" />
124
+ </QueryClientProvider>,
125
+ );
126
+ }
127
+
128
+ describe('QueueOperatorBoard', () => {
129
+ it('issues a ticket with the queue operator payload', async () => {
130
+ const client = createClient();
131
+
132
+ renderBoard(client);
133
+
134
+ fireEvent.change(await screen.findByLabelText('Cliente'), { target: { value: 'Ada Lovelace' } });
135
+ fireEvent.change(screen.getByLabelText('Teléfono'), { target: { value: '+54 381 555 0404' } });
136
+ fireEvent.change(screen.getByLabelText('Prioridad'), { target: { value: '2' } });
137
+ fireEvent.click(screen.getByRole('button', { name: 'Emitir ticket' }));
138
+
139
+ await waitFor(() => {
140
+ expect(client.createQueueTicket).toHaveBeenCalledWith('queue-1', {
141
+ customer_name: 'Ada Lovelace',
142
+ customer_phone: '+54 381 555 0404',
143
+ customer_email: undefined,
144
+ priority: 2,
145
+ });
146
+ });
147
+ });
148
+
149
+ it('confirms and closes an active queue', async () => {
150
+ const client = createClient();
151
+
152
+ renderBoard(client);
153
+
154
+ fireEvent.click(await screen.findByRole('button', { name: 'Cerrar cola' }));
155
+
156
+ await waitFor(() => {
157
+ expect(confirmActionMock).toHaveBeenCalled();
158
+ expect(client.closeQueue).toHaveBeenCalledWith('queue-1');
159
+ });
160
+ });
161
+
162
+ it('keeps spanish copy when using a regional spanish locale', async () => {
163
+ const client = createClient();
164
+
165
+ renderBoard(client, 'es-AR');
166
+
167
+ expect(await screen.findByRole('button', { name: 'Cerrar cola' })).toBeTruthy();
168
+ });
169
+ });