mirror of
https://github.com/ruilisi/fortune-sheet.git
synced 2025-01-08 11:47:38 +08:00
chore: refine test
This commit is contained in:
parent
c0800c3248
commit
cf92b6d670
38
packages/core/src/__tests__/toolbar/auto-formula.test.js
Normal file
38
packages/core/src/__tests__/toolbar/auto-formula.test.js
Normal file
@ -0,0 +1,38 @@
|
||||
import { getFlowdata } from "../../context";
|
||||
import { autoSelectionFormula } from "../../modules/toolbar";
|
||||
|
||||
describe("auto formula", () => {
|
||||
const getContext = () => ({
|
||||
currentSheetIndex: "index_1",
|
||||
allowEdit: true,
|
||||
config: {},
|
||||
luckysheet_select_save: [
|
||||
{
|
||||
row: [0, 1],
|
||||
column: [0, 1],
|
||||
},
|
||||
],
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "index_1",
|
||||
data: [
|
||||
[{ v: "30" }, { v: "40" }, null],
|
||||
[{ v: "30" }, { v: "50" }, null],
|
||||
[null, null, null],
|
||||
],
|
||||
length: 1,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
test("sum", async () => {
|
||||
const cellInput = document.createElement("div");
|
||||
const context = getContext();
|
||||
autoSelectionFormula(context, cellInput, "SUM");
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[0][2].v).toBe(70);
|
||||
expect(flowdata[1][2].v).toBe(80);
|
||||
expect(flowdata[2][0].v).toBe(60);
|
||||
expect(flowdata[2][1].v).toBe(90);
|
||||
});
|
||||
});
|
80
packages/core/src/__tests__/toolbar/border-style.test.js
Normal file
80
packages/core/src/__tests__/toolbar/border-style.test.js
Normal file
@ -0,0 +1,80 @@
|
||||
import { handleBorder } from "../../modules/toolbar";
|
||||
|
||||
const context = {
|
||||
currentSheetIndex: "0",
|
||||
config: {},
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "0",
|
||||
data: [
|
||||
[null, null],
|
||||
[null, null],
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("border", () => {
|
||||
it("border-top", async () => {
|
||||
handleBorder(context, "border-top");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[0].borderType).toEqual(
|
||||
"border-top"
|
||||
);
|
||||
});
|
||||
it("border-bottom", async () => {
|
||||
handleBorder(context, "border-bottom");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[1].borderType).toEqual(
|
||||
"border-bottom"
|
||||
);
|
||||
});
|
||||
it("border-left", async () => {
|
||||
handleBorder(context, "border-left");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[2].borderType).toEqual(
|
||||
"border-left"
|
||||
);
|
||||
});
|
||||
it("border-right", async () => {
|
||||
handleBorder(context, "border-right");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[3].borderType).toEqual(
|
||||
"border-right"
|
||||
);
|
||||
});
|
||||
it("border-none", async () => {
|
||||
handleBorder(context, "border-none");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[4].borderType).toEqual(
|
||||
"border-none"
|
||||
);
|
||||
});
|
||||
it("border-all", async () => {
|
||||
handleBorder(context, "border-all");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[5].borderType).toEqual(
|
||||
"border-all"
|
||||
);
|
||||
});
|
||||
it("border-outside", async () => {
|
||||
handleBorder(context, "border-none");
|
||||
handleBorder(context, "border-outside");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[7].borderType).toEqual(
|
||||
"border-outside"
|
||||
);
|
||||
});
|
||||
it("border-inside", async () => {
|
||||
handleBorder(context, "border-inside");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[8].borderType).toEqual(
|
||||
"border-inside"
|
||||
);
|
||||
});
|
||||
it("border-horizontal", async () => {
|
||||
handleBorder(context, "border-none");
|
||||
handleBorder(context, "border-horizontal");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[10].borderType).toEqual(
|
||||
"border-horizontal"
|
||||
);
|
||||
});
|
||||
it("border-vertical", async () => {
|
||||
handleBorder(context, "border-vertical");
|
||||
expect(context.luckysheetfile[0].config.borderInfo[11].borderType).toEqual(
|
||||
"border-vertical"
|
||||
);
|
||||
});
|
||||
});
|
52
packages/core/src/__tests__/toolbar/merge-cell.test.js
Normal file
52
packages/core/src/__tests__/toolbar/merge-cell.test.js
Normal file
@ -0,0 +1,52 @@
|
||||
import { handleMerge } from "../../modules/toolbar";
|
||||
|
||||
describe("Cells", () => {
|
||||
const context = {
|
||||
config: {},
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "0",
|
||||
data: [
|
||||
[
|
||||
{
|
||||
v: "hello",
|
||||
},
|
||||
null,
|
||||
],
|
||||
[null, null],
|
||||
],
|
||||
},
|
||||
],
|
||||
currentSheetIndex: "0",
|
||||
luckysheet_select_save: [
|
||||
{
|
||||
left: 0,
|
||||
width: 73,
|
||||
top: 0,
|
||||
height: 19,
|
||||
left_move: 0,
|
||||
width_move: 147,
|
||||
top_move: 0,
|
||||
height_move: 39,
|
||||
row: [0, 1],
|
||||
column: [0, 1],
|
||||
row_focus: 0,
|
||||
column_focus: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
it("MergeAllCell", async () => {
|
||||
handleMerge(context, "merge-all");
|
||||
expect(context.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(context.luckysheetfile[0].data[0][1].mc.r).toEqual(0);
|
||||
expect(context.luckysheetfile[0].data[0][1].mc.c).toEqual(0);
|
||||
handleMerge(context, "merge-cancel");
|
||||
handleMerge(context, "merge-vertical");
|
||||
expect(context.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(context.luckysheetfile[0].data[0][1].mc.rs).toEqual(2);
|
||||
handleMerge(context, "merge-cancel");
|
||||
handleMerge(context, "merge-horizontal");
|
||||
expect(context.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(context.luckysheetfile[0].data[1][0].mc.cs).toEqual(2);
|
||||
});
|
||||
});
|
@ -1,11 +1,10 @@
|
||||
import { getFlowdata } from "../context";
|
||||
import { getFlowdata } from "../../context";
|
||||
import {
|
||||
autoSelectionFormula,
|
||||
handleCurrencyFormat,
|
||||
handleNumberDecrease,
|
||||
handleNumberIncrease,
|
||||
handlePercentageFormat,
|
||||
} from "./toolbar";
|
||||
} from "../../modules/toolbar";
|
||||
|
||||
describe("number format", () => {
|
||||
const context = {
|
||||
@ -32,58 +31,24 @@ describe("number format", () => {
|
||||
],
|
||||
};
|
||||
const cellInput = document.createElement("div");
|
||||
test("for currency format", async () => {
|
||||
test("currency", async () => {
|
||||
handleCurrencyFormat(context, cellInput);
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[1][1].m).toBe("¥ 5.00");
|
||||
});
|
||||
test("for percentage format", async () => {
|
||||
test("percentage", async () => {
|
||||
handlePercentageFormat(context, cellInput);
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[1][1].m).toBe("500.00%");
|
||||
});
|
||||
test("for numberdecrease format", async () => {
|
||||
test("number decrease", async () => {
|
||||
handleNumberDecrease(context, cellInput);
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[1][1].m).toBe("500.0%");
|
||||
});
|
||||
test("for numberincrease format", async () => {
|
||||
test("number increase", async () => {
|
||||
handleNumberIncrease(context, cellInput);
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[1][1].m).toBe("500.00%");
|
||||
});
|
||||
});
|
||||
|
||||
describe("test for auto selection formula", () => {
|
||||
const context = {
|
||||
currentSheetIndex: "index_1",
|
||||
allowEdit: true,
|
||||
config: {},
|
||||
luckysheet_select_save: [
|
||||
{
|
||||
row: [0, 1],
|
||||
column: [0, 1],
|
||||
},
|
||||
],
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "index_1",
|
||||
data: [
|
||||
[{ v: "30" }, { v: "40" }, null],
|
||||
[{ v: "30" }, { v: "50" }, null],
|
||||
[null, null, null],
|
||||
],
|
||||
length: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
const cellInput = document.createElement("div");
|
||||
test("for sum", async () => {
|
||||
autoSelectionFormula(context, cellInput, "SUM");
|
||||
const flowdata = getFlowdata(context);
|
||||
expect(flowdata[0][2].v).toBe(70);
|
||||
expect(flowdata[1][2].v).toBe(80);
|
||||
expect(flowdata[2][0].v).toBe(60);
|
||||
expect(flowdata[2][1].v).toBe(90);
|
||||
});
|
||||
});
|
@ -1,77 +0,0 @@
|
||||
import { handleBorder } from "../toolbar";
|
||||
|
||||
const BorderAllType = {
|
||||
currentSheetIndex: "0",
|
||||
config: {
|
||||
borderInfo: null,
|
||||
},
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "0",
|
||||
data: [
|
||||
[null, null],
|
||||
[null, null],
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
describe("BorderStyles", () => {
|
||||
it("border-top", async () => {
|
||||
handleBorder(BorderAllType, "border-top");
|
||||
expect(BorderAllType.config.borderInfo[0].borderType).toEqual("border-top");
|
||||
});
|
||||
it("border-bottom", async () => {
|
||||
handleBorder(BorderAllType, "border-bottom");
|
||||
expect(BorderAllType.config.borderInfo[1].borderType).toEqual(
|
||||
"border-bottom"
|
||||
);
|
||||
});
|
||||
it("border-left", async () => {
|
||||
handleBorder(BorderAllType, "border-left");
|
||||
expect(BorderAllType.config.borderInfo[2].borderType).toEqual(
|
||||
"border-left"
|
||||
);
|
||||
});
|
||||
it("border-right", async () => {
|
||||
handleBorder(BorderAllType, "border-right");
|
||||
expect(BorderAllType.config.borderInfo[3].borderType).toEqual(
|
||||
"border-right"
|
||||
);
|
||||
});
|
||||
it("border-none", async () => {
|
||||
handleBorder(BorderAllType, "border-none");
|
||||
expect(BorderAllType.config.borderInfo[4].borderType).toEqual(
|
||||
"border-none"
|
||||
);
|
||||
});
|
||||
it("border-all", async () => {
|
||||
handleBorder(BorderAllType, "border-all");
|
||||
expect(BorderAllType.config.borderInfo[5].borderType).toEqual("border-all");
|
||||
});
|
||||
it("border-outside", async () => {
|
||||
handleBorder(BorderAllType, "border-none");
|
||||
handleBorder(BorderAllType, "border-outside");
|
||||
expect(BorderAllType.config.borderInfo[7].borderType).toEqual(
|
||||
"border-outside"
|
||||
);
|
||||
});
|
||||
it("border-inside", async () => {
|
||||
handleBorder(BorderAllType, "border-inside");
|
||||
expect(BorderAllType.config.borderInfo[8].borderType).toEqual(
|
||||
"border-inside"
|
||||
);
|
||||
});
|
||||
it("border-horizontal", async () => {
|
||||
handleBorder(BorderAllType, "border-none");
|
||||
handleBorder(BorderAllType, "border-horizontal");
|
||||
expect(BorderAllType.config.borderInfo[10].borderType).toEqual(
|
||||
"border-horizontal"
|
||||
);
|
||||
});
|
||||
it("border-vertical", async () => {
|
||||
handleBorder(BorderAllType, "border-vertical");
|
||||
expect(BorderAllType.config.borderInfo[11].borderType).toEqual(
|
||||
"border-vertical"
|
||||
);
|
||||
});
|
||||
});
|
@ -1,52 +0,0 @@
|
||||
import { handleMerge } from "../toolbar";
|
||||
|
||||
describe("Cells", () => {
|
||||
const MergeAllContext = {
|
||||
config: {},
|
||||
luckysheetfile: [
|
||||
{
|
||||
index: "0",
|
||||
data: [
|
||||
[
|
||||
{
|
||||
v: "hello",
|
||||
},
|
||||
null,
|
||||
],
|
||||
[null, null],
|
||||
],
|
||||
},
|
||||
],
|
||||
currentSheetIndex: "0",
|
||||
luckysheet_select_save: [
|
||||
{
|
||||
left: 0,
|
||||
width: 73,
|
||||
top: 0,
|
||||
height: 19,
|
||||
left_move: 0,
|
||||
width_move: 147,
|
||||
top_move: 0,
|
||||
height_move: 39,
|
||||
row: [0, 1],
|
||||
column: [0, 1],
|
||||
row_focus: 0,
|
||||
column_focus: 0,
|
||||
},
|
||||
],
|
||||
};
|
||||
it("MergeAllCell", async () => {
|
||||
handleMerge(MergeAllContext, "merge-all");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][1].mc.r).toEqual(0);
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][1].mc.c).toEqual(0);
|
||||
handleMerge(MergeAllContext, "merge-cancel");
|
||||
handleMerge(MergeAllContext, "merge-vertical");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][1].mc.rs).toEqual(2);
|
||||
handleMerge(MergeAllContext, "merge-cancel");
|
||||
handleMerge(MergeAllContext, "merge-horizontal");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[0][0].v).toEqual("hello");
|
||||
expect(MergeAllContext.luckysheetfile[0].data[1][0].mc.cs).toEqual(2);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user