test(editor-ext): extract shared ProseMirror table-test fixture (F1)
The schema + cell/row/table/doc builders + grid/stateFor/trFor were copied verbatim into the 3 new table-utils test files (and the pre-existing table-utils.test.ts) — a schema change would have to be synced across all four. Move them into a shared table-test-helpers.ts (test-only, excluded from the build like footnote-corpus.ts) and import it everywhere; cell uses the (txt, attrs?) superset (a drop-in for the bare (txt) copies). No assertion changes — test counts unchanged (223 passed + 3 expected-fail). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { Schema } from "@tiptap/pm/model";
|
||||
import type { Node as PMNode } from "@tiptap/pm/model";
|
||||
import { tableNodes, TableMap } from "@tiptap/pm/tables";
|
||||
import { TableMap } from "@tiptap/pm/tables";
|
||||
import { transpose } from "./transpose";
|
||||
import { moveRowInArrayOfRows } from "./move-row-in-array-of-rows";
|
||||
import { convertTableNodeToArrayOfRows } from "./convert-table-node-to-array-of-rows";
|
||||
import { convertArrayOfRowsToTableNode } from "./convert-array-of-rows-to-table-node";
|
||||
import { cell, row, table } from "./table-test-helpers";
|
||||
|
||||
/**
|
||||
* Unit tests for the pure table data-transformation utilities. These functions
|
||||
@@ -14,30 +14,6 @@ import { convertArrayOfRowsToTableNode } from "./convert-array-of-rows-to-table-
|
||||
* ProseMirror table schema (the same primitives the editor uses).
|
||||
*/
|
||||
|
||||
// Minimal schema containing real ProseMirror table nodes so TableMap behaves
|
||||
// exactly as it does in the editor (merged cells, colspan, etc.).
|
||||
const tNodes = tableNodes({
|
||||
tableGroup: "block",
|
||||
cellContent: "inline*",
|
||||
cellAttributes: {},
|
||||
});
|
||||
const schema = new Schema({
|
||||
nodes: {
|
||||
doc: { content: "block+" },
|
||||
paragraph: { group: "block", content: "inline*", toDOM: () => ["p", 0] },
|
||||
text: { group: "inline" },
|
||||
...tNodes,
|
||||
},
|
||||
marks: {},
|
||||
});
|
||||
|
||||
const cell = (txt: string, attrs?: Record<string, unknown>): PMNode =>
|
||||
schema.nodes.table_cell.createChecked(attrs ?? null, schema.text(txt));
|
||||
const row = (...cells: PMNode[]): PMNode =>
|
||||
schema.nodes.table_row.createChecked(null, cells);
|
||||
const table = (...rows: PMNode[]): PMNode =>
|
||||
schema.nodes.table.createChecked(null, rows);
|
||||
|
||||
// Read the text content of each (non-null) cell so we can compare structure
|
||||
// without depending on ProseMirror node identity.
|
||||
const textGrid = (rows: (PMNode | null)[][]): (string | null)[][] =>
|
||||
|
||||
Reference in New Issue
Block a user