fix(grid): improve transposed selection and navigation
This commit is contained in:
4 files changed
+169
-37
No files matched your search
@@ -1,5 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { averageTransposeRecordWidth, calculateTransposeRecordWidth, defaultTransposeRecordWidth, minTransposeFieldWidth, shouldAutoTransposeSingleRow, transposeFieldWidth, transposeRecordWidthsForDensity, visibleTransposeRecordWindow } from "@/lib/dataGrid/dataGridTranspose";
|
||||
import {
|
||||
averageTransposeRecordWidth,
|
||||
calculateTransposeRecordWidth,
|
||||
defaultTransposeRecordWidth,
|
||||
minTransposeFieldWidth,
|
||||
shouldAutoTransposeSingleRow,
|
||||
transposeAnchorRowIndex,
|
||||
transposeFieldWidth,
|
||||
transposeScrollLeftForRecord,
|
||||
transposeRecordWidthsForDensity,
|
||||
visibleTransposeRecordWindow,
|
||||
} from "@/lib/dataGrid/dataGridTranspose";
|
||||
|
||||
describe("single-row automatic transpose", () => {
|
||||
it("only opens for enabled multi-column results that are not preserving a manual transpose", () => {
|
||||
@@ -12,6 +23,21 @@ describe("single-row automatic transpose", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("transpose row anchor", () => {
|
||||
it("keeps the requested row when multiple rows or cells are selected", () => {
|
||||
const rowIds = [1, 2, 3, 4];
|
||||
|
||||
expect(
|
||||
transposeAnchorRowIndex({
|
||||
requestedRowIndex: 3,
|
||||
rowIds,
|
||||
selectedRowIds: new Set([1, 4]),
|
||||
selectedRange: { startRow: 0, endRow: 3, startCol: 0, endCol: 1 },
|
||||
}),
|
||||
).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("dataGridTranspose density widths", () => {
|
||||
it("uses the shared density preset for record and field widths", () => {
|
||||
const values = ["x".repeat(40)];
|
||||
@@ -78,3 +104,46 @@ describe("dataGridTranspose density widths", () => {
|
||||
expect(averageTransposeRecordWidth([], "compact")).toBe(defaultTransposeRecordWidth("compact"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("transpose record scrolling", () => {
|
||||
it("uses the scroll position after the sticky field for virtualization", () => {
|
||||
expect(
|
||||
visibleTransposeRecordWindow({
|
||||
totalRecords: 3,
|
||||
scrollLeft: 500,
|
||||
viewportWidth: 300,
|
||||
pinnedWidth: 100,
|
||||
recordWidth: 230,
|
||||
recordOffsets: [0, 500, 596, 692],
|
||||
overscan: 0,
|
||||
}),
|
||||
).toEqual({ start: 1, end: 3, beforeWidth: 500, afterWidth: 0 });
|
||||
});
|
||||
|
||||
it("uses actual record widths and nearest scrolling", () => {
|
||||
const recordOffsets = [0, 500, 596, 692];
|
||||
|
||||
expect(
|
||||
transposeScrollLeftForRecord({
|
||||
recordIndex: 2,
|
||||
totalRecords: 3,
|
||||
viewportWidth: 300,
|
||||
pinnedWidth: 100,
|
||||
recordWidth: 230,
|
||||
recordOffsets,
|
||||
currentScrollLeft: 0,
|
||||
}),
|
||||
).toBe(492);
|
||||
expect(
|
||||
transposeScrollLeftForRecord({
|
||||
recordIndex: 1,
|
||||
totalRecords: 3,
|
||||
viewportWidth: 300,
|
||||
pinnedWidth: 100,
|
||||
recordWidth: 230,
|
||||
recordOffsets,
|
||||
currentScrollLeft: 450,
|
||||
}),
|
||||
).toBe(450);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user