blob: e3cb08d48ab7c437bbb6f49e401d5da224ae5af0 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh

# Guards the hooks the README promises a site stylesheet or script, so a
# rename in the markup fails here instead of in someone's theme. Each check
# names the page it renders and the attribute or element it expects.

test_description='Check the markup hooks a theme relies on'
. ./setup.sh

test_expect_success 'set up a repository with a file that has an extension' '
	mkrepo repos/hooks 2 &&
	(
		cd repos/hooks &&
		mkdir dir &&
		echo "int x;" >dir/hello.c &&
		git add dir &&
		git commit -m sources
	) &&
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "enable-blame=1" &&
		echo "max-stats=year" &&
		echo "readme=:file-1" &&
		echo "repo.url=hooks" &&
		echo "repo.path=$PWD/repos/hooks/.git"
	} >hooksrc
'

hooks() { CGIT_CONFIG="$PWD/hooksrc" QUERY_STRING="url=$1" cgit; }

test_expect_success 'the root names the page and the repository' '
	hooks "" >tmp &&
	grep "<div id=.cgit. data-page=.repolist.>" tmp &&
	hooks "hooks/log/" >tmp &&
	grep "<div id=.cgit. data-page=.log. data-repo=.hooks.>" tmp
'

test_expect_success 'the landmarks and the search form are in place' '
	grep "<header id=.header.>" tmp &&
	grep "<nav class=.tabs. aria-label=.Pages.>" tmp &&
	grep "<form class=.search. role=.search." tmp &&
	grep "<main class=.content.>" tmp &&
	grep "<footer class=.footer.>" tmp
'

test_expect_success 'the listings name themselves, their sections and their rows' '
	grep "<table class=.list log. aria-label=.Commits.>" tmp &&
	grep "<tbody class=.log.>" tmp &&
	grep "<tr class=.commit.>" tmp &&
	grep "class=.active. aria-current=.page." tmp &&
	grep "<th class=.left. scope=.col.>" tmp &&
	hooks "" >tmp &&
	grep "<table class=.list repolist. aria-label=.Repositories.>" tmp &&
	grep "<tbody class=.repos.>" tmp &&
	grep "<tr class=.repo.>" tmp &&
	hooks "hooks/" >tmp &&
	grep "<table class=.list summary. aria-label=.Summary.>" tmp &&
	grep "<tbody class=.branches.>" tmp &&
	grep "<tr class=.branch.>" tmp &&
	hooks "hooks/tree/" >tmp &&
	grep "<table class=.list tree. aria-label=.Files.>" tmp &&
	grep "<tr class=.dir.>" tmp &&
	grep "<tr class=.blob.>" tmp &&
	hooks "hooks/tree/dir/" >tmp &&
	grep "class=.ls-blob ext-c." tmp
'

test_expect_success 'the diff pages wrap each file and label their controls' '
	hooks "hooks/commit/" >tmp &&
	grep "<table class=.commit-info.>" tmp &&
	grep "<th scope=.row.>author</th>" tmp &&
	grep "<div class=.file. data-path=.dir/hello.c.>" tmp &&
	grep "<label for=.diff-context.>" tmp &&
	grep "<select id=.diff-context. name=.context.>" tmp &&
	grep "<form method=.get. aria-label=.Diff options.>" tmp &&
	hooks "hooks/diff/&ss=1" >tmp &&
	grep "<tbody class=.file. data-path=.dir/hello.c.>" tmp &&
	hooks "hooks/stats/" >tmp &&
	grep "<label for=.stats-authors.>" tmp
'

test_expect_success 'the blob, blame and about pages open with their own containers' '
	hooks "hooks/tree/dir/hello.c" >tmp &&
	grep "<div class=.blob-header.>" tmp &&
	grep "<a id=.n1." tmp &&
	hooks "hooks/blame/dir/hello.c" >tmp &&
	grep "<div class=.blob-header.>" tmp &&
	hooks "hooks/about/" >tmp &&
	grep "<div id=.about.>" tmp
'

test_expect_success 'the stylesheet and the script name only the current hooks' '
	! grep "_dark\|#summary\|ul.pager\|td:empty" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
	grep "window.cgit.updateAges" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" &&
	grep "window.cgit.highlightLines" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
'

# The rest of the hooks need a tag, a symlink, a submodule, a trailer, clone
# urls, an empty repository and a second page of repositories, so they get a
# commit and a config of their own after the checks above have read the first
# ones.
test_expect_success 'set up the remaining kinds of entry' '
	(
		cd repos/hooks &&
		git tag -a -m "first release" v1 &&
		test_ln_s_add file-1 link &&
		git update-index --add --cacheinfo "160000,$(git rev-parse HEAD),sub" &&
		git commit -m "more kinds of entry" -m "Fixes: $(git rev-parse --short HEAD)"
	) &&
	git init -q --bare repos/empty.git &&
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "enable-commit-trailers=1" &&
		echo "max-repo-count=1" &&
		echo "clone-url=https://example.com/clone.git" &&
		echo "repo.url=hooks" &&
		echo "repo.path=$PWD/repos/hooks/.git" &&
		echo "repo.url=again" &&
		echo "repo.path=$PWD/repos/hooks/.git" &&
		echo "repo.url=empty" &&
		echo "repo.path=$PWD/repos/empty.git"
	} >morerc
'

more() { CGIT_CONFIG="$PWD/morerc" QUERY_STRING="url=$1" cgit; }

test_expect_success 'the refs, summary and tree name every section and row' '
	more "hooks/refs/" >tmp &&
	grep "<table class=.list refs. aria-label=.Branches and tags.>" tmp &&
	grep "<tbody class=.tags.>" tmp &&
	grep "<tr class=.tag.>" tmp &&
	more "hooks/" >tmp &&
	grep "<tbody class=.clone.>" tmp &&
	more "hooks/tree/" >tmp &&
	grep "<tbody class=.tree.>" tmp &&
	grep "<tr class=.link.>" tmp &&
	grep "<tr class=.mod.>" tmp
'

test_expect_success 'the commit page has its trailer table and diffstat' '
	more "hooks/commit/" >tmp &&
	grep "<table class=.commit-trailers.>" tmp &&
	grep "<table class=.diffstat.>" tmp
'

test_expect_success 'the breadcrumb, the pager and the ages carry their hooks' '
	more "hooks/tree/dir/" >tmp &&
	grep "<nav class=.path. aria-label=.breadcrumb.>" tmp &&
	more "" >tmp &&
	grep "<nav class=.pager. aria-label=.Pager.>" tmp &&
	grep "class=.current. aria-current=.page." tmp &&
	grep "<time class=.age-[a-z]*. datetime=.[^ ]* data-ut=.[0-9]*." tmp
'

test_expect_success 'a date shown in full is a plain time element' '
	{
		echo "enable-relative-dates=0" &&
		cat morerc
	} >fullrc &&
	CGIT_CONFIG="$PWD/fullrc" QUERY_STRING="url=" cgit >tmp &&
	grep "<time datetime=" tmp &&
	! grep "data-ut=" tmp
'

test_expect_success 'an empty repository lists its clone urls as a clone table' '
	more "empty/" >tmp &&
	grep "<table class=.list clone. aria-label=.Clone urls.>" tmp &&
	grep "<tbody class=.clone.>" tmp
'

test_expect_success 'embedded mode marks the root' '
	{
		echo "embedded=1" &&
		cat hooksrc
	} >embeddedrc &&
	CGIT_CONFIG="$PWD/embeddedrc" QUERY_STRING="url=hooks/" cgit >tmp &&
	grep "<div id=.cgit. class=.cgit-embedded. data-page=.summary." tmp
'

test_done