Skip to content

Commit dc7efbe

Browse files
Irfan Ahmadclaude
authored andcommitted
fix: restore mockRuntime in display_spec.js constructor calls
The Problem constructor takes (runtime, element) per XBlock convention. The spec was missing mockRuntime as first arg and the declaration, causing this.element_id to be undefined at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8f7bb43 commit dc7efbe

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

xblocks_contrib/problem/assets/spec/display_spec.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
describe("Problem", function () {
22
const problem_content_default = readFixtures("problem_content.html");
3+
const mockRuntime = {};
34

45
beforeEach(function () {
56
// Stub MathJax
@@ -30,7 +31,7 @@ describe("Problem", function () {
3031

3132
describe("constructor", function () {
3233
it("set the element from html", function () {
33-
this.problem999 = new Problem(`\
34+
this.problem999 = new Problem(mockRuntime, `\
3435
<section class='xblock xblock-student_view xmodule_display xmodule_CapaModule' data-type='Problem'> \
3536
<section id='problem_999' \
3637
class='problems-wrapper' \
@@ -43,7 +44,7 @@ data-url='/problem/quiz/'> \
4344
});
4445

4546
it("set the element from loadFixtures", function () {
46-
this.problem1 = new Problem($(".xblock-student_view"));
47+
this.problem1 = new Problem(mockRuntime, $(".xblock-student_view"));
4748
expect(this.problem1.element_id).toBe("problem_1");
4849
});
4950
});
@@ -52,7 +53,7 @@ data-url='/problem/quiz/'> \
5253
beforeEach(function () {
5354
spyOn(window, "update_schematics");
5455
MathJax.Hub.getAllJax.and.returnValue([this.stubbedJax]);
55-
this.problem = new Problem($(".xblock-student_view"));
56+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
5657
});
5758

5859
it("set mathjax typeset", () => expect(MathJax.Hub.Queue).toHaveBeenCalled());
@@ -88,7 +89,7 @@ data-url='/problem/quiz/'> \
8889
beforeEach(function () {
8990
spyOn(window, "update_schematics");
9091
MathJax.Hub.getAllJax.and.returnValue([this.stubbedJax]);
91-
this.problem = new Problem($(".xblock-student_view"));
92+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
9293
return $(this).html(readFixtures("problem_content_1240.html"));
9394
});
9495

@@ -103,7 +104,7 @@ data-url='/problem/quiz/'> \
103104

104105
describe("renderProgressState", function () {
105106
beforeEach(function () {
106-
this.problem = new Problem($(".xblock-student_view"));
107+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
107108
});
108109

109110
const testProgessData = function (
@@ -206,7 +207,7 @@ data-url='/problem/quiz/'> \
206207

207208
describe("render", function () {
208209
beforeEach(function () {
209-
this.problem = new Problem($(".xblock-student_view"));
210+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
210211
this.bind = this.problem.bind;
211212
spyOn(this.problem, "bind");
212213
});
@@ -245,7 +246,7 @@ data-url='/problem/quiz/'> \
245246
beforeEach(function () {
246247
// Insert an input of type file outside of the problem.
247248
$(".xblock-student_view").after('<input type="file" />');
248-
this.problem = new Problem($(".xblock-student_view"));
249+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
249250
spyOn(this.problem, "submit");
250251
});
251252

@@ -257,7 +258,7 @@ data-url='/problem/quiz/'> \
257258

258259
describe("submit", function () {
259260
beforeEach(function () {
260-
this.problem = new Problem($(".xblock-student_view"));
261+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
261262
this.problem.answers = "foo=1&bar=2";
262263
});
263264

@@ -403,7 +404,7 @@ data-url='/problem/quiz/'> \
403404

404405
describe("submit button on problems", function () {
405406
beforeEach(function () {
406-
this.problem = new Problem($(".xblock-student_view"));
407+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
407408
this.submitDisabled = (disabled) => {
408409
if (disabled) {
409410
expect(this.problem.submitButton).toHaveAttr("disabled");
@@ -489,7 +490,7 @@ data-url='/problem/quiz/'> \
489490

490491
describe("reset", function () {
491492
beforeEach(function () {
492-
this.problem = new Problem($(".xblock-student_view"));
493+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
493494
});
494495

495496
it("log the problem_reset event", function () {
@@ -597,7 +598,7 @@ data-url='/problem/quiz/'> \
597598

598599
describe("show problem with column in id", function () {
599600
beforeEach(function () {
600-
this.problem = new Problem($(".xblock-student_view"));
601+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
601602
this.problem.el.prepend('<div id="answer_1_1:11" /><div id="answer_1_2:12" />');
602603
});
603604

@@ -630,7 +631,7 @@ data-url='/problem/quiz/'> \
630631

631632
describe("show", function () {
632633
beforeEach(function () {
633-
this.problem = new Problem($(".xblock-student_view"));
634+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
634635
this.problem.el.prepend('<div id="answer_1_1" /><div id="answer_1_2" />');
635636
});
636637

@@ -733,7 +734,7 @@ data-url='/problem/quiz/'> \
733734
};
734735

735736
beforeEach(function () {
736-
this.problem = new Problem($(".xblock-student_view"));
737+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
737738
this.problem.el.prepend(_.template(imageinput_html)(DEFAULTS));
738739
});
739740

@@ -897,7 +898,7 @@ data-url='/problem/quiz/'> \
897898

898899
describe("save", function () {
899900
beforeEach(function () {
900-
this.problem = new Problem($(".xblock-student_view"));
901+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
901902
this.problem.answers = "foo=1&bar=2";
902903
});
903904

@@ -987,7 +988,7 @@ data-url='/problem/quiz/'> \
987988

988989
describe("refreshMath", function () {
989990
beforeEach(function () {
990-
this.problem = new Problem($(".xblock-student_view"));
991+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
991992
// Reset Queue spy so that bind()'s Queue call ([fn, null, domEl]) is not
992993
// included when toHaveBeenCalledWith scans recorded calls. In Jasmine 2.99,
993994
// toHaveBeenCalledWith iterates ALL recorded calls' args element-by-element
@@ -1011,7 +1012,7 @@ data-url='/problem/quiz/'> \
10111012

10121013
describe("updateMathML", function () {
10131014
beforeEach(function () {
1014-
this.problem = new Problem($(".xblock-student_view"));
1015+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
10151016
this.stubbedJax.root.toMathML.and.returnValue("<MathML>");
10161017
});
10171018

@@ -1039,7 +1040,7 @@ data-url='/problem/quiz/'> \
10391040

10401041
describe("refreshAnswers", function () {
10411042
beforeEach(function () {
1042-
this.problem = new Problem($(".xblock-student_view"));
1043+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
10431044
this.problem.el.html(`\
10441045
<textarea class="CodeMirror" />
10451046
<input id="input_1_1" name="input_1_1" class="schematic" value="one" />
@@ -1067,7 +1068,7 @@ data-url='/problem/quiz/'> \
10671068
const jsinput_html = readFixtures("jsinput_problem.html");
10681069

10691070
beforeEach(function () {
1070-
this.problem = new Problem($(".xblock-student_view"));
1071+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
10711072
this.problem.render(jsinput_html);
10721073
});
10731074

@@ -1083,7 +1084,7 @@ data-url='/problem/quiz/'> \
10831084
beforeEach(function () {
10841085
spyOn($, "postWithPrefix").and.callFake((url, callback) => callback({ html: matlabinput_html }));
10851086
jasmine.clock().install();
1086-
this.problem = new Problem($(".xblock-student_view"));
1087+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
10871088
spyOn(this.problem, "poll").and.callThrough();
10881089
this.problem.render(matlabinput_html);
10891090
});
@@ -1118,7 +1119,7 @@ data-url='/problem/quiz/'> \
11181119

11191120
beforeEach(function () {
11201121
spyOn($, "postWithPrefix").and.callFake((url, callback) => callback({ html: codeinputProblemHtml }));
1121-
this.problem = new Problem($(".xblock-student_view"));
1122+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
11221123
this.problem.render(codeinputProblemHtml);
11231124
});
11241125

@@ -1142,7 +1143,7 @@ data-url='/problem/quiz/'> \
11421143
const checkboxProblemHtml = readFixtures("checkbox_problem.html");
11431144

11441145
beforeEach(function () {
1145-
this.problem = new Problem($(".xblock-student_view"));
1146+
this.problem = new Problem(mockRuntime, $(".xblock-student_view"));
11461147

11471148
this.checkAssertionsAfterClickingAnotherOption = () => {
11481149
// verify that 'show answer button is no longer disabled'

0 commit comments

Comments
 (0)