From b8dacde69578848c98cd36a76493c59e02e1df49 Mon Sep 17 00:00:00 2001 From: nchandra Date: Sat, 25 Jul 2026 15:11:45 +0100 Subject: [PATCH] COLUMN keeps first and last part of description --- .../report/ZeroCodeReportGeneratorImpl.java | 9 ++++-- .../ZeroCodeReportGeneratorImplTest.java | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java b/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java index 32bf4817..b02552f8 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImpl.java @@ -514,8 +514,8 @@ String buildTableReportContent(List rows) { for (ZeroCodeCsvReport row : rows) { String scen = trunc(row.getScenarioName(), SCEN_WIDTH); - String step = pad(row.getStepName(), STEP_WIDTH); - String method = pad(row.getMethod(), METH_WIDTH); + String step = trunc(row.getStepName(), STEP_WIDTH); + String method = trunc(row.getMethod(), METH_WIDTH); boolean isPass = RESULT_PASS.equals(row.getResult()); String resCell = isPass ? "PASSED ✅" : "FAILED ❌"; double delay = row.getResponseDelayMilliSec() != null ? row.getResponseDelayMilliSec() : 0.0; @@ -559,7 +559,10 @@ private static String trunc(String text, int width) { if (text == null) text = ""; text = text.trim(); if (text.length() <= width) return pad(text, width); - return text.substring(0, width - 2) + ".."; + int keep = width - 3; + int head = (keep + 1) / 2; + int tail = keep - head; + return text.substring(0, head) + "..." + text.substring(text.length() - tail); } private static String rpad(double value, int width) { diff --git a/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java b/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java index 3a89f156..739bedd0 100644 --- a/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java +++ b/core/src/test/java/org/jsmart/zerocode/core/report/ZeroCodeReportGeneratorImplTest.java @@ -239,8 +239,32 @@ public void buildTableReport_truncatesLongScenarioAt48Chars() { ); String table = zeroCodeReportGenerator.buildTableReportContent(rows); - // truncated text ends with ".." and is exactly 48 chars (46 base + "..") - assertThat(table, containsString("GIVEN the very long scenario name that exceeds..")); + // truncated text keeps first 23 + "..." + last 22 chars, exactly 48 chars wide + assertThat(table, containsString("GIVEN the very long sce...imit set for the table")); + } + + @Test + public void buildTableReport_truncatesLongStepAt25CharsKeepingFirstAndLastPart() { + String longStep = "verify_the_response_contains_all_expected_fields_correctly"; + List rows = Arrays.asList( + csvRow("Scenario", longStep, "GET", RESULT_PASS, 50.0) + ); + + String table = zeroCodeReportGenerator.buildTableReportContent(rows); + // truncated text keeps first 11 + "..." + last 11 chars, exactly 25 chars wide + assertThat(table, containsString("verify_the_...s_correctly")); + } + + @Test + public void buildTableReport_truncatesLongMethodAt22CharsKeepingFirstAndLastPart() { + String longMethod = "PATCH_WITH_CUSTOM_HEADERS_AND_LONG_NAME"; + List rows = Arrays.asList( + csvRow("Scenario", "step", longMethod, RESULT_PASS, 50.0) + ); + + String table = zeroCodeReportGenerator.buildTableReportContent(rows); + // truncated text keeps first 10 + "..." + last 9 chars, exactly 22 chars wide + assertThat(table, containsString("PATCH_WITH...LONG_NAME")); } @Test