-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathObjectCalendar.msw.test.tsx
More file actions
96 lines (80 loc) · 2.57 KB
/
Copy pathObjectCalendar.msw.test.tsx
File metadata and controls
96 lines (80 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { describe, it, expect, vi, beforeAll, afterAll, afterEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ObjectCalendar } from './ObjectCalendar';
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
import { setupServer } from 'msw/node';
import { http, HttpResponse } from 'msw';
import React from 'react';
const BASE_URL = 'http://localhost';
// --- Mock Data ---
const mockEvents = {
value: [
{
_id: '1',
title: 'Meeting with Client',
start: new Date().toISOString(),
end: new Date(Date.now() + 3600000).toISOString(),
type: 'business'
},
{
_id: '2',
title: 'Team Lunch',
start: new Date(Date.now() + 86400000).toISOString(), // Tomorrow
type: 'personal'
}
]
};
// --- MSW Setup ---
const handlers = [
http.options('*', () => {
return new HttpResponse(null, { status: 200 });
}),
http.get(`${BASE_URL}/api/v1`, () => {
return HttpResponse.json({ status: 'ok', version: '1.0.0' });
}),
// Data Query: GET /api/v1/data/events
http.get(`${BASE_URL}/api/v1/data/events`, () => {
return HttpResponse.json(mockEvents);
}),
// Metadata Query
http.get(`${BASE_URL}/api/v1/meta/object/events`, () => {
return HttpResponse.json({ fields: {} });
})
];
const server = setupServer(...handlers);
// --- Test Suite ---
describe('ObjectCalendar with MSW', () => {
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
it('fetches events and renders them', async () => {
const dataSource = new ObjectStackAdapter({
baseUrl: BASE_URL,
});
render(
<ObjectCalendar
schema={{
type: 'calendar',
objectName: 'events',
// Calendar specific config usually goes into 'calendar' prop or implicit mapping
calendar: {
dateField: 'start',
endDateField: 'end',
titleField: 'title'
}
}}
dataSource={dataSource}
/>
);
// Verify events appear
await waitFor(() => {
expect(screen.getByText('Meeting with Client')).toBeInTheDocument();
});
// Check subsequent events (might need navigation depending on view,
// but default month view usually shows current month dates)
// Note: If today is near end of month, tomorrow might be in next month view.
// However, the test event is "now", so it should be visible.
// We can just assert the first event for now.
});
});