Skip to content

Commit

Permalink
[FIX] test: skipped test in renderer_plugin.test.ts
Browse files Browse the repository at this point in the history
A test was skipped in `renderer_plugin.test.ts` because it didn't
contain code instructions, but it contained a callback with those
instructions. And the callback was never called.

The test was also wrong: it forgot to add `MIN_CELL_TEXT_MARGIN` to
the width of the text, and to resize the column to make the text
overflow.

closes #5116

Task: 4276968
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
  • Loading branch information
hokolomopo committed Oct 23, 2024
1 parent 8aa4b34 commit 6629664
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions tests/renderer_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,39 +1274,32 @@ describe("renderer", () => {
);

test("Cell overflowing text centered is cut correctly when there's a border", () => {
() => {
const borders = ["right"];
const cellContent = "This is a long text larger than a cell";
const model = new Model({
sheets: [
{ id: "sheet1", colNumber: 3, rowNumber: 3, cells: { B2: { content: cellContent } } },
],
});

setStyle(model, "B2", { align: "center" });
const cellContent = "This is a long text larger than a cell";

for (const border of borders) {
setZoneBorders(model, { position: border as BorderPosition }, ["B2"]);
}
const model = new Model();
resizeColumns(model, ["B"], 10);
setCellContent(model, "B2", cellContent);
setStyle(model, "B2", { align: "center" });
setZoneBorders(model, { position: "right" }, ["B2"]);

let ctx = new MockGridRenderingContext(model, 1000, 1000, {});
model.drawGrid(ctx);
const box = getBoxFromText(model, cellContent);
const cell = getCell(model, "B2")!;
const textWidth = model.getters.getTextWidth(cell.content, cell.style || {});
const expectedClipRect = model.getters.getVisibleRect({
left: 0,
right: 1,
top: 1,
bottom: 1,
});
const expectedCLipX = box.x + box.width / 2 - textWidth / 2;
expect(box.clipRect).toEqual({
...expectedClipRect,
x: expectedCLipX,
width: expectedClipRect.x + expectedClipRect.width - expectedCLipX,
});
};
let ctx = new MockGridRenderingContext(model, 1000, 1000, {});
model.drawGrid(ctx);
const box = getBoxFromText(model, cellContent);
const cell = getCell(model, "B2")!;
const textWidth =
model.getters.getTextWidth(cell.content, cell.style || {}) + MIN_CELL_TEXT_MARGIN;
const expectedClipRect = model.getters.getVisibleRect({
left: 0,
right: 1,
top: 1,
bottom: 1,
});
const expectedCLipX = box.x + box.width / 2 - textWidth / 2;
expect(box.clipRect).toEqual({
...expectedClipRect,
x: expectedCLipX,
width: expectedClipRect.x + expectedClipRect.width - expectedCLipX,
});
});

test.each([
Expand Down

0 comments on commit 6629664

Please sign in to comment.