feat : update
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
moveExtraSheetRow,
|
||||
normalizeExtraSheetRichText,
|
||||
updateExtraSheetCell,
|
||||
updateExtraSheetCells,
|
||||
} from "@/lib/guides/extra-sheet";
|
||||
|
||||
function idFactory() {
|
||||
@@ -26,8 +27,8 @@ describe("Extra sheet", () => {
|
||||
expect(extraSheetSchema.safeParse(sheet).success).toBe(true);
|
||||
expect(sheet.columns.map((column) => column.label)).toEqual(["คอลัมน์ 1", "คอลัมน์ 2"]);
|
||||
expect(extraSheetToMatrix(sheet)).toEqual([
|
||||
[{ value: "" }, { value: "" }],
|
||||
[{ value: "" }, { value: "" }],
|
||||
[{ value: "", backgroundColor: undefined }, { value: "", backgroundColor: undefined }],
|
||||
[{ value: "", backgroundColor: undefined }, { value: "", backgroundColor: undefined }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -42,8 +43,8 @@ describe("Extra sheet", () => {
|
||||
|
||||
const moved = moveExtraSheetRow(moveExtraSheetColumn(sheet, 0, 1), 0, 1);
|
||||
expect(extraSheetToMatrix(moved)).toEqual([
|
||||
[{ value: "" }, { value: "C" }],
|
||||
[{ value: "B" }, { value: "A" }],
|
||||
[{ value: "", backgroundColor: undefined }, { value: "C", backgroundColor: undefined }],
|
||||
[{ value: "B", backgroundColor: undefined }, { value: "A", backgroundColor: undefined }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -60,7 +61,10 @@ describe("Extra sheet", () => {
|
||||
|
||||
const reduced = deleteExtraSheetColumn(expanded, 2);
|
||||
expect(reduced.rows.every((row) => !(columnId in row.cells))).toBe(true);
|
||||
expect(deleteExtraSheetRow(reduced, 2).rows).toHaveLength(2);
|
||||
const secondRowId = reduced.rows[1].id;
|
||||
const withoutFirstRow = deleteExtraSheetRow(reduced, 0);
|
||||
expect(withoutFirstRow.rows).toHaveLength(2);
|
||||
expect(withoutFirstRow.rows[0].id).toBe(secondRowId);
|
||||
});
|
||||
|
||||
it("expands rows and columns when a pasted matrix is larger", () => {
|
||||
@@ -102,4 +106,20 @@ describe("Extra sheet", () => {
|
||||
"<p><strong>safe</strong></p>",
|
||||
);
|
||||
});
|
||||
|
||||
it("updates rich text and backgrounds across a cell selection", () => {
|
||||
const sheet = createExtraSheet(idFactory());
|
||||
const updated = updateExtraSheetCells(sheet, [
|
||||
{ row: 0, column: 0 },
|
||||
{ row: 1, column: 1 },
|
||||
], { value: "<p>Shared</p>", backgroundColor: "#16A34A" });
|
||||
|
||||
expect(extraSheetToMatrix(updated)).toEqual([
|
||||
[{ value: "<p>Shared</p>", backgroundColor: "#16A34A" }, { value: "", backgroundColor: undefined }],
|
||||
[{ value: "", backgroundColor: undefined }, { value: "<p>Shared</p>", backgroundColor: "#16A34A" }],
|
||||
]);
|
||||
expect(extraSheetSchema.safeParse(updated).success).toBe(true);
|
||||
expect(updateExtraSheetCells(updated, [{ row: 0, column: 0 }], { backgroundColor: null })
|
||||
.rows[0].backgrounds).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user