@wix/headless-bookings 0.0.97 → 0.0.99
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/cjs/dist/__mocks__/booking/booking-client-service.d.ts +9 -0
- package/cjs/dist/__mocks__/booking/booking-client-service.js +55 -0
- package/cjs/dist/__mocks__/booking/booking-mocks.d.ts +20 -0
- package/cjs/dist/__mocks__/booking/booking-mocks.js +76 -0
- package/{dist/__mocks__/services.d.ts → cjs/dist/__mocks__/services/services-mocks.d.ts} +5 -17
- package/cjs/dist/__mocks__/{services.js → services/services-mocks.js} +1 -27
- package/cjs/dist/__mocks__/time-slots/time-slots-client-service.d.ts +79 -0
- package/cjs/dist/__mocks__/time-slots/time-slots-client-service.js +120 -0
- package/{dist/__mocks__/time-slots.d.ts → cjs/dist/__mocks__/time-slots/time-slots-core.d.ts} +1 -28
- package/cjs/dist/__mocks__/{time-slots.js → time-slots/time-slots-core.js} +1 -115
- package/cjs/dist/__mocks__/time-slots/time-slots-mocks.d.ts +14 -0
- package/cjs/dist/__mocks__/time-slots/time-slots-mocks.js +50 -0
- package/cjs/dist/services/booking/booking.js +2 -1
- package/cjs/dist/services/constants.d.ts +12 -0
- package/cjs/dist/services/constants.js +11 -0
- package/cjs/dist/services/service-list/service-list.js +1 -0
- package/cjs/dist/services/time-slot-list/time-slot-list.def.js +2 -1
- package/cjs/dist/services/time-slot-list/time-slot.js +2 -1
- package/dist/__mocks__/booking/booking-client-service.d.ts +9 -0
- package/dist/__mocks__/booking/booking-client-service.js +55 -0
- package/dist/__mocks__/booking/booking-mocks.d.ts +20 -0
- package/dist/__mocks__/booking/booking-mocks.js +76 -0
- package/{cjs/dist/__mocks__/services.d.ts → dist/__mocks__/services/services-mocks.d.ts} +5 -17
- package/dist/__mocks__/{services.js → services/services-mocks.js} +1 -27
- package/dist/__mocks__/time-slots/time-slots-client-service.d.ts +79 -0
- package/dist/__mocks__/time-slots/time-slots-client-service.js +120 -0
- package/{cjs/dist/__mocks__/time-slots.d.ts → dist/__mocks__/time-slots/time-slots-core.d.ts} +1 -28
- package/dist/__mocks__/{time-slots.js → time-slots/time-slots-core.js} +1 -115
- package/dist/__mocks__/time-slots/time-slots-mocks.d.ts +14 -0
- package/dist/__mocks__/time-slots/time-slots-mocks.js +50 -0
- package/dist/services/booking/booking.js +2 -1
- package/dist/services/constants.d.ts +12 -0
- package/dist/services/constants.js +11 -0
- package/dist/services/service-list/service-list.js +1 -0
- package/dist/services/time-slot-list/time-slot-list.def.js +2 -1
- package/dist/services/time-slot-list/time-slot.js +2 -1
- package/package.json +2 -2
- package/cjs/dist/__mocks__/booking.d.ts +0 -87
- package/cjs/dist/__mocks__/booking.js +0 -229
- package/dist/__mocks__/booking.d.ts +0 -87
- package/dist/__mocks__/booking.js +0 -229
- /package/cjs/dist/__mocks__/{payment.d.ts → payment/payment-mocks.d.ts} +0 -0
- /package/cjs/dist/__mocks__/{payment.js → payment/payment-mocks.js} +0 -0
- /package/dist/__mocks__/{payment.d.ts → payment/payment-mocks.d.ts} +0 -0
- /package/dist/__mocks__/{payment.js → payment/payment-mocks.js} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Signal } from '@wix/services-definitions/core-services/signals';
|
|
2
|
+
import type { BookingServiceConfig, BookingService } from '../../services/booking/booking.js';
|
|
3
|
+
export declare function mockSignal<T>(initialValue: T): Signal<T>;
|
|
4
|
+
export declare function createMockSignalsService(): {
|
|
5
|
+
signal: typeof mockSignal;
|
|
6
|
+
computed: <T>(fn: () => T) => Signal<T>;
|
|
7
|
+
effect: (fn: () => void) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createMockBookingService(config?: Partial<BookingServiceConfig>): BookingService;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
export function mockSignal(initialValue) {
|
|
3
|
+
let value = initialValue;
|
|
4
|
+
return {
|
|
5
|
+
get: () => value,
|
|
6
|
+
peek: () => value,
|
|
7
|
+
set: (newValue) => {
|
|
8
|
+
value = newValue;
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function createMockSignalsService() {
|
|
13
|
+
return {
|
|
14
|
+
signal: mockSignal,
|
|
15
|
+
// Re-evaluate the computed function on every get/peek (like real computed signals)
|
|
16
|
+
computed: (fn) => ({
|
|
17
|
+
get: () => fn(),
|
|
18
|
+
peek: () => fn(),
|
|
19
|
+
set: () => { }, // no-op for computed
|
|
20
|
+
}),
|
|
21
|
+
effect: vi.fn((fn) => {
|
|
22
|
+
fn();
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function createMockBookingService(config = {}) {
|
|
27
|
+
const { serviceSelections = [], location = null, timezone = 'UTC', formSubmission = null, } = config;
|
|
28
|
+
const serviceSelectionsSignal = mockSignal(serviceSelections);
|
|
29
|
+
const locationSignal = mockSignal(location);
|
|
30
|
+
const timezoneSignal = mockSignal(timezone);
|
|
31
|
+
const formSubmissionSignal = mockSignal(formSubmission);
|
|
32
|
+
return {
|
|
33
|
+
serviceSelections: serviceSelectionsSignal,
|
|
34
|
+
location: locationSignal,
|
|
35
|
+
timezone: timezoneSignal,
|
|
36
|
+
formSubmission: formSubmissionSignal,
|
|
37
|
+
actions: {
|
|
38
|
+
updateItem: vi.fn(),
|
|
39
|
+
setItem: vi.fn(),
|
|
40
|
+
addItem: vi.fn(),
|
|
41
|
+
removeItem: vi.fn(),
|
|
42
|
+
clearItems: vi.fn(),
|
|
43
|
+
setResource: vi.fn(),
|
|
44
|
+
getResourceByType: vi.fn(),
|
|
45
|
+
clearResourceByType: vi.fn(),
|
|
46
|
+
setLocation: vi.fn(),
|
|
47
|
+
clearLocation: vi.fn(),
|
|
48
|
+
setTimezone: vi.fn(),
|
|
49
|
+
setFormSubmission: vi.fn(),
|
|
50
|
+
clearFormSubmission: vi.fn(),
|
|
51
|
+
clearAll: vi.fn(),
|
|
52
|
+
book: vi.fn(),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FormValues } from '@wix/form-public';
|
|
2
|
+
import type { Location } from '@wix/auto_sdk_bookings_services';
|
|
3
|
+
import type { ServiceSelection, ServiceSelectionTimeSlot, ExtendedResource } from '../../services/booking/booking.js';
|
|
4
|
+
export declare function createMockResource(overrides?: Partial<ExtendedResource>): ExtendedResource;
|
|
5
|
+
export declare function createMockLocation(overrides?: Partial<Location>): Location;
|
|
6
|
+
export declare const mockResource: ExtendedResource;
|
|
7
|
+
export declare const mockResourceTwo: ExtendedResource;
|
|
8
|
+
export declare const mockLocation: Location;
|
|
9
|
+
export declare const mockLocationTwo: Location;
|
|
10
|
+
export declare const mockTimezone = "America/New_York";
|
|
11
|
+
export declare const mockTimeSlot: ServiceSelectionTimeSlot;
|
|
12
|
+
export declare function createMockServiceSelectionTimeSlot(overrides?: Partial<ServiceSelectionTimeSlot>): ServiceSelectionTimeSlot;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a mock ServiceSelection with sensible defaults
|
|
15
|
+
*/
|
|
16
|
+
export declare function createMockServiceSelection(overrides?: Partial<ServiceSelection>): ServiceSelection;
|
|
17
|
+
export declare const mockServiceSelection: ServiceSelection;
|
|
18
|
+
export declare const mockServiceSelectionWithoutTimeSlot: ServiceSelection;
|
|
19
|
+
export declare function createMockFormSubmission(overrides?: Partial<FormValues>): FormValues;
|
|
20
|
+
export declare const mockFormSubmission: FormValues;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { mockService } from '../services/services-mocks.js';
|
|
2
|
+
export function createMockResource(overrides = {}) {
|
|
3
|
+
return {
|
|
4
|
+
_id: 'resource-1',
|
|
5
|
+
name: 'John Doe',
|
|
6
|
+
type: 'staff',
|
|
7
|
+
...overrides,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function createMockLocation(overrides = {}) {
|
|
11
|
+
return {
|
|
12
|
+
_id: 'location-1',
|
|
13
|
+
type: 'BUSINESS',
|
|
14
|
+
business: {
|
|
15
|
+
_id: 'location-1',
|
|
16
|
+
name: 'Main Office',
|
|
17
|
+
},
|
|
18
|
+
...overrides,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export const mockResource = createMockResource();
|
|
22
|
+
export const mockResourceTwo = createMockResource({
|
|
23
|
+
_id: 'resource-2',
|
|
24
|
+
name: 'Jane Smith',
|
|
25
|
+
});
|
|
26
|
+
export const mockLocation = createMockLocation();
|
|
27
|
+
export const mockLocationTwo = createMockLocation({
|
|
28
|
+
_id: 'location-2',
|
|
29
|
+
business: {
|
|
30
|
+
_id: 'location-2',
|
|
31
|
+
name: 'Downtown Branch',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
export const mockTimezone = 'America/New_York';
|
|
35
|
+
export const mockTimeSlot = createMockServiceSelectionTimeSlot();
|
|
36
|
+
export function createMockServiceSelectionTimeSlot(overrides = {}) {
|
|
37
|
+
return {
|
|
38
|
+
startDate: '2024-03-15T10:00:00Z',
|
|
39
|
+
endDate: '2024-03-15T11:00:00Z',
|
|
40
|
+
totalCapacity: 10,
|
|
41
|
+
remainingCapacity: 5,
|
|
42
|
+
scheduleId: 'schedule-123',
|
|
43
|
+
resources: [mockResource],
|
|
44
|
+
location: mockLocation,
|
|
45
|
+
...overrides,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a mock ServiceSelection with sensible defaults
|
|
50
|
+
*/
|
|
51
|
+
export function createMockServiceSelection(overrides = {}) {
|
|
52
|
+
return {
|
|
53
|
+
instanceId: 'instance-1',
|
|
54
|
+
service: mockService,
|
|
55
|
+
resources: [mockResource],
|
|
56
|
+
timeSlot: mockTimeSlot,
|
|
57
|
+
totalParticipants: 1,
|
|
58
|
+
...overrides,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export const mockServiceSelection = createMockServiceSelection();
|
|
62
|
+
export const mockServiceSelectionWithoutTimeSlot = createMockServiceSelection({
|
|
63
|
+
instanceId: 'instance-2',
|
|
64
|
+
resources: [],
|
|
65
|
+
timeSlot: undefined,
|
|
66
|
+
});
|
|
67
|
+
export function createMockFormSubmission(overrides = {}) {
|
|
68
|
+
return {
|
|
69
|
+
firstName: 'John',
|
|
70
|
+
lastName: 'Doe',
|
|
71
|
+
email: 'john.doe@example.com',
|
|
72
|
+
phone: '+1234567890',
|
|
73
|
+
...overrides,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export const mockFormSubmission = createMockFormSubmission();
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Shared mock data for booking service tests
|
|
3
3
|
*/
|
|
4
4
|
import type { Service, StaffMember } from '@wix/auto_sdk_bookings_services';
|
|
5
|
-
import type { ServiceServiceConfig } from '
|
|
6
|
-
import type { ServiceListServiceConfig } from '
|
|
7
|
-
import type { StaffMemberListServiceConfig } from '
|
|
8
|
-
import type { PagingMetadata } from '
|
|
9
|
-
import type { Category } from '
|
|
5
|
+
import type { ServiceServiceConfig } from '../../services/service/service.js';
|
|
6
|
+
import type { ServiceListServiceConfig } from '../../services/service-list/service-list.js';
|
|
7
|
+
import type { StaffMemberListServiceConfig } from '../../services/staff-member-list/staff-member-list.js';
|
|
8
|
+
import type { PagingMetadata } from '../../api/query-services/index.js';
|
|
9
|
+
import type { Category } from '../../api/query-categories/index.js';
|
|
10
10
|
/**
|
|
11
11
|
* Base mock service with all fields populated (APPOINTMENT type, FIXED pricing)
|
|
12
12
|
*/
|
|
@@ -75,22 +75,10 @@ export declare function createLargeServiceList(count: number): Service[];
|
|
|
75
75
|
* Mock categories for filter tests
|
|
76
76
|
*/
|
|
77
77
|
export declare const mockCategories: Category[];
|
|
78
|
-
/**
|
|
79
|
-
* Empty categories array
|
|
80
|
-
*/
|
|
81
|
-
export declare const mockEmptyCategories: Category[];
|
|
82
78
|
/**
|
|
83
79
|
* Service list config with categories for filter testing
|
|
84
80
|
*/
|
|
85
81
|
export declare const mockServiceListConfigWithCategories: ServiceListServiceConfig;
|
|
86
|
-
/**
|
|
87
|
-
* Service list config with categories and hasNext for pagination + filter testing
|
|
88
|
-
*/
|
|
89
|
-
export declare const mockServiceListConfigWithCategoriesAndMore: ServiceListServiceConfig;
|
|
90
|
-
/**
|
|
91
|
-
* Empty service list config with categories
|
|
92
|
-
*/
|
|
93
|
-
export declare const mockEmptyServiceListConfigWithCategories: ServiceListServiceConfig;
|
|
94
82
|
/**
|
|
95
83
|
* Base mock staff member with all fields
|
|
96
84
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Shared mock data for booking service tests
|
|
3
3
|
*/
|
|
4
4
|
import { RateType, ServiceType } from '@wix/auto_sdk_bookings_services';
|
|
5
|
-
import { BOOKING_APP_ID } from '
|
|
5
|
+
import { BOOKING_APP_ID } from '../../services/constants.js';
|
|
6
6
|
/**
|
|
7
7
|
* Base mock service with all fields populated (APPOINTMENT type, FIXED pricing)
|
|
8
8
|
*/
|
|
@@ -320,10 +320,6 @@ export const mockCategories = [
|
|
|
320
320
|
name: 'Beauty',
|
|
321
321
|
},
|
|
322
322
|
];
|
|
323
|
-
/**
|
|
324
|
-
* Empty categories array
|
|
325
|
-
*/
|
|
326
|
-
export const mockEmptyCategories = [];
|
|
327
323
|
/**
|
|
328
324
|
* Service list config with categories for filter testing
|
|
329
325
|
*/
|
|
@@ -335,28 +331,6 @@ export const mockServiceListConfigWithCategories = {
|
|
|
335
331
|
pagingMetadata: mockPagingMetadata,
|
|
336
332
|
},
|
|
337
333
|
};
|
|
338
|
-
/**
|
|
339
|
-
* Service list config with categories and hasNext for pagination + filter testing
|
|
340
|
-
*/
|
|
341
|
-
export const mockServiceListConfigWithCategoriesAndMore = {
|
|
342
|
-
services: mockServices,
|
|
343
|
-
categories: mockCategories,
|
|
344
|
-
options: {
|
|
345
|
-
appId: BOOKING_APP_ID,
|
|
346
|
-
pagingMetadata: mockPagingMetadataWithMore,
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
/**
|
|
350
|
-
* Empty service list config with categories
|
|
351
|
-
*/
|
|
352
|
-
export const mockEmptyServiceListConfigWithCategories = {
|
|
353
|
-
services: [],
|
|
354
|
-
categories: mockCategories,
|
|
355
|
-
options: {
|
|
356
|
-
appId: BOOKING_APP_ID,
|
|
357
|
-
pagingMetadata: mockPagingMetadataEmpty,
|
|
358
|
-
},
|
|
359
|
-
};
|
|
360
334
|
// ============================================================================
|
|
361
335
|
// Staff Member Mocks
|
|
362
336
|
// ============================================================================
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
3
|
+
import type { TimeSlotListServiceAPI, TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
4
|
+
import type { BookingService, BookingServiceConfig } from '../../services/booking/booking.js';
|
|
5
|
+
import { Signal } from '@wix/services-definitions/core-services/signals';
|
|
6
|
+
export type UnwrapSignal<T> = T extends Signal<infer U> ? U : T;
|
|
7
|
+
export type UnwrapSignals<T> = {
|
|
8
|
+
[K in keyof T]: UnwrapSignal<T[K]>;
|
|
9
|
+
};
|
|
10
|
+
type TimeSlotListState = UnwrapSignals<Omit<TimeSlotListServiceAPI, 'actions'>>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a mock TimeSlotListService
|
|
13
|
+
*/
|
|
14
|
+
export declare function createMockTimeSlotListService(options?: Partial<TimeSlotListState>): {
|
|
15
|
+
timeSlots: Signal<TimeSlot[]>;
|
|
16
|
+
hasMore: Signal<boolean>;
|
|
17
|
+
isLoading: Signal<boolean>;
|
|
18
|
+
error: Signal<string | null>;
|
|
19
|
+
dateRange: Signal<import("../../services/time-slot-list/time-slot-list.def.js").DateRange>;
|
|
20
|
+
actions: {
|
|
21
|
+
loadMore: import("vitest").Mock<(...args: any[]) => any>;
|
|
22
|
+
setDateRange: import("vitest").Mock<(...args: any[]) => any>;
|
|
23
|
+
selectSlot: import("vitest").Mock<(...args: any[]) => any>;
|
|
24
|
+
selectStaffMember: import("vitest").Mock<(...args: any[]) => any>;
|
|
25
|
+
clearStaffSelection: import("vitest").Mock<(...args: any[]) => any>;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
|
|
29
|
+
service: TimeSlotListServiceAPI;
|
|
30
|
+
bookingService: BookingService;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Setup client service mocks for TimeSlot core component tests
|
|
34
|
+
* @param options - Optional configuration (timeSlot state + booking state)
|
|
35
|
+
*/
|
|
36
|
+
export declare function setupTimeSlotClientServiceMocks(options: Partial<{
|
|
37
|
+
timeSlot: TimeSlot;
|
|
38
|
+
} & BookingServiceConfig> | undefined, mockUseService: ReturnType<typeof vi.fn>): {
|
|
39
|
+
timeSlotService: {
|
|
40
|
+
timeSlotSignal: Signal<TimeSlot>;
|
|
41
|
+
};
|
|
42
|
+
timeSlotListService: {
|
|
43
|
+
timeSlots: Signal<TimeSlot[]>;
|
|
44
|
+
hasMore: Signal<boolean>;
|
|
45
|
+
isLoading: Signal<boolean>;
|
|
46
|
+
error: Signal<string | null>;
|
|
47
|
+
dateRange: Signal<import("../../services/time-slot-list/time-slot-list.def.js").DateRange>;
|
|
48
|
+
actions: {
|
|
49
|
+
loadMore: import("vitest").Mock<(...args: any[]) => any>;
|
|
50
|
+
setDateRange: import("vitest").Mock<(...args: any[]) => any>;
|
|
51
|
+
selectSlot: import("vitest").Mock<(...args: any[]) => any>;
|
|
52
|
+
selectStaffMember: import("vitest").Mock<(...args: any[]) => any>;
|
|
53
|
+
clearStaffSelection: import("vitest").Mock<(...args: any[]) => any>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
bookingService: BookingService;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Setup client service mocks for TimeSlotList core component tests
|
|
60
|
+
* @param options - Optional configuration for the mock state (TimeSlotList + Booking)
|
|
61
|
+
*/
|
|
62
|
+
export declare function setupTimeSlotListClientServiceMocks(options: Partial<TimeSlotListState & BookingServiceConfig> | undefined, mockUseService: ReturnType<typeof vi.fn>): {
|
|
63
|
+
timeSlotListService: {
|
|
64
|
+
timeSlots: Signal<TimeSlot[]>;
|
|
65
|
+
hasMore: Signal<boolean>;
|
|
66
|
+
isLoading: Signal<boolean>;
|
|
67
|
+
error: Signal<string | null>;
|
|
68
|
+
dateRange: Signal<import("../../services/time-slot-list/time-slot-list.def.js").DateRange>;
|
|
69
|
+
actions: {
|
|
70
|
+
loadMore: import("vitest").Mock<(...args: any[]) => any>;
|
|
71
|
+
setDateRange: import("vitest").Mock<(...args: any[]) => any>;
|
|
72
|
+
selectSlot: import("vitest").Mock<(...args: any[]) => any>;
|
|
73
|
+
selectStaffMember: import("vitest").Mock<(...args: any[]) => any>;
|
|
74
|
+
clearStaffSelection: import("vitest").Mock<(...args: any[]) => any>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
bookingService: BookingService;
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import { mockSignal, createMockBookingService, createMockSignalsService, } from '../booking/booking-client-service.js';
|
|
3
|
+
import { mockTimeSlot as defaultTimeSlot, mockTimeSlots as defaultTimeSlots, createTimeSlotListConfig, } from './time-slots-mocks.js';
|
|
4
|
+
import { ClientServiceIds } from '../../services/constants.js';
|
|
5
|
+
import { TimeSlotListService } from '../../services/time-slot-list/time-slot-list.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a mock TimeSlotListService
|
|
8
|
+
*/
|
|
9
|
+
export function createMockTimeSlotListService(options = {}) {
|
|
10
|
+
const { timeSlots = defaultTimeSlots, hasMore = false, isLoading = false, error = null, dateRange = {
|
|
11
|
+
start: new Date('2024-01-15'),
|
|
12
|
+
end: new Date('2024-01-22'),
|
|
13
|
+
}, } = options;
|
|
14
|
+
const actions = {
|
|
15
|
+
loadMore: vi.fn(),
|
|
16
|
+
setDateRange: vi.fn(),
|
|
17
|
+
selectSlot: vi.fn(),
|
|
18
|
+
selectStaffMember: vi.fn(),
|
|
19
|
+
clearStaffSelection: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
timeSlots: mockSignal(timeSlots),
|
|
23
|
+
hasMore: mockSignal(hasMore),
|
|
24
|
+
isLoading: mockSignal(isLoading),
|
|
25
|
+
error: mockSignal(error),
|
|
26
|
+
dateRange: mockSignal(dateRange),
|
|
27
|
+
actions,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function createTimeSlotListService(overrides = {}) {
|
|
31
|
+
const config = createTimeSlotListConfig(overrides);
|
|
32
|
+
const mockBookingService = createMockBookingService();
|
|
33
|
+
const mockSignalsService = createMockSignalsService();
|
|
34
|
+
const getService = (definition) => {
|
|
35
|
+
const def = definition;
|
|
36
|
+
if (def.name === 'signals') {
|
|
37
|
+
return mockSignalsService;
|
|
38
|
+
}
|
|
39
|
+
if (def.name === 'booking') {
|
|
40
|
+
return mockBookingService;
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Unknown service: ${def.name}`);
|
|
43
|
+
};
|
|
44
|
+
const service = TimeSlotListService({
|
|
45
|
+
getService,
|
|
46
|
+
config,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
service,
|
|
50
|
+
bookingService: mockBookingService,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Setup client service mocks for TimeSlot core component tests
|
|
55
|
+
* @param options - Optional configuration (timeSlot state + booking state)
|
|
56
|
+
*/
|
|
57
|
+
export function setupTimeSlotClientServiceMocks(options = {}, mockUseService) {
|
|
58
|
+
const { timeSlot = defaultTimeSlot, ...bookingOptions } = options;
|
|
59
|
+
const timeSlotService = { timeSlotSignal: mockSignal(timeSlot) };
|
|
60
|
+
const timeSlotListService = createMockTimeSlotListService();
|
|
61
|
+
const bookingService = createMockBookingService(bookingOptions);
|
|
62
|
+
mockUseService.mockImplementation((def) => {
|
|
63
|
+
switch (def.id) {
|
|
64
|
+
case ClientServiceIds.timeSlot:
|
|
65
|
+
return timeSlotService;
|
|
66
|
+
case ClientServiceIds.timeSlotList:
|
|
67
|
+
return timeSlotListService;
|
|
68
|
+
case ClientServiceIds.booking:
|
|
69
|
+
return bookingService;
|
|
70
|
+
default:
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
timeSlotService,
|
|
76
|
+
timeSlotListService,
|
|
77
|
+
bookingService,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// TimeSlotList Client Service Mocks Setup
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Setup client service mocks for TimeSlotList core component tests
|
|
85
|
+
* @param options - Optional configuration for the mock state (TimeSlotList + Booking)
|
|
86
|
+
*/
|
|
87
|
+
export function setupTimeSlotListClientServiceMocks(options = {}, mockUseService) {
|
|
88
|
+
const {
|
|
89
|
+
// TimeSlotList state
|
|
90
|
+
timeSlots, hasMore, isLoading, error, dateRange,
|
|
91
|
+
// Booking state
|
|
92
|
+
serviceSelections, location, timezone, formSubmission, } = options;
|
|
93
|
+
const timeSlotListService = createMockTimeSlotListService({
|
|
94
|
+
timeSlots,
|
|
95
|
+
hasMore,
|
|
96
|
+
isLoading,
|
|
97
|
+
error,
|
|
98
|
+
dateRange,
|
|
99
|
+
});
|
|
100
|
+
const bookingService = createMockBookingService({
|
|
101
|
+
serviceSelections,
|
|
102
|
+
location,
|
|
103
|
+
timezone,
|
|
104
|
+
formSubmission,
|
|
105
|
+
});
|
|
106
|
+
mockUseService.mockImplementation((def) => {
|
|
107
|
+
switch (def.id) {
|
|
108
|
+
case ClientServiceIds.timeSlotList:
|
|
109
|
+
return timeSlotListService;
|
|
110
|
+
case ClientServiceIds.booking:
|
|
111
|
+
return bookingService;
|
|
112
|
+
default:
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
timeSlotListService,
|
|
118
|
+
bookingService,
|
|
119
|
+
};
|
|
120
|
+
}
|
package/{dist/__mocks__/time-slots.d.ts → cjs/dist/__mocks__/time-slots/time-slots-core.d.ts}
RENAMED
|
@@ -1,34 +1,7 @@
|
|
|
1
1
|
import { vi } from 'vitest';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
4
|
-
import type {
|
|
5
|
-
import type { BookingService } from '../services/booking/booking.js';
|
|
6
|
-
import type { StaffMemberData } from '../react/time-slot-list/TimeSlot.js';
|
|
7
|
-
export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
|
|
8
|
-
service: TimeSlotListServiceAPI;
|
|
9
|
-
bookingService: BookingService;
|
|
10
|
-
};
|
|
11
|
-
export declare function createTimeSlot(overrides?: Partial<TimeSlot>): TimeSlot;
|
|
12
|
-
export declare function createTimeSlots(count: number): TimeSlot[];
|
|
13
|
-
export declare function createTimeSlotListConfig(overrides?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceConfig;
|
|
14
|
-
export declare const mockTimeSlot: TimeSlot;
|
|
15
|
-
export declare const mockTimeSlotMultipleStaff: TimeSlot;
|
|
16
|
-
export declare const mockTimeSlotNotBookable: TimeSlot;
|
|
17
|
-
export declare const mockTimeSlots: TimeSlot[];
|
|
18
|
-
export declare const mockStartDate: Date;
|
|
19
|
-
export declare const mockEndDate: Date;
|
|
20
|
-
export declare const mockTimezone = "America/New_York";
|
|
21
|
-
export declare const mockTimeSlotListConfig: TimeSlotListServiceConfig;
|
|
22
|
-
export declare const mockEmptyTimeSlotListConfig: TimeSlotListServiceConfig;
|
|
23
|
-
export declare const mockCursorPagingMetadataWithMore: {
|
|
24
|
-
cursors: {
|
|
25
|
-
next: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export declare const mockCursorPagingMetadataNoMore: {
|
|
29
|
-
cursors: {};
|
|
30
|
-
};
|
|
31
|
-
export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
|
|
4
|
+
import type { StaffMemberData } from '../../react/time-slot-list/TimeSlot.js';
|
|
32
5
|
export interface CoreTimeSlotMockConfig {
|
|
33
6
|
timeSlot: TimeSlot;
|
|
34
7
|
staffMembers: StaffMemberData[];
|
|
@@ -1,121 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { vi } from 'vitest';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
|
|
6
|
-
export function createTimeSlotListService(overrides = {}) {
|
|
7
|
-
const config = createTimeSlotListConfig(overrides);
|
|
8
|
-
const mockBookingService = createMockBookingService();
|
|
9
|
-
const mockSignalsService = createMockSignalsService();
|
|
10
|
-
const getService = (definition) => {
|
|
11
|
-
const def = definition;
|
|
12
|
-
if (def.name === 'signals') {
|
|
13
|
-
return mockSignalsService;
|
|
14
|
-
}
|
|
15
|
-
if (def.name === 'booking') {
|
|
16
|
-
return mockBookingService;
|
|
17
|
-
}
|
|
18
|
-
throw new Error(`Unknown service: ${def.name}`);
|
|
19
|
-
};
|
|
20
|
-
const service = TimeSlotListService({
|
|
21
|
-
getService,
|
|
22
|
-
config,
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
service,
|
|
26
|
-
bookingService: mockBookingService,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export function createTimeSlot(overrides = {}) {
|
|
30
|
-
return {
|
|
31
|
-
localStartDate: '2024-01-15T10:00:00',
|
|
32
|
-
localEndDate: '2024-01-15T11:00:00',
|
|
33
|
-
bookable: true,
|
|
34
|
-
totalCapacity: 10,
|
|
35
|
-
remainingCapacity: 5,
|
|
36
|
-
scheduleId: 'schedule-1',
|
|
37
|
-
location: { _id: 'loc-1', name: 'Main Office' },
|
|
38
|
-
availableResources: [{ resources: [{ _id: 'staff-1', name: 'John Doe' }] }],
|
|
39
|
-
...overrides,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function createTimeSlots(count) {
|
|
43
|
-
return Array.from({ length: count }, (_, i) => createTimeSlot({
|
|
44
|
-
localStartDate: `2024-01-15T${String(9 + (i % 8)).padStart(2, '0')}:00:00`,
|
|
45
|
-
localEndDate: `2024-01-15T${String(10 + (i % 8)).padStart(2, '0')}:00:00`,
|
|
46
|
-
scheduleId: `schedule-${i}`,
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
export function createTimeSlotListConfig(overrides = {}) {
|
|
50
|
-
const { startDate = new Date('2024-01-15T00:00:00'), endDate = new Date('2024-01-22T00:00:00'), timezone = 'America/New_York', timeSlots, ...rest } = overrides;
|
|
51
|
-
return {
|
|
52
|
-
startDate,
|
|
53
|
-
endDate,
|
|
54
|
-
timezone,
|
|
55
|
-
...rest,
|
|
56
|
-
...(timeSlots !== undefined ? { timeSlots } : {}),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
export const mockTimeSlot = createTimeSlot();
|
|
60
|
-
export const mockTimeSlotMultipleStaff = createTimeSlot({
|
|
61
|
-
availableResources: [
|
|
62
|
-
{
|
|
63
|
-
resources: [
|
|
64
|
-
{ _id: 'staff-1', name: 'John Doe' },
|
|
65
|
-
{ _id: 'staff-2', name: 'Jane Smith' },
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
});
|
|
70
|
-
export const mockTimeSlotNotBookable = createTimeSlot({
|
|
71
|
-
localStartDate: '2024-01-15T14:00:00',
|
|
72
|
-
localEndDate: '2024-01-15T15:00:00',
|
|
73
|
-
bookable: false,
|
|
74
|
-
remainingCapacity: 0,
|
|
75
|
-
location: { _id: 'loc-2', name: 'Downtown Branch' },
|
|
76
|
-
});
|
|
77
|
-
export const mockTimeSlots = [
|
|
78
|
-
mockTimeSlot,
|
|
79
|
-
mockTimeSlotMultipleStaff,
|
|
80
|
-
mockTimeSlotNotBookable,
|
|
81
|
-
];
|
|
82
|
-
export const mockStartDate = new Date('2024-01-15T00:00:00');
|
|
83
|
-
export const mockEndDate = new Date('2024-01-22T00:00:00');
|
|
84
|
-
export const mockTimezone = 'America/New_York';
|
|
85
|
-
export const mockTimeSlotListConfig = createTimeSlotListConfig({
|
|
86
|
-
timeSlots: mockTimeSlots,
|
|
87
|
-
});
|
|
88
|
-
export const mockEmptyTimeSlotListConfig = createTimeSlotListConfig();
|
|
89
|
-
export const mockCursorPagingMetadataWithMore = {
|
|
90
|
-
cursors: { next: 'next-cursor-token' },
|
|
91
|
-
};
|
|
92
|
-
export const mockCursorPagingMetadataNoMore = { cursors: {} };
|
|
93
|
-
export function createMockTimeSlotListService(config = {}) {
|
|
94
|
-
const timeSlotsSignal = mockSignal(config.timeSlots || []);
|
|
95
|
-
const isLoadingSignal = mockSignal(false);
|
|
96
|
-
const errorSignal = mockSignal(null);
|
|
97
|
-
const hasMoreSignal = mockSignal(false);
|
|
98
|
-
const dateRangeSignal = mockSignal({
|
|
99
|
-
start: config.startDate || mockStartDate,
|
|
100
|
-
end: config.endDate || mockEndDate,
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
timeSlots: timeSlotsSignal,
|
|
104
|
-
isLoading: isLoadingSignal,
|
|
105
|
-
error: errorSignal,
|
|
106
|
-
hasMore: hasMoreSignal,
|
|
107
|
-
dateRange: dateRangeSignal,
|
|
108
|
-
actions: {
|
|
109
|
-
selectSlot: vi.fn(),
|
|
110
|
-
selectStaffMember: vi.fn(),
|
|
111
|
-
clearStaffSelection: vi.fn(),
|
|
112
|
-
loadMore: vi.fn(),
|
|
113
|
-
setDateRange: vi.fn((start, end) => {
|
|
114
|
-
dateRangeSignal.set({ start, end });
|
|
115
|
-
}),
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
4
|
+
import { mockTimeSlot, mockTimeSlots } from './time-slots-mocks.js';
|
|
119
5
|
export function createCoreTimeSlotMock(config) {
|
|
120
6
|
const { timeSlot, staffMembers, selectTimeSlot, clearStaffSelection, selectStaffMember, } = config;
|
|
121
7
|
const startDate = new Date(timeSlot.localStartDate);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
2
|
+
import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
3
|
+
export declare function createTimeSlot(overrides?: Partial<TimeSlot>): TimeSlot;
|
|
4
|
+
export declare function createTimeSlotListConfig(overrides?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceConfig;
|
|
5
|
+
export declare const mockTimeSlot: TimeSlot;
|
|
6
|
+
export declare const mockTimeSlotMultipleStaff: TimeSlot;
|
|
7
|
+
export declare const mockTimeSlotNotBookable: TimeSlot;
|
|
8
|
+
export declare const mockTimeSlots: TimeSlot[];
|
|
9
|
+
export declare const mockStartDate: Date;
|
|
10
|
+
export declare const mockEndDate: Date;
|
|
11
|
+
export declare const mockTimezone = "America/New_York";
|
|
12
|
+
export declare const mockCursorPagingMetadataNoMore: {
|
|
13
|
+
cursors: {};
|
|
14
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function createTimeSlot(overrides = {}) {
|
|
2
|
+
return {
|
|
3
|
+
localStartDate: '2024-01-15T10:00:00',
|
|
4
|
+
localEndDate: '2024-01-15T11:00:00',
|
|
5
|
+
bookable: true,
|
|
6
|
+
totalCapacity: 10,
|
|
7
|
+
remainingCapacity: 5,
|
|
8
|
+
scheduleId: 'schedule-1',
|
|
9
|
+
location: { _id: 'loc-1', name: 'Main Office' },
|
|
10
|
+
availableResources: [{ resources: [{ _id: 'staff-1', name: 'John Doe' }] }],
|
|
11
|
+
...overrides,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function createTimeSlotListConfig(overrides = {}) {
|
|
15
|
+
const { startDate = new Date('2024-01-15T00:00:00'), endDate = new Date('2024-01-22T00:00:00'), timezone = 'America/New_York', timeSlots, ...rest } = overrides;
|
|
16
|
+
return {
|
|
17
|
+
startDate,
|
|
18
|
+
endDate,
|
|
19
|
+
timezone,
|
|
20
|
+
...rest,
|
|
21
|
+
...(timeSlots !== undefined ? { timeSlots } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export const mockTimeSlot = createTimeSlot();
|
|
25
|
+
export const mockTimeSlotMultipleStaff = createTimeSlot({
|
|
26
|
+
availableResources: [
|
|
27
|
+
{
|
|
28
|
+
resources: [
|
|
29
|
+
{ _id: 'staff-1', name: 'John Doe' },
|
|
30
|
+
{ _id: 'staff-2', name: 'Jane Smith' },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
export const mockTimeSlotNotBookable = createTimeSlot({
|
|
36
|
+
localStartDate: '2024-01-15T14:00:00',
|
|
37
|
+
localEndDate: '2024-01-15T15:00:00',
|
|
38
|
+
bookable: false,
|
|
39
|
+
remainingCapacity: 0,
|
|
40
|
+
location: { _id: 'loc-2', name: 'Downtown Branch' },
|
|
41
|
+
});
|
|
42
|
+
export const mockTimeSlots = [
|
|
43
|
+
mockTimeSlot,
|
|
44
|
+
mockTimeSlotMultipleStaff,
|
|
45
|
+
mockTimeSlotNotBookable,
|
|
46
|
+
];
|
|
47
|
+
export const mockStartDate = new Date('2024-01-15T00:00:00');
|
|
48
|
+
export const mockEndDate = new Date('2024-01-22T00:00:00');
|
|
49
|
+
export const mockTimezone = 'America/New_York';
|
|
50
|
+
export const mockCursorPagingMetadataNoMore = { cursors: {} };
|