From a36121f66ce0aba9e604bed58d3433a4857bcf51 Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Tue, 22 Oct 2024 11:45:19 +0000 Subject: [PATCH] [FIX] test: skipped test in `renderer_plugin.test.ts` 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 odoo/o-spreadsheet#5120 Task: 4276968 X-original-commit: 6629664068a80815baa73788602d1b9cb160d32f Signed-off-by: Pierre Rousseau (pro) Signed-off-by: Adrien Minne (adrm) --- tests/renderer_store.test.ts | 58 ++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/tests/renderer_store.test.ts b/tests/renderer_store.test.ts index 448d1f69b2..b0b41e5f09 100644 --- a/tests/renderer_store.test.ts +++ b/tests/renderer_store.test.ts @@ -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([