Skip to content

Commit b87d62f

Browse files
committed
feat(grading) - add prefill to 0 and adjust prefill policies for some question types
- refactor to differentiate question types that can be prefilled either to 0 or max, both or neither (for previous code, only boolean for if it can be prefilled) - TextResponse and Comprehension question types adjusted to allow prefilling to full - add tests for different policies
1 parent 958e986 commit b87d62f

2 files changed

Lines changed: 393 additions & 35 deletions

File tree

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
import { dispatch, store } from 'store';
2+
3+
import actions, { questionTypes } from '../../../constants';
4+
5+
const answerId = 3;
6+
7+
const buildPayload = ({ questionType, grade, correct, testCases } = {}) => ({
8+
submission: {
9+
pointsAwarded: null,
10+
basePoints: 1000,
11+
submittedAt: '2017-05-11T17:02:17.000+08:00',
12+
bonusEndAt: '2017-05-11T17:02:17.000+08:00',
13+
bonusPoints: 0,
14+
},
15+
assessment: {},
16+
annotations: [],
17+
posts: [],
18+
topics: [],
19+
questions: [{ id: 1, type: questionType, maximumGrade: 10 }],
20+
answers: [
21+
{
22+
id: answerId,
23+
fields: {
24+
id: answerId,
25+
questionId: 1,
26+
},
27+
questionId: 1,
28+
grading: {
29+
grade,
30+
id: answerId,
31+
},
32+
explanation: correct !== undefined ? { correct } : undefined,
33+
testCases,
34+
},
35+
],
36+
});
37+
38+
const dispatchFetchSuccess = (payload) =>
39+
dispatch({ type: actions.FETCH_SUBMISSION_SUCCESS, payload });
40+
41+
const getGrade = () =>
42+
store.getState().assessments.submission.grading.questions[1].grade;
43+
44+
describe('getPrefilledGrade via FETCH_SUBMISSION_SUCCESS', () => {
45+
describe('general behavior', () => {
46+
it('preserves existing grade even if answer is correct', () => {
47+
dispatchFetchSuccess(
48+
buildPayload({
49+
questionType: questionTypes.MultipleChoice,
50+
grade: 5,
51+
correct: true,
52+
}),
53+
);
54+
55+
expect(getGrade()).toBe(5);
56+
});
57+
58+
it('preserves existing grade even if answer is incorrect', () => {
59+
dispatchFetchSuccess(
60+
buildPayload({
61+
questionType: questionTypes.MultipleChoice,
62+
grade: 8,
63+
correct: false,
64+
}),
65+
);
66+
67+
expect(getGrade()).toBe(8);
68+
});
69+
70+
it('leaves grade as null when there is no explanation', () => {
71+
dispatchFetchSuccess(
72+
buildPayload({
73+
questionType: questionTypes.MultipleChoice,
74+
grade: null,
75+
correct: undefined,
76+
}),
77+
);
78+
79+
expect(getGrade()).toBeNull();
80+
});
81+
});
82+
83+
describe('Question Types with ALWAYS_PREFILL_POLICY', () => {
84+
it('prefills maximum grade for an ungraded correct answer', () => {
85+
dispatchFetchSuccess(
86+
buildPayload({
87+
questionType: questionTypes.MultipleChoice,
88+
grade: null,
89+
correct: true,
90+
}),
91+
);
92+
93+
expect(getGrade()).toBe(10);
94+
});
95+
96+
it('prefills 0 for an ungraded incorrect answer', () => {
97+
dispatchFetchSuccess(
98+
buildPayload({
99+
questionType: questionTypes.MultipleChoice,
100+
grade: null,
101+
correct: false,
102+
}),
103+
);
104+
105+
expect(getGrade()).toBe(0);
106+
});
107+
});
108+
109+
describe('Question Types with NEVER_PREFILL_POLICY', () => {
110+
it('does not prefill for an ungraded correct answer', () => {
111+
dispatchFetchSuccess(
112+
buildPayload({
113+
questionType: questionTypes.VoiceResponse,
114+
grade: null,
115+
correct: true,
116+
}),
117+
);
118+
119+
expect(getGrade()).toBeNull();
120+
});
121+
122+
it('does not prefill for an ungraded incorrect answer', () => {
123+
dispatchFetchSuccess(
124+
buildPayload({
125+
questionType: questionTypes.VoiceResponse,
126+
grade: null,
127+
correct: false,
128+
}),
129+
);
130+
131+
expect(getGrade()).toBeNull();
132+
});
133+
});
134+
135+
describe('Question Types with ONLY_PREFILL_FULL_POLICY', () => {
136+
it('prefills maximum grade for an ungraded correct answer', () => {
137+
dispatchFetchSuccess(
138+
buildPayload({
139+
questionType: questionTypes.TextResponse,
140+
grade: null,
141+
correct: true,
142+
}),
143+
);
144+
145+
expect(getGrade()).toBe(10);
146+
});
147+
148+
it('does not prefill 0 for an ungraded incorrect answer', () => {
149+
dispatchFetchSuccess(
150+
buildPayload({
151+
questionType: questionTypes.TextResponse,
152+
grade: null,
153+
correct: false,
154+
}),
155+
);
156+
157+
expect(getGrade()).toBeNull();
158+
});
159+
});
160+
161+
describe('Programming', () => {
162+
const withTestCases = {
163+
public_test: [{ identifier: 'test1' }],
164+
};
165+
166+
it('prefills maximum grade when test cases exist and answer is correct', () => {
167+
dispatchFetchSuccess(
168+
buildPayload({
169+
questionType: questionTypes.Programming,
170+
grade: null,
171+
correct: true,
172+
testCases: withTestCases,
173+
}),
174+
);
175+
176+
expect(getGrade()).toBe(10);
177+
});
178+
179+
it('does not prefill 0 when test cases exist and answer is incorrect', () => {
180+
dispatchFetchSuccess(
181+
buildPayload({
182+
questionType: questionTypes.Programming,
183+
grade: null,
184+
correct: false,
185+
testCases: withTestCases,
186+
}),
187+
);
188+
189+
expect(getGrade()).toBeNull();
190+
});
191+
192+
it('prefills maximum grade when only private_test cases exist and answer is correct', () => {
193+
dispatchFetchSuccess(
194+
buildPayload({
195+
questionType: questionTypes.Programming,
196+
grade: null,
197+
correct: true,
198+
testCases: { private_test: [{ identifier: 'test1' }] },
199+
}),
200+
);
201+
202+
expect(getGrade()).toBe(10);
203+
});
204+
205+
it('prefills maximum grade when only evaluation_test cases exist and answer is correct', () => {
206+
dispatchFetchSuccess(
207+
buildPayload({
208+
questionType: questionTypes.Programming,
209+
grade: null,
210+
correct: true,
211+
testCases: { evaluation_test: [{ identifier: 'test1' }] },
212+
}),
213+
);
214+
215+
expect(getGrade()).toBe(10);
216+
});
217+
218+
it('leaves grade as null when no test cases exist, even if answer is correct', () => {
219+
dispatchFetchSuccess(
220+
buildPayload({
221+
questionType: questionTypes.Programming,
222+
grade: null,
223+
correct: true,
224+
testCases: null,
225+
}),
226+
);
227+
228+
expect(getGrade()).toBeNull();
229+
});
230+
});
231+
});

0 commit comments

Comments
 (0)