feat : update
This commit is contained in:
@@ -3,15 +3,20 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
addExtraSheetColumn,
|
||||
addExtraSheetRow,
|
||||
clearExtraSheetCellFormatting,
|
||||
createExtraSheet,
|
||||
deleteExtraSheetColumn,
|
||||
deleteExtraSheetRow,
|
||||
extraSheetSchema,
|
||||
extraSheetRangeToTsv,
|
||||
extraSheetToMatrix,
|
||||
matrixToExtraSheet,
|
||||
moveExtraSheetColumn,
|
||||
moveExtraSheetRow,
|
||||
normalizeExtraSheetRichText,
|
||||
parseExtraSheetTsv,
|
||||
pasteExtraSheetText,
|
||||
resizeExtraSheetColumn,
|
||||
styleExtraSheetCells,
|
||||
updateExtraSheetCell,
|
||||
updateExtraSheetCells,
|
||||
@@ -152,6 +157,57 @@ describe("Extra sheet", () => {
|
||||
expect(extraSheetToMatrix(legacy)[0][0]).toEqual({
|
||||
value: "",
|
||||
backgroundColor: undefined,
|
||||
alignment: undefined,
|
||||
});
|
||||
|
||||
const parsed = extraSheetSchema.parse(legacy);
|
||||
expect(parsed.columns[0].width).toBe(140);
|
||||
expect(parsed.rows[0].alignments).toEqual({});
|
||||
});
|
||||
|
||||
it("persists bounded column widths and cell alignment", () => {
|
||||
const sheet = createExtraSheet(idFactory());
|
||||
const resized = resizeExtraSheetColumn(sheet, 0, 999);
|
||||
const aligned = updateExtraSheetCells(resized, [{ row: 0, column: 0 }], {
|
||||
alignment: "center",
|
||||
backgroundColor: "#123456",
|
||||
});
|
||||
|
||||
expect(aligned.columns[0].width).toBe(480);
|
||||
expect(extraSheetToMatrix(aligned)[0][0]).toMatchObject({
|
||||
alignment: "center",
|
||||
backgroundColor: "#123456",
|
||||
});
|
||||
expect(extraSheetSchema.safeParse(aligned).success).toBe(true);
|
||||
});
|
||||
|
||||
it("clears visual formatting without clearing cell content", () => {
|
||||
const sheet = createExtraSheet(idFactory());
|
||||
const columnId = sheet.columns[0].id;
|
||||
sheet.rows[0].cells[columnId] = '<p><strong><span style="color: #FF0000">Alpha</span></strong></p>';
|
||||
sheet.rows[0].backgrounds[columnId] = "#123456";
|
||||
sheet.rows[0].alignments[columnId] = "right";
|
||||
|
||||
const cleared = clearExtraSheetCellFormatting(sheet, [{ row: 0, column: 0 }]);
|
||||
expect(cleared.rows[0].cells[columnId]).toBe("<p>Alpha</p>");
|
||||
expect(cleared.rows[0].backgrounds).toEqual({});
|
||||
expect(cleared.rows[0].alignments).toEqual({});
|
||||
});
|
||||
|
||||
it("copies plain TSV and pastes multiline cells while expanding the grid", () => {
|
||||
const createId = idFactory();
|
||||
const sheet = createExtraSheet(createId);
|
||||
const firstColumn = sheet.columns[0].id;
|
||||
sheet.rows[0].cells[firstColumn] = "<p>Alpha<br>Beta</p>";
|
||||
const copied = extraSheetRangeToTsv(sheet, { row: 0, column: 0 }, { row: 0, column: 0 });
|
||||
|
||||
expect(copied).toBe('"Alpha\nBeta"');
|
||||
expect(parseExtraSheetTsv('"Alpha\nBeta"\tGamma')).toEqual([["Alpha\nBeta", "Gamma"]]);
|
||||
|
||||
const pasted = pasteExtraSheetText(sheet, { row: 2, column: 2 }, '"Alpha\nBeta"\tGamma', createId);
|
||||
expect(pasted.rows).toHaveLength(3);
|
||||
expect(pasted.columns).toHaveLength(4);
|
||||
expect(pasted.rows[2].cells[pasted.columns[2].id]).toBe("<p>Alpha<br>Beta</p>");
|
||||
expect(pasted.rows[2].cells[pasted.columns[3].id]).toBe("<p>Gamma</p>");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user