blob: 2e49ed840a86a7ebcd17480cd07084434c5d6f39 (plain) (blame)
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
#!/bin/sh

# The index page, one row per repository in cgitrc. The checks look for each
# fixture repository and its description, for the escaping a name with a
# plus or a space needs in a link, and for the absence of the tree and log
# links that belong to a repository's own pages unless enable-index-links
# asks for them. The page's head also stands in for every page's, with one
# link per css and js entry.

test_description='Check content on index page'
. ./setup.sh

test_expect_success 'generate index page' 'cgit_url "" >tmp'
test_expect_success 'find foo repo' 'grep ">foo</a>" tmp'
test_expect_success 'find foo description' 'grep "\[no description\]" tmp'
test_expect_success 'find bar repo' 'grep ">bar</a>" tmp'
test_expect_success 'find bar description' 'grep "the bar repo" tmp'
test_expect_success 'find foo+bar repo' 'grep ">foo+bar<" tmp'
test_expect_success 'verify foo+bar links' 'test $(grep -o "href=./foo%2Bbar/." tmp | wc -l) = 2'
test_expect_success 'verify "with%20space" links' 'test $(grep -o "href=./with%20space/." tmp | wc -l) = 2'
test_expect_success 'no tree-link' '! grep "foo/tree" tmp'
test_expect_success 'no log-link' '! grep "foo/log" tmp'

test_expect_success 'index links lead to the summary, log and tree' '
	cgitrc_copy links-cgitrc enable-index-links=1 &&
	cgit_rc links-cgitrc "url=" >tmp &&
	grep ">summary</a><a class=.button. href=./foo/log/.>log</a>" tmp &&
	grep "href=./foo/log/.>log</a><a class=.button. href=./foo/tree/.>tree<" tmp
'

test_expect_success 'each css and js entry gets a link of its own' '
	cgitrc_copy headrc css=/a.css css=/b.css js=/a.js js= js=/b.js &&
	cgit_rc headrc "url=" >tmp &&
	grep "<link rel=.stylesheet. href=./a.css.>" tmp &&
	grep "<link rel=.stylesheet. href=./b.css.>" tmp &&
	grep "<script src=" tmp >scripts &&
	test_line_count = 2 scripts &&
	grep "/a.js" scripts &&
	grep "/b.js" scripts
'

# The description limit counts bytes, so a cut has to land between
# characters rather than leave half of one on the page.
test_expect_success 'a cut description keeps whole characters' '
	{
		echo "max-repodesc-length=10" &&
		sed "s/^cache-size=.*/cache-size=0/" cgitrc &&
		echo "repo.url=mb" &&
		echo "repo.path=$PWD/repos/foo/.git" &&
		echo "repo.desc=日本語の説明文です"
	} >descrc &&
	cgit_rc descrc "url=" >tmp &&
	grep ">日本語\.\.\.</a>" tmp
'

# The index sorts by a column only when asked, which nothing else exercises.
test_expect_success 'the index sorts by a column on request' '
	cgit_query "s=name" >tmp &&
	bar=$(grep -n ">bar</a>" tmp | head -1 | cut -d: -f1) &&
	foo=$(grep -n ">foo</a>" tmp | head -1 | cut -d: -f1) &&
	test "$bar" -lt "$foo" &&
	for s in desc owner idle
	do
		cgit_query "s=$s" >tmp &&
		grep ">foo</a>" tmp || return 1
	done
'

test_done