From dcd8c4feda0832702645c1af18288592159a5112 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:44:08 -1000 Subject: Check the stats columns, periods and path Each period check needed a single heading of the right shape, so a wrong window or column count passed, and the weekly default had no check. A request that straddles midnight is made again rather than failing, since cgit reads the clock for itself and a new day can open a new period. The absence checks gain a presence check on the same page. --- tests/t0112-stats.sh | 168 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 138 insertions(+), 30 deletions(-) diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh index 9bd8b7c..4cf87ae 100755 --- a/tests/t0112-stats.sh +++ b/tests/t0112-stats.sh @@ -12,11 +12,37 @@ test_description='Check the statistics page' # install does. test_expect_success 'stats are off by default' ' cgit_url "foo/stats" >tmp && - grep "Status: 404" tmp && - cgit_url "foo" >tmp && + grep "^Status: 404" tmp && + grep "
Stats are disabled
" tmp && + cgit_ok_url "foo" >tmp && + grep ">log" tmp && ! grep ">stats" tmp ' +# A word that names no period leaves the page off rather than picking one. +test_expect_success 'a max-stats naming no period leaves stats off' ' + cgitrc_repo badrc foo max-stats=decade && + cgit_rc badrc "url=foo/stats/" >tmp && + grep "^Status: 404" tmp && + grep "
Stats are disabled
" tmp +' + +# Asks for a stats page into tmp, and fails when the day turned during the +# request, since cgit reads the clock for itself and a new day can open a new +# period. The day read is left in now as year, month, day, ISO week and its +# year, for the caller to work out the labels from. +stats_today() { + now=$(date -u "+%Y %m %d W%V %G") && + cgit_ok "$@" >tmp && + test "$(date -u "+%Y %m %d W%V %G")" = "$now" +} + +# The column labels of the stats table in tmp, one to a line. +period_labels() { + sed -n "s/^Author<\/th>\(.*\)Total<\/th><\/tr>$/\1/p" tmp | + sed -e "s///g" -e "s/<\/th>/;/g" | tr ";" "\n" | sed "/^$/d" +} + # Makes the given number of empty commits by the named author. author_commits() { i=0 && @@ -58,7 +84,7 @@ test_expect_success 'set up a stats config' ' ' test_expect_success 'stats tab appears when enabled' ' - cgit_rc statsrc "url=stat/" >tmp && + cgit_ok statsrc "url=stat/" >tmp && grep ">stats" tmp ' @@ -93,23 +119,31 @@ test_expect_success 'the authors past the row count share one row' ' ' # The table scrolls sideways on a narrow window with nothing in it a keyboard -# can reach, so the table itself takes focus. +# can reach, so the table itself takes focus, and the focus ring links have. test_expect_success 'the authors table can take keyboard focus' ' - grep "" tmp + cgit_ok statsrc "url=stat/stats/" >tmp && + grep "
" tmp && + sed -n "/^div#cgit a:focus-visible,$/,/^}/p" \ + "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule && + grep "^div#cgit table.stats:focus-visible {$" rule && + grep "^ outline: solid 2px var(--link);$" rule ' test_expect_success 'stat options sit above the content' ' + cgit_ok statsrc "url=stat/stats/" >tmp && tr -d "\n" Commits per author.*//" | grep "cgit-panel" ' -test_expect_success 'stats below a path stay a normal page' ' - cgit_rc statsrc "url=stat/stats/file-1" >tmp && - grep "Status: 200" tmp && - grep "

Commits per author" tmp +# Only Ada touched ada.txt, and in a commit inside the window. +test_expect_success 'stats below a path count that path alone' ' + cgit_ok statsrc "url=stat/stats/ada.txt" >tmp && + grep "

Commits per author per week (path .ada.txt.)

" tmp && + grep "
" tmp && + ! grep ">Gil Seven<" tmp ' test_expect_success 'max-stats=year offers all four periods' ' - cgit_rc statsrc "url=stat/stats/" >tmp && + cgit_ok statsrc "url=stat/stats/" >tmp && grep "
Ada One