From ea618c5e257a6aabded76e63567ec0e7b99ac6c4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Mon, 24 Aug 2026 16:21:18 -1000 Subject: Renumber the test scripts into themed ranges t000x the ground the suite stands on: git version, html validity, the cache t01xx page content, one script per page t02xx features that cut across pages: filters, submodule links, dates, limits t03xx defence, the security regressions and the $HOME promise t04xx the helper tools under tools/ --- tests/t0112-stats.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 tests/t0112-stats.sh (limited to 'tests/t0112-stats.sh') diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh new file mode 100755 index 0000000..2ada672 --- /dev/null +++ b/tests/t0112-stats.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +# Checks the per repository statistics page, which stays off until a config +# turns it on and then reports commits per author beside a breakdown of the +# tree by language. A second config caps the period so that what max-stats +# takes out of the period selector is covered as well. + +test_description='Check the statistics page' +. ./setup.sh + +# The shared test config sets no enable-stats, so this is what an untouched +# install does. +test_expect_success 'stats are off by default' ' + cgit_url "foo/stats" >tmp && + grep "Status: 404" tmp && + cgit_url "foo" >tmp && + ! grep ">stats" tmp +' + +# The authors table counts only recent periods, so the fixture needs a commit +# dated now to sit beside the 2005 dates the shared repositories carry. The +# commit graph is written on purpose, because it sends the language walk down +# the graph lookup path, which once handed back another commit after the +# history walk had released its memory. +test_expect_success 'set up a stats config' ' + mkrepo repos/pulse 2 && + ( + cd repos/pulse && + GIT_AUTHOR_DATE="@$(date +%s) +0000" \ + GIT_COMMITTER_DATE="@$(date +%s) +0000" \ + git commit --allow-empty -m fresh && + git commit-graph write --reachable + ) && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "enable-stats=1" && + echo "repo.url=stat" && + echo "repo.path=$PWD/repos/pulse/.git" + } >statsrc && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "enable-stats=1" && + echo "max-stats=month" && + echo "repo.url=stat" && + echo "repo.path=$PWD/repos/pulse/.git" + } >statmaxrc +' + +statq() { CGIT_CONFIG="$PWD/statsrc" QUERY_STRING="$1" cgit; } + +test_expect_success 'stats tab appears when enabled' ' + statq "url=stat/" >tmp && + grep ">stats" tmp +' + +test_expect_success 'stats page renders both sections' ' + statq "url=stat/stats/" >tmp && + grep "

Languages" tmp && + grep "

Commits per author" tmp +' + +test_expect_success 'stat options sit above the content' ' + tr -d "\n" Commits per author.*//" | grep "cgit-panel" +' + +test_expect_success 'extensionless fixture files fold into Other' ' + grep "LanguageSizeShare" tmp && + grep "class=.left.>Other" tmp +' + +test_expect_success 'all four periods offered when max-stats is unset' ' + statq "url=stat/stats/" >tmp && + grep "