This repository was archived by the owner on Mar 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-pagination-sync.tsx
More file actions
235 lines (222 loc) · 6.05 KB
/
test-pagination-sync.tsx
File metadata and controls
235 lines (222 loc) · 6.05 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import React, { useState } from "react";
import {
DataTable,
PaginationConfig,
} from "./packages/ui-kit/src/components/data-display/DataTable/DataTable";
import { ColumnDef } from "@tanstack/react-table";
// Test data type
interface TestPerson {
id: number;
name: string;
email: string;
department: string;
salary: number;
startDate: string;
}
// Generate test data with > 100 entries
const generateTestData = (count: number): TestPerson[] => {
const departments = [
"Engineering",
"Marketing",
"Sales",
"HR",
"Finance",
"Operations",
];
const firstNames = [
"John",
"Jane",
"Mike",
"Sarah",
"David",
"Emily",
"Chris",
"Lisa",
"Alex",
"Rachel",
];
const lastNames = [
"Smith",
"Johnson",
"Williams",
"Brown",
"Jones",
"Garcia",
"Miller",
"Davis",
"Rodriguez",
"Martinez",
];
return Array.from({ length: count }, (_, i) => ({
id: i + 1,
name: `${firstNames[i % firstNames.length]} ${lastNames[i % lastNames.length]}`,
email: `user${i + 1}@company.com`,
department: departments[i % departments.length],
salary: 50000 + Math.floor(Math.random() * 100000),
startDate: new Date(
2020 + Math.floor(Math.random() * 4),
Math.floor(Math.random() * 12),
Math.floor(Math.random() * 28) + 1,
)
.toISOString()
.split("T")[0],
}));
};
// Column definitions
const columns: ColumnDef<TestPerson>[] = [
{
accessorKey: "id",
header: "ID",
size: 80,
},
{
accessorKey: "name",
header: "Name",
size: 150,
},
{
accessorKey: "email",
header: "Email",
size: 200,
},
{
accessorKey: "department",
header: "Department",
size: 120,
},
{
accessorKey: "salary",
header: "Salary",
size: 100,
cell: ({ getValue }) => {
const amount = getValue() as number;
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(amount);
},
},
{
accessorKey: "startDate",
header: "Start Date",
size: 120,
},
];
// Test scenarios
export const PaginationSyncTest: React.FC = () => {
const [testData] = useState(() => generateTestData(150)); // Generate 150 entries
const [currentTest, setCurrentTest] = useState<string>("default");
const testScenarios: Record<
string,
{ title: string; config: PaginationConfig | undefined }
> = {
default: {
title: "Default Configuration",
config: undefined,
},
customPageSize: {
title: "Custom Page Size (15) - Should be in dropdown",
config: {
pageSize: 15,
showSizeSelector: true,
showPageInfo: true,
showNavigation: true,
pageSizeOptions: [10, 25, 50, 100],
},
},
missingPageSize: {
title: "Page Size NOT in Options (35) - This should cause sync issue",
config: {
pageSize: 35,
showSizeSelector: true,
showPageInfo: true,
showNavigation: true,
pageSizeOptions: [10, 25, 50, 100], // 35 is NOT in this list
},
},
edgeCasePageSize: {
title: "Edge Case: Page Size 1 (not in default options)",
config: {
pageSize: 1,
showSizeSelector: true,
showPageInfo: true,
showNavigation: true,
pageSizeOptions: [10, 25, 50, 100],
},
},
duplicateOptions: {
title: "Duplicate Page Size Options",
config: {
pageSize: 20,
showSizeSelector: true,
showPageInfo: true,
showNavigation: true,
pageSizeOptions: [10, 20, 25, 20, 50, 100, 25], // Duplicates should be handled
},
},
};
return (
<div className="p-8 max-w-6xl mx-auto">
<h1 className="text-3xl font-bold mb-6">
DataTable Pagination Sync Test
</h1>
<div className="mb-6">
<h2 className="text-xl font-semibold mb-4">Test Scenarios</h2>
<div className="flex flex-wrap gap-2 mb-4">
{Object.entries(testScenarios).map(([key, scenario]) => (
<button
key={key}
onClick={() => setCurrentTest(key)}
className={`px-4 py-2 rounded-md text-sm font-medium ${
currentTest === key
? "bg-blue-600 text-white"
: "bg-gray-200 text-gray-700 hover:bg-gray-300"
}`}
>
{scenario.title}
</button>
))}
</div>
<div className="bg-yellow-50 border border-yellow-200 rounded-md p-4 mb-6">
<h3 className="font-semibold text-yellow-800 mb-2">
Current Test:{" "}
{testScenarios[currentTest as keyof typeof testScenarios].title}
</h3>
<p className="text-sm text-yellow-700">
<strong>Instructions:</strong> Test the page size dropdown. Check
if:
</p>
<ul className="text-sm text-yellow-700 list-disc list-inside mt-2">
<li>The dropdown shows the correct current page size</li>
<li>Changing the dropdown updates the table immediately</li>
<li>The table state stays synchronized with the dropdown</li>
<li>No console errors or infinite re-renders occur</li>
</ul>
</div>
</div>
<div className="mb-4">
<p className="text-sm text-gray-600">
Dataset: {testData.length} entries | Current Test:{" "}
{testScenarios[currentTest as keyof typeof testScenarios].title}
</p>
</div>
<DataTable
data={testData}
columns={columns}
pagination={testScenarios[currentTest].config}
enableKeyboardShortcuts={true}
/>
<div className="mt-8 bg-gray-50 border border-gray-200 rounded-md p-4">
<h3 className="font-semibold mb-2">Debug Information</h3>
<pre className="text-xs text-gray-600">
{JSON.stringify(
testScenarios[currentTest as keyof typeof testScenarios].config,
null,
2,
)}
</pre>
</div>
</div>
);
};
export default PaginationSyncTest;