@@ -2,13 +2,18 @@ import {mockStrings} from "../../strings";
2
2
3
3
import radioValidator from "./radio-validator" ;
4
4
5
+ import type {
6
+ PerseusRadioRubric ,
7
+ PerseusRadioUserInput ,
8
+ } from "../../validation.types" ;
9
+
5
10
describe ( "radioValidator" , ( ) => {
6
11
it ( "is invalid when no options are selected" , ( ) => {
7
- const userInput = {
12
+ const userInput : PerseusRadioUserInput = {
8
13
choicesSelected : [ false , false , false , false ] ,
9
14
} ;
10
15
11
- const rubric = {
16
+ const rubric : PerseusRadioRubric = {
12
17
choices : [
13
18
{ content : "Choice 1" } ,
14
19
{ content : "Choice 2" } ,
@@ -23,12 +28,12 @@ describe("radioValidator", () => {
23
28
} ) ;
24
29
25
30
it ( "is invalid when number selected does not match number correct" , ( ) => {
26
- const userInput = {
31
+ const userInput : PerseusRadioUserInput = {
27
32
numCorrect : 2 ,
28
33
choicesSelected : [ true , false , false , false ] ,
29
34
} ;
30
35
31
- const rubric = {
36
+ const rubric : PerseusRadioRubric = {
32
37
choices : [
33
38
{ content : "Choice 1" , correct : true } ,
34
39
{ content : "Choice 2" , correct : true } ,
@@ -43,20 +48,19 @@ describe("radioValidator", () => {
43
48
} ) ;
44
49
45
50
it ( "is invalid when none of the above and an answer are both selected" , ( ) => {
46
- const userInput = {
51
+ const userInput : PerseusRadioUserInput = {
47
52
noneOfTheAboveSelected : true ,
48
53
choicesSelected : [ true , false , false , false , true ] ,
49
54
} ;
50
55
51
- const rubric = {
56
+ const rubric : PerseusRadioRubric = {
52
57
choices : [
53
58
{ content : "Choice 1" , correct : true } ,
54
59
{ content : "Choice 2" , correct : false } ,
55
60
{ content : "Choice 3" , correct : false } ,
56
61
{ content : "Choice 4" , correct : false } ,
57
62
{ content : "None of the above" , correct : false } ,
58
63
] ,
59
- hasNoneOfTheAbove : true ,
60
64
} ;
61
65
62
66
const result = radioValidator ( userInput , rubric , mockStrings ) ;
@@ -65,11 +69,11 @@ describe("radioValidator", () => {
65
69
} ) ;
66
70
67
71
it ( "can handle single correct answer" , ( ) => {
68
- const userInput = {
72
+ const userInput : PerseusRadioUserInput = {
69
73
choicesSelected : [ true , false , false , false ] ,
70
74
} ;
71
75
72
- const rubric = {
76
+ const rubric : PerseusRadioRubric = {
73
77
choices : [
74
78
{ content : "Choice 1" , correct : true } ,
75
79
{ content : "Choice 2" , correct : false } ,
@@ -84,11 +88,11 @@ describe("radioValidator", () => {
84
88
} ) ;
85
89
86
90
it ( "can handle single incorrect answer" , ( ) => {
87
- const userInput = {
91
+ const userInput : PerseusRadioUserInput = {
88
92
choicesSelected : [ false , false , false , true ] ,
89
93
} ;
90
94
91
- const rubric = {
95
+ const rubric : PerseusRadioRubric = {
92
96
choices : [
93
97
{ content : "Choice 1" , correct : true } ,
94
98
{ content : "Choice 2" , correct : false } ,
@@ -103,11 +107,11 @@ describe("radioValidator", () => {
103
107
} ) ;
104
108
105
109
it ( "can handle multiple correct answer" , ( ) => {
106
- const userInput = {
110
+ const userInput : PerseusRadioUserInput = {
107
111
choicesSelected : [ true , true , false , false ] ,
108
112
} ;
109
113
110
- const rubric = {
114
+ const rubric : PerseusRadioRubric = {
111
115
choices : [
112
116
{ content : "Choice 1" , correct : true } ,
113
117
{ content : "Choice 2" , correct : true } ,
@@ -122,11 +126,11 @@ describe("radioValidator", () => {
122
126
} ) ;
123
127
124
128
it ( "can handle multiple incorrect answer" , ( ) => {
125
- const userInput = {
129
+ const userInput : PerseusRadioUserInput = {
126
130
choicesSelected : [ true , false , false , true ] ,
127
131
} ;
128
132
129
- const rubric = {
133
+ const rubric : PerseusRadioRubric = {
130
134
choices : [
131
135
{ content : "Choice 1" , correct : true } ,
132
136
{ content : "Choice 2" , correct : true } ,
@@ -141,13 +145,13 @@ describe("radioValidator", () => {
141
145
} ) ;
142
146
143
147
it ( "can handle none of the above correct answer" , ( ) => {
144
- const userInput = {
148
+ const userInput : PerseusRadioUserInput = {
145
149
choicesSelected : [ false , false , false , false , true ] ,
146
150
noneOfTheAboveSelected : true ,
147
151
noneOfTheAboveIndex : 4 ,
148
152
} ;
149
153
150
- const rubric = {
154
+ const rubric : PerseusRadioRubric = {
151
155
choices : [
152
156
{ content : "Choice 1" , correct : false } ,
153
157
{ content : "Choice 2" , correct : false } ,
@@ -162,13 +166,13 @@ describe("radioValidator", () => {
162
166
} ) ;
163
167
164
168
it ( "can handle none of the above incorrect answer" , ( ) => {
165
- const userInput = {
169
+ const userInput : PerseusRadioUserInput = {
166
170
choicesSelected : [ false , false , false , false , true ] ,
167
171
noneOfTheAboveSelected : true ,
168
172
noneOfTheAboveIndex : 4 ,
169
173
} ;
170
174
171
- const rubric = {
175
+ const rubric : PerseusRadioRubric = {
172
176
choices : [
173
177
{ content : "Choice 1" , correct : true } ,
174
178
{ content : "Choice 2" , correct : false } ,
0 commit comments