2023-08-26 14:28:30 +02:00
|
|
|
(defpackage cl-sbt/tests/questionnaire
|
|
|
|
(:use
|
|
|
|
:cl
|
|
|
|
:cl-sbt
|
|
|
|
:rove)
|
|
|
|
(:import-from
|
|
|
|
:cl-sbt/questionnaire
|
|
|
|
:question
|
|
|
|
:resolve-input-type
|
|
|
|
:resolve-input-and-choices
|
|
|
|
:questionnaire))
|
|
|
|
|
|
|
|
(in-package :cl-sbt/tests/questionnaire)
|
|
|
|
|
|
|
|
(deftest test-resolve-input-type
|
|
|
|
(testing "Test for resolve-input-type"
|
|
|
|
(ok (string= "radio" (resolve-input-type "single")))
|
|
|
|
(ok (string= "checkbox" (resolve-input-type "multiple")))
|
|
|
|
(ok (string= "text" (resolve-input-type "text")))))
|
|
|
|
|
|
|
|
(deftest test-resolve-input-and-choices
|
|
|
|
(testing "Test for resolve-input-and-choices"
|
|
|
|
(multiple-value-bind (type choices)
|
|
|
|
(resolve-input-and-choices '(:radio "A" "B"))
|
|
|
|
(ok (string= type "radio"))
|
|
|
|
(ok (equal choices '("A" "B"))))
|
|
|
|
(multiple-value-bind (type choices)
|
|
|
|
(resolve-input-and-choices '("A" "B"))
|
|
|
|
(ok (null type))
|
|
|
|
(ok (equal choices '("A" "B"))))))
|
2023-09-04 15:03:21 +02:00
|
|
|
|
2023-09-04 15:21:22 +02:00
|
|
|
(deftest test-create-questionnaire-single
|
2023-09-04 15:03:21 +02:00
|
|
|
(let ((result (spinneret:with-html-string
|
|
|
|
(questionnaire "/submit"
|
|
|
|
(:ask "Your Gender?"
|
|
|
|
:group "gender"
|
|
|
|
:choices (:single "Male" "Female" "Non-Binary" "Prefer not to say"))))))
|
2023-09-04 15:21:22 +02:00
|
|
|
(testing "Generates correct HTML for questionnaire with single choices"
|
2023-09-04 15:03:21 +02:00
|
|
|
(ok (search "<form class=py-5 action=/submit method=post>" result))
|
2023-09-04 15:21:22 +02:00
|
|
|
(ok (search "<legend>Your Gender?</legend>" result))
|
2023-09-06 14:30:51 +02:00
|
|
|
(ok (search "class=form-check-input" result))
|
|
|
|
(ok (search "name=group-gender" result))
|
|
|
|
(ok (search "value=male" result))
|
2023-09-04 15:03:21 +02:00
|
|
|
(ok (search "<hr class=my-4>" result))
|
|
|
|
(ok (search "<button class=\"btn btn-primary\" type=submit>Submit</button>" result)))))
|
2023-09-04 15:21:22 +02:00
|
|
|
|
|
|
|
(deftest test-create-questionnaire-multiple
|
|
|
|
(let ((result (spinneret:with-html-string
|
|
|
|
(questionnaire "/submit"
|
|
|
|
(:ask "Which of the following devices do you regularly use to browse the internet?"
|
|
|
|
:group "device"
|
|
|
|
:choices (:multiple "Desktop" "Laptop" "Tablet"))))))
|
|
|
|
(testing "Generates correct HTML for questionnaire with multiple choices"
|
|
|
|
(ok (search "<form class=py-5 action=/submit method=post>" result))
|
|
|
|
(ok (search "<legend>Which of the following devices do you regularly use to browse the internet?</legend>" result))
|
2023-09-06 14:30:51 +02:00
|
|
|
(ok (search "type=checkbox" result))
|
|
|
|
(ok (search "name=group-device" result))
|
|
|
|
(ok (search "value=desktop" result))
|
2023-09-04 15:21:22 +02:00
|
|
|
(ok (search "<hr class=my-4>" result))
|
|
|
|
(ok (search "<button class=\"btn btn-primary\" type=submit>Submit</button>" result)))))
|
2023-09-04 15:48:47 +02:00
|
|
|
|
|
|
|
(deftest test-create-questionnaire-mixed-choices
|
|
|
|
(let ((result (spinneret:with-html-string
|
|
|
|
(questionnaire "/submit"
|
|
|
|
(:ask "Which of the following devices do you regularly use to browse the internet?"
|
|
|
|
:group "device"
|
|
|
|
:choices (:multiple "Desktop" "Laptop" "Tablet"
|
|
|
|
:text "Others (please specify)"))))))
|
|
|
|
(testing "Generates correct HTML for questionnaire with multiple choices"
|
|
|
|
(ok (search "<form class=py-5 action=/submit method=post>" result))
|
|
|
|
(ok (search "<legend>Which of the following devices do you regularly use to browse the internet?</legend>" result))
|
2023-09-06 14:30:51 +02:00
|
|
|
(ok (search "type=checkbox" result))
|
|
|
|
(ok (search "name=group-device" result))
|
|
|
|
(ok (search "class=\"form-label group-device\"" result))
|
|
|
|
(ok (search "class=form-control" result))
|
2023-09-04 15:48:47 +02:00
|
|
|
(ok (search "<hr class=my-4>" result))
|
|
|
|
(ok (search "<button class=\"btn btn-primary\" type=submit>Submit</button>" result)))))
|
2023-09-13 15:46:26 +02:00
|
|
|
|
|
|
|
(deftest test-create-questionnaire-single-german
|
|
|
|
(let* ((spinneret:*html-lang* "de")
|
|
|
|
(result (spinneret:with-html-string
|
|
|
|
(questionnaire "/submit"
|
|
|
|
(:frage "Ihr Geschlecht?"
|
|
|
|
:gruppe "geschlecht"
|
|
|
|
:auswahl (:single "Männlich"
|
|
|
|
"Weiblich"
|
|
|
|
"Non-Binary"
|
|
|
|
"Keine Angabe"))))))
|
|
|
|
(testing "Generates correct HTML for questionnaire with single choices"
|
|
|
|
(ok (search "<form class=py-5 action=/submit method=post>" result))
|
|
|
|
(ok (search "<legend>Ihr Geschlecht?</legend>" result))
|
|
|
|
(ok (search "class=form-check-input" result))
|
|
|
|
(ok (search "name=group-geschlecht" result))
|
|
|
|
(ok (search "value=männlich" result))
|
|
|
|
(ok (search "value=weiblich" result))
|
|
|
|
(ok (search "value=keine-angabe" result))
|
|
|
|
(ok (search "<button class=\"btn btn-primary\" type=submit>Absenden</button>" result)))))
|