blob: 2ada672768a2cc677e7372aa4161f12419dfac04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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</a>" 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</a>" tmp
'

test_expect_success 'stats page renders both sections' '
	statq "url=stat/stats/" >tmp &&
	grep "<h2>Languages" tmp &&
	grep "<h2>Commits per author" tmp
'

test_expect_success 'stat options sit above the content' '
	tr -d "\n" <tmp | sed "s/<h2>Commits per author.*//" | grep "cgit-panel"
'

test_expect_success 'extensionless fixture files fold into Other' '
	grep "<th>Language</th><th>Size</th><th>Share</th>" tmp &&
	grep "class=.left.>Other" tmp
'

test_expect_success 'all four periods offered when max-stats is unset' '
	statq "url=stat/stats/" >tmp &&
	grep "<option value=.w." tmp &&
	grep "<option value=.m." tmp &&
	grep "<option value=.q." tmp &&
	grep "<option value=.y." tmp
'

test_expect_success 'max-stats bounds the selectable periods' '
	CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/&period=y" cgit >tmp &&
	grep "Statistics type disabled" tmp &&
	CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/" cgit >tmp &&
	! grep "<option value=.q." tmp
'

test_done