-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathObjectTimeline.msw.test.tsx
More file actions
84 lines (67 loc) · 2.5 KB
/
ObjectTimeline.msw.test.tsx
File metadata and controls
84 lines (67 loc) · 2.5 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
import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest';
import { render, screen, waitFor } from '@testing-library/react';
import { ObjectTimeline } from './ObjectTimeline';
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 mockMilestones = {
value: [
{ id: '1', title: 'Start Project', due_date: '2023-01-01', description: 'Initial Kickoff' },
{ id: '2', title: 'Beta Launch', due_date: '2023-06-01', description: 'Public Beta' },
{ id: '3', title: 'Release', due_date: '2023-12-01', description: 'v1.0 Release' }
]
};
// --- 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' });
}),
http.get(`${BASE_URL}/api/v1/discovery`, () => {
return HttpResponse.json({ status: 'ok', version: '1.0.0' });
}),
http.get(`${BASE_URL}/api/v1/data/milestones`, () => {
return HttpResponse.json(mockMilestones);
})
];
const server = setupServer(...handlers);
// --- Test Suite ---
describe('ObjectTimeline with MSW', () => {
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
it('fetches and renders timeline items from object data', async () => {
const adapter = new ObjectStackAdapter({
baseUrl: BASE_URL,
bucket: 'test-bucket'
});
const schema = {
type: 'timeline',
objectName: 'milestones',
variant: 'vertical',
titleField: 'title',
dateField: 'due_date',
descriptionField: 'description'
};
render(
<ObjectTimeline
// @ts-expect-error - Mock schema type mismatch with TimelineSchema
schema={schema}
dataSource={adapter}
/>
);
// Wait for items to appear
await waitFor(() => {
expect(screen.getByText('Start Project')).toBeInTheDocument();
});
expect(screen.getByText('Beta Launch')).toBeInTheDocument();
expect(screen.getByText('Release')).toBeInTheDocument();
// Check descriptions if rendered
expect(screen.getByText('Initial Kickoff')).toBeInTheDocument();
});
});