#!/bin/sh
# Checks the per repository statistics page, which stays off until max-stats
# turns it on and then reports commits per author. A second config sets a
# finer max-stats so that what it takes out of the period selector is covered
# as well.
test_description='Check the statistics page'
. ./setup.sh
# The shared test config sets no max-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.
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
) &&
cgitrc_repo statsrc stat max-stats=year "repo.path=$PWD/repos/pulse/.git" &&
cgitrc_repo statmaxrc stat max-stats=month "repo.path=$PWD/repos/pulse/.git"
'
test_expect_success 'stats tab appears when enabled' '
cgit_rc statsrc "url=stat/" >tmp &&
grep ">stats" tmp
'
test_expect_success 'stats page renders the authors table' '
cgit_rc statsrc "url=stat/stats/" >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 '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
'
test_expect_success 'max-stats=year offers all four periods' '
cgit_rc statsrc "url=stat/stats/" >tmp &&
grep "