feat: add test mode to quizzes and withhold its solutions
- mode, navigation and max_attempts columns with Go-side defaults - classes.Withheld gates every solution field of the answer feedback and the attempt result while a test attempt is open - a test's quiz detail lists no questions before the attempt starts - admin fields and lang keys for the three settings
This commit is contained in:
29
models/quiz_test.go
Normal file
29
models/quiz_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestQuizDefaults(t *testing.T) {
|
||||
zero, negative := 0, -1
|
||||
for name, hook := range map[string]func(*Quiz) error{
|
||||
"BeforeSave": func(q *Quiz) error { return q.BeforeSave(nil) },
|
||||
"BeforeValidate": func(q *Quiz) error { return q.BeforeValidate(nil) },
|
||||
} {
|
||||
for _, limit := range []*int{&zero, &negative} {
|
||||
q := &Quiz{Title: "Q", MaxAttempts: limit}
|
||||
if err := hook(q); err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
if q.Mode != ModeLearning || q.Navigation != NavigationFree || q.MaxAttempts != nil {
|
||||
t.Errorf("%s with max_attempts %d = %q %q %v, want learning free nil", name, *limit, q.Mode, q.Navigation, q.MaxAttempts)
|
||||
}
|
||||
}
|
||||
two := 2
|
||||
q := &Quiz{Title: "Q", Mode: ModeTest, Navigation: NavigationOneWay, MaxAttempts: &two}
|
||||
if err := hook(q); err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
if q.Mode != ModeTest || q.Navigation != NavigationOneWay || q.MaxAttempts == nil || *q.MaxAttempts != 2 {
|
||||
t.Errorf("%s changed a test quiz: %q %q %v", name, q.Mode, q.Navigation, q.MaxAttempts)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user