Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI flags to output well-formatted optional question attributes. #123

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions app/cmd/challenge_attributes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package cmd

import (
"strings"
"testing"
)

var questionTypes = []string{
"mc",
"cb",
"tl",
"sa",
"nb",
"pg",
"or",
"js",
"ja",
"py",
"sq",
"rb",
"up",
"cs",
"pr",
"tpr",
}

func Test_AttributesCommentsOccurInMaximalWithNoAttributes(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, blockHeader) {
t2.Errorf("%s did not have block header", command)
}
if !strings.Contains(rendered, hintTemplateSilent) {
t2.Errorf("%s did not have hint comment", command)
}
if !strings.Contains(rendered, rubricTemplateSilent) {
t2.Errorf("%s did not have rubric comment", command)
}
if !strings.Contains(rendered, explanationTemplateSilent) {
t2.Errorf("%s did not have explanation comment", command)
}
})
}
}

func Test_ExplanationBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = true
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, explanationTemplate) {
t2.Errorf("%s did not have explanation block", command)
}
})
}
}

func Test_RubricBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = true
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, rubricTemplate) {
t2.Errorf("%s did not have rubric block", command)
}
})
}
}

func Test_HintBlockAppearsWhenTrueInMaximal(t *testing.T) {
PrintTemplate = false
Minimal = false
WithExplanation = false
WithRubric = true
WithHints = 1

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, hintTemplate) {
t2.Errorf("%s did not have hint block", command)
}
})
}
}

func Test_AttributesCommentsAbsentInMinimalWithNoAttributes(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if strings.Contains(rendered, blockHeader) {
t2.Errorf("%s did have block header", command)
}
if strings.Contains(rendered, hintTemplateSilent) {
t2.Errorf("%s did have hint comment", command)
}
if strings.Contains(rendered, rubricTemplateSilent) {
t2.Errorf("%s did have rubric comment", command)
}
if strings.Contains(rendered, explanationTemplateSilent) {
t2.Errorf("%s did have explanation comment", command)
}
})
}
}

func Test_ExplanationBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = true
WithRubric = false
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, explanationTemplateMin) {
t2.Errorf("%s did not have explanation block", command)
}
})
}
}

func Test_RubricBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = true
WithHints = 0

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, rubricTemplateMin) {
t2.Errorf("%s did not have rubric block", command)
}
})
}
}

func Test_HintBlockAppearsWhenTrueInMinimal(t *testing.T) {
PrintTemplate = false
Minimal = true
WithExplanation = false
WithRubric = true
WithHints = 1

for _, command := range questionTypes {
t.Run(command, func(t2 *testing.T) {
template, _ := getTemp(command)
rendered := template.renderTemplate()

if !strings.Contains(rendered, hintTemplateMin) {
t2.Errorf("%s did not have hint block", command)
}
})
}
}
Loading
Loading