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 #5120

Task: 4276968
X-original-commit: 6629664
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
Signed-off-by: Adrien Minne (adrm) <[email protected]>
  • Loading branch information
hokolomopo committed Oct 23, 2024
1 parent 7e88bec commit a36121f
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions tests/renderer_store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,42 +1306,34 @@ 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 { drawGridRenderer, model, gridRendererStore } = setRenderer(
new Model({
sheets: [
{ id: "sheet1", colNumber: 3, rowNumber: 3, cells: { B2: { content: cellContent } } },
],
})
);
const cellContent = "This is a long text larger than a cell";

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

for (const border of borders) {
setZoneBorders(model, { position: border as BorderPosition }, ["B2"]);
}

let ctx = new MockGridRenderingContext(model, 1000, 1000, {});
drawGridRenderer(ctx);
const { drawGridRenderer, gridRendererStore } = setRenderer(model);

const box = getBoxFromText(gridRendererStore, 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, {});
drawGridRenderer(ctx);
const box = getBoxFromText(gridRendererStore, 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 a36121f

Please sign in to comment.