Commit cace3f9d authored by Vojtěch Horký's avatar Vojtěch Horký
Browse files

Tests for final tasks

parent 44135cf3
# CI configuration for individual tasks and quizzes
# Keep CI configuration happy, will be replaced by
# real tests soon
final-tasks-placeholder:
final-gallery:
stage: tests
image: registry.gitlab.com/mffd3s/nswi177/student:latest
when: manual
script:
- ./bin/run_tests.sh
- ./bin/run_tests.sh final/21
final-templater:
stage: tests
image: registry.gitlab.com/mffd3s/nswi177/student:latest
script:
- ./bin/run_tests.sh final/22
final-disk:
stage: tests
image: registry.gitlab.com/mffd3s/nswi177/student:latest
script:
- ./bin/run_tests.sh final/23
<!DOCTYPE html>
<html>
<head>
<title>$title$ | $site.title$</title>
</head>
<body>
<h1>$title$</h1>
<p><a href="../index.html">Back to gallery list</a></p>
$body$
$for(images)$
<p>
<a href="$it.filename$">
<img src="$it.thumbnail$" width="200" height="200">
</a>
$if(it.date_time)$
<br />
$it.date_time$
</p>
$endif$
$endfor$
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>$title$</title>
</head>
<body>
<h1>$title$</h1>
$body$
<ul>
$for(site.albums)$
<li><a href="$it.dir$/index.html">$it.title$</a></li>
$endfor$
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>NSWI177 :: $site.title$ :: $title$</title>
</head>
<body>
<h1>$title$</h1>
<p><a href="../index.html">Back to gallery list</a></p>
$body$
<p>
$for(images)$
<a href="$it.filename$">
<img src="$it.filename$" width="200" height="200">
</a>
$endfor$
</p>
<address>&copy; NSWI177</address>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>NSWI177 :: $title$</title>
</head>
<body>
<h1>$title$</h1>
$body$
<ul>
$for(site.albums)$
<li><a href="$it.dir$/index.html">$it.title$</a></li>
$endfor$
</ul>
<address>&copy; NSWI177</address>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>$title$ | $site.title$</title>
</head>
<body>
<h1>$title$</h1>
<p><a href="../index.html">Back to gallery list</a></p>
$body$
<p>
$for(images)$
<a href="$it.filename$">
<img src="$it.filename$" width="200" height="200">
</a>
$endfor$
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>$title$</title>
</head>
<body>
<h1>$title$</h1>
$body$
<ul>
$for(site.albums)$
<li><a href="$it.dir$/index.html">$it.title$</a></li>
$endfor$
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>$title$ | $site.title$</title>
</head>
<body>
<h1>$title$</h1>
<p><a href="../index.html">Back to gallery list</a></p>
$body$
<p>
$for(images)$
<a href="$it.filename$">
<img src="$it.thumbnail$" width="$it.thumb_width$" height="$it.thumb_height$">
</a>
$endfor$
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>$title$</title>
</head>
<body>
<h1>$title$</h1>
$body$
<ul>
$for(site.albums)$
<li><a href="$it.dir$/index.html">$it.title$</a></li>
$endfor$
</ul>
</body>
</html>
#!/usr/bin/env bats
#> task: 21/gallery.sh
load "../../nswi177"
load "./gallery"
prepare_photos() {
add_photo lima 1.jpg
add_photo lima 2.jpg
add_photo sierra 3.jpg
add_photo sierra 4.jpg
add_photo sierra 5.jpg
}
check_it() {
assert_status 0 \
'stdout' "$output" \
'stderr' "$erroroutput" \
'files' "$( find . )"
assert_photos_copied
}
@test "21/gallery.sh - Custom album title (20)" {
skip_if_missing
prepare simple
prepare_photos
echo 'title="The L album"' >albums/lima/album.rc
run_it
check_it
assert_html index.html '<!DOCTYPE html>
<html>
<head>
<title>My photo gallery</title>
</head>
<body>
<h1>My photo gallery</h1>
<ul>
<li>
<a href="lima/index.html">The L album</a>
</li>
<li>
<a href="sierra/index.html">sierra</a>
</li>
</ul>
</body>
</html>'
assert_html lima/index.html '<!DOCTYPE html>
<html>
<head>
<title>The L album | My photo gallery</title>
</head>
<body>
<h1>The L album</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
assert_html sierra/index.html '<!DOCTYPE html>
<html>
<head>
<title>sierra | My photo gallery</title>
</head>
<body>
<h1>sierra</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000003.jpg">
<img src="00000003.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
}
compare_front_images() {
local actual_image="$1"
local expected_full_image="${NSWI177_TEST_ROOT:?}/data/21/images/$2"
local expected_thumb_image="$3"
if [ -f "$expected_full_image" ]; then
if cmp -s "$actual_image" "$expected_full_image"; then
return 0
fi
fi
if [ -f "$expected_thumb_image" ]; then
if cmp -s "$actual_image" "$expected_thumb_image"; then
return 0
fi
fi
return 1
}
@test "21/gallery.sh - Custom album front image (30)" {
skip_if_missing
prepare simple
prepare_photos
echo 'front_image=4.jpg' >albums/sierra/album.rc
run_it
check_it
assert_html index.html '<!DOCTYPE html>
<html>
<head>
<title>My photo gallery</title>
</head>
<body>
<h1>My photo gallery</h1>
<ul>
<li>
<a href="lima/index.html">lima</a>
</li>
<li>
<a href="sierra/index.html">sierra</a>
</li>
</ul>
</body>
</html>'
assert_html lima/index.html '<!DOCTYPE html>
<html>
<head>
<title>lima | My photo gallery</title>
</head>
<body>
<h1>lima</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
assert_html sierra/index.html '<!DOCTYPE html>
<html>
<head>
<title>sierra | My photo gallery</title>
</head>
<body>
<h1>sierra</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000003.jpg">
<img src="00000003.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
lima_front="$( jq -r .site.albums[0].image < public_html/.meta.json || true )"
if ! compare_front_images "public_html/lima/$lima_front" 1.jpg public_html/lima/thumb.0000001.jpg; then
batslib_print_kv_single_or_multi 8 \
'album' "lima" \
'actual' "$lima_front" \
'want' "original=1.jpg (in-album=00000001.jpg)" \
'fs' "$( find . )" \
| batslib_decorate "Wrong front image for album lima (uses default)" \
| fail
fi
sierra_front="$( jq -r .site.albums[1].image < public_html/.meta.json || true )"
if ! compare_front_images "public_html/sierra/$sierra_front" 4.jpg public_html/lima/thumb.0000002.jpg; then
batslib_print_kv_single_or_multi 8 \
'album' "sierra" \
'actual' "$sierra_front" \
'want' "original=4.jpg (in-album=00000002.jpg)" \
'fs' "$( find . )" \
| batslib_decorate "Wrong front image for album sierra (overriden by user)" \
| fail
fi
}
#!/usr/bin/env bats
#> task: 21/gallery.sh
load "../../nswi177"
load "./gallery"
@test "21/gallery.sh - Base gallery generation (0)" {
skip_if_missing
prepare simple
add_photo 001 1.jpg
add_photo 001 2.jpg
add_photo 002 3.jpg
add_photo 002 4.jpg
add_photo 002 5.jpg
run_it
assert_status 0 \
'stdout' "$output" \
'stderr' "$erroroutput" \
'files' "$( find . )"
assert_photos_copied
assert_html index.html '<!DOCTYPE html>
<html>
<head>
<title>My photo gallery</title>
</head>
<body>
<h1>My photo gallery</h1>
<ul>
<li>
<a href="001/index.html">001</a>
</li>
<li>
<a href="002/index.html">002</a>
</li>
</ul>
</body>
</html>'
assert_html 001/index.html '<!DOCTYPE html>
<html>
<head>
<title>001 | My photo gallery</title>
</head>
<body>
<h1>001</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
assert_html 002/index.html '<!DOCTYPE html>
<html>
<head>
<title>002 | My photo gallery</title>
</head>
<body>
<h1>002</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000003.jpg">
<img src="00000003.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
}
@test "21/gallery.sh - Base gallery generation - custom title (0)" {
skip_if_missing
prepare simple
add_photo 001 1.jpg
add_photo 001 2.jpg
add_photo 002 3.jpg
add_photo 002 4.jpg
add_photo 002 5.jpg
echo 'site_title="Custom gallery title"' >gallery.rc
run_it
assert_status 0 \
'stdout' "$output" \
'stderr' "$erroroutput" \
'files' "$( find . )"
assert_photos_copied
assert_html index.html '<!DOCTYPE html>
<html>
<head>
<title>Custom gallery title</title>
</head>
<body>
<h1>Custom gallery title</h1>
<ul>
<li>
<a href="001/index.html">001</a>
</li>
<li>
<a href="002/index.html">002</a>
</li>
</ul>
</body>
</html>'
assert_html 001/index.html '<!DOCTYPE html>
<html>
<head>
<title>001 | Custom gallery title</title>
</head>
<body>
<h1>001</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
assert_html 002/index.html '<!DOCTYPE html>
<html>
<head>
<title>002 | Custom gallery title</title>
</head>
<body>
<h1>002</h1>
<p><a href="../index.html">Back to gallery list</a></p>
<p>
<a href="00000001.jpg">
<img src="00000001.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000002.jpg">
<img src="00000002.jpg" width="200" height="{{{[0-9]+}}}">
</a>
<a href="00000003.jpg">
<img src="00000003.jpg" width="200" height="{{{[0-9]+}}}">
</a>
</p>
</body>
</html>'
}
@test "21/gallery.sh - Base gallery generation - intro page (0)" {
skip_if_missing
prepare simple
add_photo 001 1.jpg
add_photo 002 2.jpg
add_photo 002 3.jpg
echo 'Some _formatted_ content.' >HEADER.md
run_it
assert_status 0 \
'stdout' "$output" \
'stderr' "$erroroutput" \
'files' "$( find . )"
assert_photos_copied
assert_html index.html '<!DOCTYPE html>
<html>
<head>
<title>My photo gallery</title>
</head>
<body>
<h1>My photo gallery</h1>
<p>Some <em>formatted</em> content.</p>
<ul>
<li>
<a href="001/index.html">001</a>
</li>
<li>
<a href="002/index.html">002</a>
</li>
</ul>
</body>
</html>'
assert_html 001/index.html '<!DOCTYPE html>
<html>
<head>
<title>001 | My photo gallery</title>
</head>
<body>