Add dish CRUD to the UI, including inline from Kirjaa
The catalog could only be filled by importing JSON, which is a poor way to add the one dish you are about to eat. Ruoat now covers PRD §7.3 in full: add and edit mains with their categories and has_sides, add and edit sides, and delete either. Deletes are soft, so a log entry keeps resolving the dish it used and the freed name can be reused. Validation messages are Finnish and the rejected form comes back filled in rather than blank. Bulk import moves into a details element, since it is now the occasional path rather than the only one. Kirjaa gets the same ability without the detour: a search that finds nothing offers to add what was typed, and saving creates the dish and continues straight to the sides step. An empty catalog shows the same card instead of dead-ending on a link to another tab, and the search box is no longer hidden behind the empty state. The importer's own insert is gone; it and the UI both go through createMain and createSide, so duplicate detection lives in one place and reason() can match on errNameTaken instead of poking at driver strings.
This commit is contained in:
@@ -115,6 +115,60 @@ check "the day is empty again" \
|
||||
check "search filters the board" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/?haku=keitto")" "keitto"
|
||||
|
||||
# ---- adding a dish without leaving Kirjaa --------------------------------
|
||||
|
||||
miss=$(curl -s -u ":$pass" "http://$addr/?haku=Poronkariste")
|
||||
check "a search with no hits offers to add it" "$miss" "Ei osumia. Lisätäänkö?"
|
||||
check "the add form is prefilled with the search" "$miss" 'value="Poronkariste"'
|
||||
|
||||
check "quick add goes straight to the sides step" \
|
||||
"$(curl -s -o /dev/null -w '%{redirect_url}' -u ":$pass" \
|
||||
-d 'nimi=Poronkariste&kategoria=meat&lisukkeita=1' "http://$addr/lisaa")" \
|
||||
"ruoka="
|
||||
|
||||
check "quick add rejects a dish with no category" \
|
||||
"$(curl -s -u ":$pass" -d 'nimi=Kategoriaton' "http://$addr/lisaa")" \
|
||||
"Valitse vähintään yksi kategoria."
|
||||
|
||||
check "the quick-added dish is on the board" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/")" "Poronkariste"
|
||||
|
||||
# ---- catalog CRUD from the UI -------------------------------------------
|
||||
|
||||
check "adding a main redirects" \
|
||||
"$(curl -s -o /dev/null -w '%{http_code}' -u ":$pass" \
|
||||
-d 'nimi=uunikala&kategoria=fish&lisukkeita=1' "http://$addr/ruoat/paaruoka")" "303"
|
||||
|
||||
catalog=$(curl -s -u ":$pass" "http://$addr/ruoat")
|
||||
check "the new main is listed, sentence-cased" "$catalog" "Uunikala"
|
||||
|
||||
check "a duplicate name is refused" \
|
||||
"$(curl -s -u ":$pass" -d 'nimi=UUNIKALA&kategoria=fish' "http://$addr/ruoat/paaruoka")" \
|
||||
"Nimi on jo listalla."
|
||||
|
||||
check "a main with no category is refused" \
|
||||
"$(curl -s -u ":$pass" -d 'nimi=Kategoriaton' "http://$addr/ruoat/paaruoka")" \
|
||||
"Valitse vähintään yksi kategoria."
|
||||
|
||||
check "a nameless dish is refused" \
|
||||
"$(curl -s -u ":$pass" -d 'nimi=+++&kategoria=fish' "http://$addr/ruoat/paaruoka")" \
|
||||
"Anna nimi."
|
||||
|
||||
check "adding a side redirects" \
|
||||
"$(curl -s -o /dev/null -w '%{http_code}' -u ":$pass" \
|
||||
-d 'nimi=lohkoperunat' "http://$addr/ruoat/lisuke")" "303"
|
||||
|
||||
check "the new side is listed" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/ruoat")" "Lohkoperunat"
|
||||
|
||||
uusi=$(printf '%s' "$catalog" | grep -o 'muokkaa=[0-9]*' | head -n1 | cut -d= -f2)
|
||||
check "the edit form is prefilled" \
|
||||
"$(curl -s -u ":$pass" "http://$addr/ruoat?muokkaa=$uusi")" "Muokkaa pääruokaa"
|
||||
|
||||
check "deleting a main redirects" \
|
||||
"$(curl -s -o /dev/null -w '%{http_code}' -u ":$pass" \
|
||||
-d "id=$uusi&tyyppi=paa" "http://$addr/ruoat/poista")" "303"
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
echo "smoke: FAILED"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user