Diff options
Diffstat (limited to '')
-rwxr-xr-xtests/t0005-markup.sh104
1 file changed, 50 insertions, 54 deletions
diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh
index 5fa866d..a6dd028 100755
--- a/tests/t0005-markup.sh
+++ b/tests/t0005-markup.sh
@@ -5,6 +5,7 @@
# names the page it renders and the attribute or element it expects.
test_description='Check the markup hooks a theme relies on'
+CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
test_expect_success 'set up a repository with a file that has an extension' '
@@ -16,23 +17,13 @@ test_expect_success 'set up a repository with a file that has an extension' '
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
+ cgitrc_repo hooksrc hooks enable-blame=1 max-stats=year readme=:file-1
'
-hooks() { CGIT_CONFIG="$PWD/hooksrc" QUERY_STRING="url=$1" cgit; }
-
test_expect_success 'the root names the page and the repository' '
- hooks "" >tmp &&
+ cgit_rc hooksrc "url=" >tmp &&
grep "<div id=.cgit. data-page=.repolist.>" tmp &&
- hooks "hooks/log/" >tmp &&
+ cgit_rc hooksrc "url=hooks/log/" >tmp &&
grep "<div id=.cgit. data-page=.log. data-repo=.hooks.>" tmp
'
@@ -45,14 +36,14 @@ test_expect_success 'the landmarks and the search form are in place' '
'
test_expect_success 'the pages name the versions only when asked to' '
- hooks "hooks/" >footer &&
+ cgit_rc hooksrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit.>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit</a></footer>" footer &&
{
echo "enable-version-info=1" &&
cat hooksrc
} >versionrc &&
- CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer &&
+ cgit_rc versionrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit v[0-9][^>]*>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit v[0-9][^<]*</a> (<a href=[^>]*>git [0-9][^<]*</a>)</footer>" footer &&
echo "<footer>our own</footer>" >footer.html &&
@@ -61,7 +52,7 @@ test_expect_success 'the pages name the versions only when asked to' '
echo "footer=$PWD/footer.html" &&
cat hooksrc
} >versionrc &&
- CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer &&
+ cgit_rc versionrc "url=hooks/" >footer &&
grep "<footer>our own</footer>" footer &&
! grep "git-scm" footer
'
@@ -72,58 +63,58 @@ test_expect_success 'the listings name themselves, their sections and their rows
grep "<tr class=.commit.>" tmp &&
grep "class=.active. aria-current=.page." tmp &&
grep "<th class=.left. scope=.col.>" tmp &&
- hooks "" >tmp &&
+ cgit_rc hooksrc "url=" >tmp &&
grep "<table class=.list repolist. aria-label=.Repositories.>" tmp &&
grep "<tbody class=.repos.>" tmp &&
grep "<tr class=.repo.>" tmp &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=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 &&
+ cgit_rc hooksrc "url=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 &&
+ cgit_rc hooksrc "url=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 &&
+ cgit_rc hooksrc "url=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.>context</label>" tmp &&
grep "<select id=.diff-context. name=.context.>" tmp &&
grep "<form method=.get. aria-label=.Diff options.>" tmp &&
- hooks "hooks/diff/&ss=1" >tmp &&
+ cgit_rc hooksrc "url=hooks/diff/&ss=1" >tmp &&
grep "<tbody class=.file. data-path=.dir/hello.c.>" tmp &&
- hooks "hooks/stats/" >tmp &&
+ cgit_rc hooksrc "url=hooks/stats/" >tmp &&
grep "<label for=.stats-authors.>authors</label>" tmp
'
test_expect_success 'the blob, blame and about pages open with their own containers' '
- hooks "hooks/tree/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
grep "<a id=.n1." tmp &&
- hooks "hooks/blame/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
- hooks "hooks/about/" >tmp &&
+ cgit_rc hooksrc "url=hooks/about/" >tmp &&
grep "<div id=.about.>" tmp
'
test_expect_success 'each page names itself, then the repository and the site' '
site="Git repository browser" &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<title>hooks - $site</title>" tmp &&
for page in about log refs tree stats
do
- hooks "hooks/$page/" >tmp &&
+ cgit_rc hooksrc "url=hooks/$page/" >tmp &&
grep "<title>$page - hooks - $site</title>" tmp || return 1
done &&
- hooks "hooks/tree/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<title>hello.c &lt; dir - hooks - $site</title>" tmp &&
- hooks "hooks/blame/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<title>blame - hello.c &lt; dir - hooks - $site</title>" tmp
'
@@ -150,7 +141,7 @@ test_expect_success 'the page background is the same everywhere it is set' '
test_line_count = 1 expect &&
sed -n "/^html.cgit-standalone {\$/,/^}/s/^ background: light-dark(\(#[0-9a-f]*\), \(#[0-9a-f]*\));\$/\1 \2/p" "$css" >actual &&
test_cmp expect actual &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
light=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: light). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
dark=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: dark). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
echo "$light $dark" >actual &&
@@ -158,21 +149,33 @@ test_expect_success 'the page background is the same everywhere it is set' '
'
test_expect_success 'the script waits for the page instead of holding it up' '
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<script src=./cgit.js. defer></script>" tmp
'
-# The rest of the hooks need a tag, a symlink, a submodule, a trailer, a lone
-# carriage return, 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.
+# A collection from getElementsByClassName is live, so an age the loop moves to
+# another unit drops out of it at once and the age after it is skipped.
+test_expect_success 'the script walks the ages from a list that holds still' '
+ ! grep "getElementsByClassName" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
+'
+
+# The line anchors carry a scroll margin of half the window, which centres a
+# line scrolled to the top of the view. Asking scrollIntoView to centre it as
+# well centres the margin too and drops a range three quarters of the way down.
+test_expect_success 'a line range scrolls where a single line does' '
+ grep "^ scroll-margin-top: calc(50vh - 1em);$" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
+ grep "first.scrollIntoView();" "$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 &&
- printf "a\\rb\\n" >cr.txt &&
- git add cr.txt &&
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)"
) &&
@@ -192,36 +195,29 @@ test_expect_success 'set up the remaining kinds of entry' '
} >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 &&
+ cgit_rc morerc "url=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 &&
+ cgit_rc morerc "url=hooks/" >tmp &&
grep "<tbody class=.clone.>" tmp &&
- more "hooks/tree/" >tmp &&
+ cgit_rc morerc "url=hooks/tree/" >tmp &&
grep "<tbody class=.tree.>" tmp &&
grep "<tr class=.link.>" tmp &&
grep "<tr class=.mod.>" tmp
'
-test_expect_success 'a character the browser would break a line at is an escape' '
- more "hooks/tree/cr.txt" >tmp &&
- grep "a<span class=.escape.>" tmp
-'
-
test_expect_success 'the commit page has its trailer table and diffstat' '
- more "hooks/commit/" >tmp &&
+ cgit_rc morerc "url=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 &&
+ cgit_rc morerc "url=hooks/tree/dir/" >tmp &&
grep "<nav class=.path. aria-label=.breadcrumb.>" tmp &&
- more "" >tmp &&
+ cgit_rc morerc "url=" >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
@@ -232,13 +228,13 @@ 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 &&
+ cgit_rc fullrc "url=" >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 &&
+ cgit_rc morerc "url=empty/" >tmp &&
grep "<table class=.list clone. aria-label=.Clone urls.>" tmp &&
grep "<tbody class=.clone.>" tmp
'
@@ -248,7 +244,7 @@ test_expect_success 'embedded mode marks the root' '
echo "embedded=1" &&
cat hooksrc
} >embeddedrc &&
- CGIT_CONFIG="$PWD/embeddedrc" QUERY_STRING="url=hooks/" cgit >tmp &&
+ cgit_rc embeddedrc "url=hooks/" >tmp &&
grep "<div id=.cgit. class=.cgit-embedded. data-page=.summary." tmp
'