diff --git a/CHANGELOG.md b/CHANGELOG.md index 54c7d24..efecf16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ -# ChangeLog +# ChangeLog --- develop --- +* dev: Keep the status-legend chips equal width (sized to the longest label, laid out as a CSS grid so chips stay equal across wrapped rows) as the legend wraps responsively * dev: Measure CI coverage with xdebug instead of pcov so the plugin's own sources are instrumented (pcov auto-scopes to the Composer root and skipped cacti/plugins/, leaving the patch-coverage gate with nothing to measure) * dev: Enforce patch coverage of changed lines in CI and remove the inert COMPOSER_ROOT_VERSION env from the Pest step * feature: Add a configurable User-Agent setting for HTTP/HTTPS and other cURL based service checks, so outdated-browser blocking no longer rejects the plugin's requests diff --git a/css/common.css b/css/common.css index 14f75ea..44d0951 100644 --- a/css/common.css +++ b/css/common.css @@ -65,21 +65,21 @@ } /* - * Status legend footer. The items are laid out as an evenly sized, wrapping - * flex row (flex: 1 1 0 gives every chip the same width). A legend is a colour - * key, so the chips use their own solid, opaque colours with white text so they - * stay legible on every theme rather than inheriting the subtle row tints. + * Status legend footer. The items are laid out as a wrapping CSS grid whose + * columns share one width (seeded from the longest label via + * --servcheck-chip-min) so every chip is equal width across all rows. A legend + * is a colour key, so the chips use their own solid, opaque colours with white + * text so they stay legible on every theme rather than inheriting the subtle + * row tints. */ .servcheck_legend { - display: flex; - flex-wrap: wrap; + display: grid; + grid-template-columns: repeat(auto-fit, minmax(var(--servcheck-chip-min, 8ch), 1fr)); gap: 4px; width: 100%; } .servcheck_legend .servcheck_legend_item { - flex: 1 1 0; - min-width: 0; text-align: center; white-space: nowrap; padding: 4px 6px; diff --git a/includes/functions.php b/includes/functions.php index 66f8ba0..73870d0 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -342,11 +342,17 @@ function servcheck_legend(): void { html_start_box('', '100%', false, 3, 'center', ''); + $chip_min = 0; + + foreach ($servcheck_states as $state) { + $chip_min = max($chip_min, mb_strlen($state)); + } + print ''; - print '
'; + print '
'; foreach ($servcheck_states as $index => $state) { - print '
' . $state . '
'; + print '
' . html_escape($state) . '
'; } print '
'; diff --git a/phpunit.xml b/phpunit.xml index 20c6af8..9b0a582 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -28,6 +28,7 @@ setup.php + includes/functions.php diff --git a/tests/Unit/ServcheckLegendTest.php b/tests/Unit/ServcheckLegendTest.php new file mode 100644 index 0000000..72297a3 --- /dev/null +++ b/tests/Unit/ServcheckLegendTest.php @@ -0,0 +1,60 @@ +toContain('
'); + expect(substr_count($output, 'servcheck_legend_item'))->toBe(count($states)); + + foreach ($states as $index => $state) { + expect($output)->toContain('
' . $state . '
'); + } +}); diff --git a/tests/bootstrap-unit.php b/tests/bootstrap-unit.php index f831bba..6ef38d4 100644 --- a/tests/bootstrap-unit.php +++ b/tests/bootstrap-unit.php @@ -361,6 +361,16 @@ function form_input_validate($value, $name, $regex, $optional, $error) { } } +if (!function_exists('html_start_box')) { + function html_start_box($title = '', $width = '100%', $div = '', $cell_padding = 3, $align = 'center', $add_text = '') { + } +} + +if (!function_exists('html_end_box')) { + function html_end_box($trailing_br = true, $resizable = false) { + } +} + if (!function_exists('is_error_message')) { function is_error_message() { return false;