anbot

f432b40 / test/webui.sh

View file at this commit

diff --git a/test/webui.sh b/test/webui.sh
index f0914e4..fc696c5 100755
--- a/test/webui.sh
+++ b/test/webui.sh
@@ -22,9 +22,20 @@ printf 'nested file\n' >"$scratch/source/sub/file.txt"
 printf 'a\000b\000c' >"$scratch/source/binary.bin"
 git -C "$scratch/source" add .
 git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q -m 'Test <script>alert(1)</script> escaping'
+printf 'second version\n' >"$scratch/source/README.md"
+git -C "$scratch/source" rm -q sub/file.txt
+git -C "$scratch/source" add .
+git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q -m 'Change README and delete nested file'
+printf '<b>bold</b> & "quotes"\n' >"$scratch/source/README.md"
+mkdir "$scratch/source/sub"
+printf 'nested file\n' >"$scratch/source/sub/file.txt"
+git -C "$scratch/source" add .
+git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q -m 'Restore files'
 git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q --allow-empty -m 'Second commit'
 head=$(git -C "$scratch/source" rev-parse HEAD)
 parent=$(git -C "$scratch/source" rev-parse HEAD~1)
+change=$(git -C "$scratch/source" rev-parse HEAD~2)
+root=$(git -C "$scratch/source" rev-parse HEAD~3)
 
 node "$cli" publish --data "$scratch/node" --source "$scratch/source" --branch main --name webui --port "$port" >/dev/null
 node "$cli" serve --data "$scratch/node" --port "$port" >"$scratch/url" &
@@ -52,10 +63,10 @@ cp "$scratch/peer/posts/"* "$scratch/node/posts/"
 if node "$cli" post --data "$scratch/node" --text '   ' >/dev/null 2>&1; then exit 1; fi
 if node "$cli" post --data "$scratch/node" --text 'Bad reply' --reply-to 'invalid' >/dev/null 2>&1; then exit 1; fi
 
-node --input-type=module - "$base" "$head" "$parent" "$author" "$other" "$post" <<'JS'
+node --input-type=module - "$base" "$head" "$parent" "$change" "$root" "$author" "$other" "$post" <<'JS'
 import assert from 'node:assert/strict'
 import http from 'node:http'
-const [, , base, head, parent, author, other, post] = process.argv
+const [, , base, head, parent, change, root, author, other, post] = process.argv
 
 async function get(path) {
   const response = await fetch(base + path)
@@ -117,6 +128,45 @@ const commit = await get(`/commit/${head}`)
 checkHtml(commit)
 assert.match(commit.text, new RegExp(head))
 assert.match(commit.text, /Second commit/)
+assert.match(commit.text, /No files changed\./)
+
+const changePage = await get(`/commit/${change}`)
+checkHtml(changePage)
+assert.match(changePage.text, /Change README and delete nested file/)
+assert.match(changePage.text, new RegExp(`/commit/${change}/diff/README\\.md">README\\.md</a></td><td>1</td><td>1</td>`))
+assert.match(changePage.text, new RegExp(`/commit/${change}/diff/sub/file\\.txt">sub/file\\.txt</a></td><td>0</td><td>1</td>`))
+
+const diff = await get(`/commit/${change}/diff/README.md`)
+checkHtml(diff)
+assert.match(diff.text, /\+second version/)
+assert.match(diff.text, /-&lt;b&gt;bold&lt;\/b&gt; &amp; &quot;quotes&quot;/)
+assert.match(diff.text, new RegExp(`/commit/${change}/blob/README\\.md`))
+
+const deletedDiff = await get(`/commit/${change}/diff/sub/file.txt`)
+checkHtml(deletedDiff)
+assert.match(deletedDiff.text, /-nested file/)
+assert.doesNotMatch(deletedDiff.text, new RegExp(`/commit/${change}/blob/sub/file\\.txt`))
+
+const rootDiff = await get(`/commit/${root}/diff/README.md`)
+checkHtml(rootDiff)
+assert.match(rootDiff.text, /\+&lt;b&gt;bold&lt;\/b&gt;/)
+
+const oldBlob = await get(`/commit/${root}/blob/README.md`)
+checkHtml(oldBlob)
+assert.match(oldBlob.text, /&lt;b&gt;bold&lt;\/b&gt;/)
+assert.doesNotMatch(oldBlob.text, /second version/)
+
+const changeBlob = await get(`/commit/${change}/blob/README.md`)
+checkHtml(changeBlob)
+assert.match(changeBlob.text, /second version/)
+assert.doesNotMatch(changeBlob.text, /&lt;b&gt;/)
+
+assert.equal((await get(`/commit/${head}/diff/README.md`)).status, 404)
+assert.equal((await get(`/commit/${change}/diff/nope.txt`)).status, 404)
+assert.equal((await get(`/commit/${change}/blob/nope.txt`)).status, 404)
+assert.equal((await get(`/commit/${change}/blob/sub/file.txt`)).status, 404)
+assert.equal((await get('/commit/0000000000000000000000000000000000000000/diff/README.md')).status, 404)
+assert.equal((await getRaw(`/commit/${change}/diff/%2e%2e%2fREADME.md`)).status, 404)
 
 assert.equal((await get('/blob/nope.txt')).status, 404)
 assert.equal((await get('/tree/nope')).status, 404)

Git ยท Social feed