Skip to content

Commit

Permalink
[TEST]
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachico committed Apr 16, 2024
1 parent e93dcf5 commit f2bee9d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
1 change: 0 additions & 1 deletion tests/clipboard/clipboard_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,6 @@ describe("clipboard", () => {
});

cut(model, "A1:A2");
expect(getStyle(model, "A2", "s2")).toEqual({});
activateSheet(model, "sheet2");
paste(model, "A1");

Expand Down
28 changes: 24 additions & 4 deletions tests/grid/grid_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,12 @@ describe("Copy paste keyboard shortcut", () => {
setCellContent(model, "A1", "things");
selectCell(model, "A1");
document.body.dispatchEvent(getClipboardEvent("copy", clipboardData));
expect(clipboardData.content).toEqual({ "text/plain": "things", "text/html": "things" });
expect(clipboardData.content).toEqual({
"text/plain": "things",
"text/html": "things",
"web application/o-spreadsheet":
'{"cellPositions":[[{"col":0,"row":0,"sheetId":"Sheet1"}]],"cells":[[{"cell":{"id":"1","content":"things","isFormula":false},"evaluatedCell":{"value":"things","formattedValue":"things","type":"text","isAutoSummable":true,"defaultAlign":"left"},"position":{"col":0,"row":0,"sheetId":"Sheet1"}}]],"zones":[{"left":0,"right":0,"top":0,"bottom":0}],"sheetId":"Sheet1","borders":[[null]],"tableCells":[[{}]]}',
});
selectCell(model, "A2");
document.body.dispatchEvent(getClipboardEvent("paste", clipboardData));
expect(getCellContent(model, "A2")).toEqual("things");
Expand All @@ -1379,7 +1384,12 @@ describe("Copy paste keyboard shortcut", () => {
setCellContent(model, "A1", "things");
selectCell(model, "A1");
document.body.dispatchEvent(getClipboardEvent("cut", clipboardData));
expect(clipboardData.content).toEqual({ "text/plain": "things", "text/html": "things" });
expect(clipboardData.content).toEqual({
"text/plain": "things",
"text/html": "things",
"web application/o-spreadsheet":
'{"cellPositions":[[{"col":0,"row":0,"sheetId":"Sheet1"}]],"cells":[[{"cell":{"id":"1","content":"things","isFormula":false},"evaluatedCell":{"value":"things","formattedValue":"things","type":"text","isAutoSummable":true,"defaultAlign":"left"},"position":{"col":0,"row":0,"sheetId":"Sheet1"}}]],"zones":[{"left":0,"right":0,"top":0,"bottom":0}],"sheetId":"Sheet1","borders":[[null]],"tableCells":[[{}]]}',
});
selectCell(model, "A2");
document.body.dispatchEvent(getClipboardEvent("paste", clipboardData));
expect(getCellContent(model, "A1")).toEqual("");
Expand Down Expand Up @@ -1541,7 +1551,12 @@ describe("Copy paste keyboard shortcut", () => {
createChart(model, {}, "chartId");
model.dispatch("SELECT_FIGURE", { id: "chartId" });
document.body.dispatchEvent(getClipboardEvent("copy", clipboardData));
expect(clipboardData.content).toEqual({ "text/plain": "\t" });
expect(clipboardData.content).toEqual({
"text/plain": "\t",
"text/html": undefined,
"web application/o-spreadsheet":
'{"figureId":"chartId","copiedFigure":{"id":"chartId","x":0,"y":0,"width":536,"height":335,"tag":"chart"},"copiedChart":{"sheetId":"Sheet1","title":"test","getters":{},"dataSets":[],"verticalAxisPosition":"left","legendPosition":"top","stacked":false,"aggregated":false,"type":"bar","dataSetsHaveTitle":false}}',
});
document.body.dispatchEvent(getClipboardEvent("paste", clipboardData));
expect(model.getters.getChartIds(sheetId)).toHaveLength(2);
});
Expand All @@ -1551,7 +1566,12 @@ describe("Copy paste keyboard shortcut", () => {
createChart(model, {}, "chartId");
model.dispatch("SELECT_FIGURE", { id: "chartId" });
document.body.dispatchEvent(getClipboardEvent("cut", clipboardData));
expect(clipboardData.content).toEqual({ "text/plain": "\t" });
expect(clipboardData.content).toEqual({
"text/plain": "\t",
"text/html": undefined,
"web application/o-spreadsheet":
'{"figureId":"chartId","copiedFigure":{"id":"chartId","x":0,"y":0,"width":536,"height":335,"tag":"chart"},"copiedChart":{"sheetId":"Sheet1","title":"test","getters":{},"dataSets":[],"verticalAxisPosition":"left","legendPosition":"top","stacked":false,"aggregated":false,"type":"bar","dataSetsHaveTitle":false}}',
});
document.body.dispatchEvent(getClipboardEvent("paste", clipboardData));
expect(model.getters.getChartIds(sheetId)).toHaveLength(1);
expect(model.getters.getChartIds(sheetId)[0]).not.toEqual("chartId");
Expand Down
8 changes: 6 additions & 2 deletions tests/helpers/ui_helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ describe("UI Helpers", () => {
const clipboardString = "a\t1\nb\t2";

test("Can interactive paste", () => {
interactivePasteFromOS(env, target("D2"), clipboardString);
interactivePasteFromOS(env, target("D2"), {
"text/plain": clipboardString,
});
expect(getCellContent(model, "D2")).toBe("a");
expect(getCellContent(model, "E2")).toBe("1");
expect(getCellContent(model, "D3")).toBe("b");
Expand All @@ -262,7 +264,9 @@ describe("UI Helpers", () => {
test("Pasting content that will destroy a merge will notify the user", async () => {
merge(model, "B2:C3");
selectCell(model, "A1");
interactivePasteFromOS(env, model.getters.getSelectedZones(), clipboardString);
interactivePasteFromOS(env, model.getters.getSelectedZones(), {
"text/plain": clipboardString,
});
expect(notifyUserTextSpy).toHaveBeenCalledWith(
PasteInteractiveContent.willRemoveExistingMerge.toString()
);
Expand Down
20 changes: 15 additions & 5 deletions tests/menus/menu_items_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ describe("Menu Item actions", () => {
await env.clipboard.writeText("Then copy in OS clipboard");
await doAction(["edit", "paste"], env);
expect(dispatch).toHaveBeenCalledWith("PASTE_FROM_OS_CLIPBOARD", {
text: "Then copy in OS clipboard",
clipboardContent: {
"text/plain": "Then copy in OS clipboard",
},
target: [{ bottom: 0, left: 0, right: 0, top: 0 }],
});
});
Expand Down Expand Up @@ -186,7 +188,9 @@ describe("Menu Item actions", () => {
selectCell(model, "A1");
await doAction(["edit", "paste_special", "paste_special_format"], env);
expect(dispatch).toHaveBeenCalledWith("PASTE_FROM_OS_CLIPBOARD", {
text: "Copy in OS clipboard",
clipboardContent: {
"text/plain": "Copy in OS clipboard",
},
target: target("A1"),
pasteOption: "onlyFormat",
});
Expand All @@ -202,7 +206,9 @@ describe("Menu Item actions", () => {
selectCell(model, "A1");
await doAction(["edit", "paste_special", "paste_special_format"], env);
expect(dispatch).toHaveBeenCalledWith("PASTE_FROM_OS_CLIPBOARD", {
text: "Then copy in OS clipboard",
clipboardContent: {
"text/plain": "Then copy in OS clipboard",
},
target: target("A1"),
pasteOption: "onlyFormat",
});
Expand Down Expand Up @@ -234,7 +240,9 @@ describe("Menu Item actions", () => {
await doAction(["edit", "paste_special", "paste_special_value"], env);
expect(dispatch).toHaveBeenCalledWith("PASTE_FROM_OS_CLIPBOARD", {
target: target("A1"),
text,
clipboardContent: {
"text/plain": text,
},
pasteOption: "asValue",
});
});
Expand All @@ -254,7 +262,9 @@ describe("Menu Item actions", () => {
await doAction(["edit", "paste_special", "paste_special_format"], env);
expect(dispatch).toHaveBeenCalledWith("PASTE_FROM_OS_CLIPBOARD", {
target: target("A1"),
text,
clipboardContent: {
"text/plain": text,
},
pasteOption: "onlyFormat",
});
});
Expand Down

0 comments on commit f2bee9d

Please sign in to comment.