Skip to content

Commit b3590b6

Browse files
committed
test: add integration tests for ObjectKanban component with various grouping scenarios
1 parent c3a0668 commit b3590b6

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
import { describe, it, expect, vi, beforeEach } from 'vitest';
3+
import { render, screen, waitFor } from '@testing-library/react';
4+
import React from 'react';
5+
import { ObjectKanban } from '@object-ui/plugin-kanban';
6+
7+
// We perform Integration Testing on the REAL component to verify display.
8+
// We do not mock KanbanImpl, so we test the full stack including DndContext.
9+
10+
describe('ObjectKanban Todo Example Display', () => {
11+
12+
// Mock Data Source
13+
const mockDataSource = {
14+
find: vi.fn(),
15+
getObjectSchema: vi.fn(),
16+
getObject: vi.fn() // Fallback if old code still exists
17+
};
18+
19+
const todoSchema = {
20+
name: 'todo_task',
21+
fields: {
22+
priority: {
23+
type: 'rating',
24+
max: 3,
25+
label: 'Priority'
26+
},
27+
status: {
28+
type: 'select',
29+
options: [
30+
{ label: 'New', value: 'new' },
31+
{ label: 'Done', value: 'done' }
32+
]
33+
}
34+
}
35+
};
36+
37+
beforeEach(() => {
38+
vi.clearAllMocks();
39+
mockDataSource.getObjectSchema.mockResolvedValue(todoSchema);
40+
});
41+
42+
it('Scenario 1: Priority Grouping with Data (Dynamic Columns 1, 2, 3)', async () => {
43+
const mockData = [
44+
{ id: '1', subject: 'Task A', priority: 1 },
45+
{ id: '2', subject: 'Task B', priority: 2 },
46+
{ id: '4', subject: 'Task D', priority: 3 }
47+
];
48+
mockDataSource.find.mockResolvedValue(mockData);
49+
50+
render(
51+
<ObjectKanban
52+
schema={{
53+
type: 'kanban',
54+
objectName: 'todo_task',
55+
groupBy: 'priority',
56+
// Critical: Must map the card title to the correct field (subject)
57+
cardTitle: 'subject'
58+
} as any}
59+
dataSource={mockDataSource as any}
60+
/>
61+
);
62+
63+
// Wait for data to appear
64+
await waitFor(() => expect(screen.getByText('Task A')).toBeInTheDocument());
65+
66+
// Verify Column Headers (H3 in real component)
67+
// We expect columns named "1", "2", "3"
68+
expect(screen.getByRole('heading', { name: '1' })).toBeInTheDocument();
69+
expect(screen.getByRole('heading', { name: '2' })).toBeInTheDocument();
70+
expect(screen.getByRole('heading', { name: '3' })).toBeInTheDocument();
71+
});
72+
73+
it('Scenario 2: Priority Grouping WITHOUT Data (Empty Board)', async () => {
74+
mockDataSource.find.mockResolvedValue([]);
75+
76+
const { container } = render(
77+
<ObjectKanban
78+
schema={{ type: 'kanban', objectName: 'todo_task', groupBy: 'priority' } as any}
79+
dataSource={mockDataSource as any}
80+
/>
81+
);
82+
83+
await waitFor(() => expect(mockDataSource.find).toHaveBeenCalled());
84+
85+
// Should NOT find any generated numerical headings
86+
expect(screen.queryByRole('heading', { name: '1' })).toBeNull();
87+
88+
// Use container query to ensure nothing substantial rendered
89+
// The real component renders a wrapper div.
90+
// We check that NO columns exist.
91+
// Assuming .flex-shrink-0 matches the column wrapper style inside KanbanImpl
92+
const columns = container.querySelectorAll('.flex-shrink-0');
93+
expect(columns.length).toBe(0);
94+
});
95+
96+
it('Scenario 3: Status Grouping (Select Field) WITHOUT Data (Shows Options)', async () => {
97+
mockDataSource.find.mockResolvedValue([]);
98+
99+
render(
100+
<ObjectKanban
101+
schema={{ type: 'kanban', objectName: 'todo_task', groupBy: 'status' } as any}
102+
dataSource={mockDataSource as any}
103+
/>
104+
);
105+
106+
// Wait for metadata options to render
107+
await waitFor(() => expect(screen.getByRole('heading', { name: /New/i })).toBeInTheDocument());
108+
expect(screen.getByRole('heading', { name: /Done/i })).toBeInTheDocument();
109+
});
110+
111+
it('Scenario 4: Explicit Columns Override (Fix for Empty Data)', async () => {
112+
mockDataSource.find.mockResolvedValue([]);
113+
114+
render(
115+
<ObjectKanban
116+
schema={{
117+
type: 'kanban',
118+
objectName: 'todo_task',
119+
groupBy: 'priority',
120+
// User manually defines the columns (Lanes) they want
121+
columns: [
122+
{ id: '1', title: 'High (1)' },
123+
{ id: '2', title: 'Medium (2)' },
124+
{ id: '3', title: 'Low (3)' }
125+
]
126+
} as any}
127+
dataSource={mockDataSource as any}
128+
/>
129+
);
130+
131+
await waitFor(() => expect(screen.getByRole('heading', { name: 'High (1)' })).toBeInTheDocument());
132+
133+
// We should see the 3 explicit columns
134+
expect(screen.getByRole('heading', { name: 'Medium (2)' })).toBeInTheDocument();
135+
expect(screen.getByRole('heading', { name: 'Low (3)' })).toBeInTheDocument();
136+
});
137+
});

0 commit comments

Comments
 (0)