mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-16 17:17:03 +00:00
692d91cffa
- DataTable: route handlePageSizeChange through handlePaginationChange so onPageChange fires when picking "All" on a high page drops pageIndex to 0. Without this, the URL kept a stale ?page=N while the display correctly clamped to "Page 1 of 1". - DataTable: reconcile effect in controlled mode now compares externalPageIndex (the URL source of truth) against safePageIndex instead of the internal mirror, which can drop to 0 via handlePageSizeChange and hide the URL mismatch from the previous comparison. - knowledges: add meta.columnMenuLabel to docType and question columns so the Columns dropdown reads "Type" / "Question" — same labels as the table headers — aligning with the Flags/Preview entries. - data-table.test: cover both pathways — out-of-range controlled pageIndex on mount, and pageSize=All from page 2. - vitest.setup: polyfill hasPointerCapture / setPointerCapture / releasePointerCapture so Radix Select interactions don't crash in jsdom. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
import '@testing-library/jest-dom/vitest';
|
|
|
|
import { cleanup } from '@testing-library/react';
|
|
import { afterEach } from 'vitest';
|
|
|
|
// jsdom doesn't implement `Element.prototype.scrollIntoView` — components
|
|
// that call it from effects (e.g. roving-focus + scroll into view) crash in
|
|
// tests without this no-op polyfill.
|
|
if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView) {
|
|
Element.prototype.scrollIntoView = function scrollIntoView() {
|
|
/* no-op for jsdom */
|
|
};
|
|
}
|
|
|
|
// Radix ScrollArea (used inside the navigation sheet) calls
|
|
// `new ResizeObserver(...)` from a layout effect; jsdom doesn't ship one.
|
|
// The component degrades gracefully — a no-op observer never invokes the
|
|
// callback, which is fine for tests that don't assert on overflow state.
|
|
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
class NoopResizeObserver implements ResizeObserver {
|
|
disconnect() {
|
|
/* no-op */
|
|
}
|
|
observe() {
|
|
/* no-op */
|
|
}
|
|
unobserve() {
|
|
/* no-op */
|
|
}
|
|
}
|
|
globalThis.ResizeObserver = NoopResizeObserver as unknown as typeof ResizeObserver;
|
|
}
|
|
|
|
// Radix Select gates pointer events behind `hasPointerCapture` / `setPointerCapture`,
|
|
// which jsdom doesn't implement. Without these no-ops, `userEvent.click` on a
|
|
// SelectTrigger throws "target.hasPointerCapture is not a function" mid-render.
|
|
if (typeof Element !== 'undefined' && !Element.prototype.hasPointerCapture) {
|
|
Element.prototype.hasPointerCapture = function hasPointerCapture() {
|
|
return false;
|
|
};
|
|
Element.prototype.setPointerCapture = function setPointerCapture() {
|
|
/* no-op for jsdom */
|
|
};
|
|
Element.prototype.releasePointerCapture = function releasePointerCapture() {
|
|
/* no-op for jsdom */
|
|
};
|
|
}
|
|
|
|
// React Testing Library leaves rendered nodes attached to `document.body`
|
|
// after each test. Without this, tests would leak DOM state into each other
|
|
// — e.g. two `render(<X />)` calls would both end up on screen at once.
|
|
afterEach(() => {
|
|
cleanup();
|
|
});
|