mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
LibTest+Spreadsheet: Add some basic spreadsheet runtime behaviour tests
As there's a somewhat active development going on, let's keep the expected behaviour under tests to make sure nothing blows up :^)
This commit is contained in:
parent
0fe97cdfe4
commit
bed129a69f
13 changed files with 578 additions and 12 deletions
97
Userland/Applications/Spreadsheet/Tests/basic.js
Normal file
97
Userland/Applications/Spreadsheet/Tests/basic.js
Normal file
|
@ -0,0 +1,97 @@
|
|||
describe("Position", () => {
|
||||
test("here", () => {
|
||||
const workbook = createWorkbook();
|
||||
const sheet = createSheet(workbook, "Sheet 1");
|
||||
sheet.makeCurrent();
|
||||
|
||||
sheet.setCell("A", 0, "0");
|
||||
sheet.focusCell("A", 0);
|
||||
|
||||
expect(here).toBeDefined();
|
||||
let position = here();
|
||||
expect(position).toBeDefined();
|
||||
|
||||
expect(position.column).toEqual("A");
|
||||
expect(position.name).toEqual("A0");
|
||||
expect(position.row).toEqual(0);
|
||||
expect(position.sheet).toBe(sheet);
|
||||
|
||||
expect(position.contents).toEqual("0");
|
||||
expect(position.value()).toEqual("0");
|
||||
expect(position.toString()).toEqual("<Cell at A0>");
|
||||
|
||||
position.contents = "=1 + 1";
|
||||
expect(position.contents).toEqual("=1 + 1");
|
||||
expect(position.value()).toEqual(2);
|
||||
|
||||
expect(position.up().row).toEqual(0);
|
||||
expect(position.down().row).toEqual(1);
|
||||
expect(position.right().row).toEqual(0);
|
||||
expect(position.left().row).toEqual(0);
|
||||
|
||||
sheet.addColumn("B");
|
||||
expect(position.up().column).toEqual("A");
|
||||
expect(position.down().column).toEqual("A");
|
||||
expect(position.right().column).toEqual("B");
|
||||
expect(position.left().column).toEqual("A");
|
||||
});
|
||||
|
||||
test("Position.from_name", () => {
|
||||
const workbook = createWorkbook();
|
||||
const sheet = createSheet(workbook, "Sheet 1");
|
||||
sheet.makeCurrent();
|
||||
|
||||
sheet.setCell("A", 0, "0");
|
||||
sheet.focusCell("A", 0);
|
||||
|
||||
expect(Position.from_name).toBeDefined();
|
||||
let position = Position.from_name("A0");
|
||||
expect(position).toBeInstanceOf(Position);
|
||||
|
||||
position = Position.from_name("A123");
|
||||
expect(position).toBeInstanceOf(Position);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Range", () => {
|
||||
test("simple", () => {
|
||||
const workbook = createWorkbook();
|
||||
const sheet = createSheet(workbook, "Sheet 1");
|
||||
sheet.makeCurrent();
|
||||
|
||||
sheet.setCell("A", 0, "0");
|
||||
sheet.setCell("A", 10, "0");
|
||||
sheet.setCell("B", 1, "0");
|
||||
sheet.focusCell("A", 0);
|
||||
|
||||
expect(R).toBeDefined();
|
||||
let cellsVisited = 0;
|
||||
R`A0:A10`.forEach(name => {
|
||||
++cellsVisited;
|
||||
});
|
||||
expect(cellsVisited).toEqual(11);
|
||||
|
||||
cellsVisited = 0;
|
||||
R`A0:A10:1:2`.forEach(name => {
|
||||
++cellsVisited;
|
||||
});
|
||||
expect(cellsVisited).toEqual(6);
|
||||
});
|
||||
|
||||
test("Ranges", () => {
|
||||
const workbook = createWorkbook();
|
||||
const sheet = createSheet(workbook, "Sheet 1");
|
||||
sheet.makeCurrent();
|
||||
|
||||
sheet.setCell("A", 0, "0");
|
||||
sheet.setCell("A", 10, "0");
|
||||
sheet.setCell("B", 1, "0");
|
||||
sheet.focusCell("A", 0);
|
||||
|
||||
let cellsVisited = 0;
|
||||
R`A0:A5`.union(R`A6:A10`).forEach(name => {
|
||||
++cellsVisited;
|
||||
});
|
||||
expect(cellsVisited).toEqual(11);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue