From 0959c6740b457e968d7b6f256458cd7ebfed234d Mon Sep 17 00:00:00 2001 From: Shinuwa Date: Tue, 29 Sep 2026 15:18:35 +0200 Subject: [PATCH] Refine the calculator result layout --- e2e/calculator.spec.js | 4 +++ e2e/style-layouts.spec.js | 14 +++++++-- .../toolboxes/modules/CalculatorModule.jsx | 10 ++++--- .../styles/toolboxes/_calculator-results.scss | 30 +++++++++++++++++-- website/src/styles/toolboxes/_calculator.scss | 14 +++++++-- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/e2e/calculator.spec.js b/e2e/calculator.spec.js index 4bbe59f..b82ba35 100644 --- a/e2e/calculator.spec.js +++ b/e2e/calculator.spec.js @@ -67,6 +67,9 @@ test("current values are subtracted from totals and kept during recalculation", await expect(subtractCurrent).toHaveAttribute("aria-pressed", "true"); await expect(current).toBeFocused(); await expect(totalLabel).toBeVisible(); + await expect(tool.locator(".calculator-result-field")).toHaveClass(/has-current/); + await expect(tool.locator(".calculator-result").getByText("Résultat", { exact: true })).toHaveCount(0); + await expect(tool.locator(".calculator-result-field > span")).toHaveText("Résultat"); const expressionBounds = await expression.boundingBox(); const currentBounds = await current.boundingBox(); expect(currentBounds.x).toBeCloseTo(expressionBounds.x, 0); @@ -94,6 +97,7 @@ test("current values are subtracted from totals and kept during recalculation", await expect(tool.locator(".calculator-result strong")).toHaveAttribute("aria-label", "160"); await subtractCurrent.click(); await expect(current).toHaveCount(0); + await expect(tool.locator(".calculator-result-field")).not.toHaveClass(/has-current/); await expect(tool.locator(".calculator-result strong")).toHaveAttribute("aria-label", "180"); }); diff --git a/e2e/style-layouts.spec.js b/e2e/style-layouts.spec.js index 7dc8ffe..d687f75 100644 --- a/e2e/style-layouts.spec.js +++ b/e2e/style-layouts.spec.js @@ -9,7 +9,7 @@ async function columns(locator, count) { test("calculator layout follows the tool width rather than its location", async ({ page }) => { await page.setViewportSize({ width: 1280, height: 900 }); - await mountStyles(page, `
Formula
Current
Result
Entries
`); + await mountStyles(page, `
Formula
Current
Result
12
Entries
`); const tool = page.locator('[data-module-type="calculator"]'); const calculator = tool.locator(".calculator-module"); const card = tool.locator(".calculator-card"); @@ -20,9 +20,19 @@ test("calculator layout follows the tool width rather than its location", async await columns(calculator, 1); await columns(card, 2); await expect(tool.locator(".calculator-field")).toHaveCSS("grid-column-start", "1"); - await expect(tool.locator(".calculator-result")).toHaveCSS("grid-column-start", "2"); + await expect(tool.locator(".calculator-result-field")).toHaveCSS("grid-column-start", "2"); + await expect(tool.locator(".calculator-result")).toHaveCSS("height", "36px"); + await expect(tool.locator(".calculator-result")).toHaveCSS("min-height", "36px"); + const resultValue = tool.locator(".calculator-result strong"); + const compactResultFontSize = Number.parseFloat(await computed(resultValue, "font-size")); + await expect(tool.locator(".calculator-result")).toHaveCSS("padding-top", "7px"); + await tool.locator(".calculator-result-field").evaluate((element) => { element.classList.add("has-current"); }); + await expect.poll(async () => Number.parseFloat(await computed(tool.locator(".calculator-result"), "height"))).toBeGreaterThan(36); + await expect.poll(async () => Number.parseFloat(await computed(resultValue, "font-size"))).toBeGreaterThan(compactResultFontSize); + await expect(tool.locator(".calculator-result")).toHaveCSS("padding-top", "12px"); await tool.evaluate((element) => { element.style.width = "480px"; }); await columns(card, 1); + await expect(tool.locator(".calculator-result")).toHaveCSS("min-height", "72px"); }); for (const width of [1280, 900, 390]) { diff --git a/website/src/features/toolboxes/modules/CalculatorModule.jsx b/website/src/features/toolboxes/modules/CalculatorModule.jsx index 4afb250..a3fd6a8 100644 --- a/website/src/features/toolboxes/modules/CalculatorModule.jsx +++ b/website/src/features/toolboxes/modules/CalculatorModule.jsx @@ -306,11 +306,13 @@ export function CalculatorModule({ toolboxId, moduleId, context, textExchangeOpe /> )} -
+
{textContent.resultLabel || "Résultat"} - - - +
+ + + +