@@ -118,6 +118,29 @@ def test_studio_submit_creates_scenario(rf, block):
118118 assert block .max_score == 77
119119
120120
121+ def test_studio_submit_persists_enable_reset_activity (rf , block ):
122+ payload = {
123+ "nodes" : [
124+ {
125+ "id" : "temp-1" ,
126+ "content" : "Start node" ,
127+ "media" : {"type" : "" , "url" : "" },
128+ "choices" : [],
129+ "transcript_url" : "" ,
130+ },
131+ ],
132+ "enable_undo" : False ,
133+ "enable_scoring" : False ,
134+ "enable_reset_activity" : True ,
135+ "max_score" : 0 ,
136+ }
137+ req = rf .post ("/" , data = json .dumps (payload ), content_type = "application/json" )
138+ resp = block .studio_submit (req )
139+ result = json .loads (resp .body .decode ("utf-8" ))
140+ assert result ["result" ] == "success"
141+ assert block .enable_reset_activity is True
142+
143+
121144def test_studio_submit_persists_display_name (rf , block ):
122145 payload = {
123146 "nodes" : [
@@ -256,6 +279,52 @@ def test_undo_choice_honors_enable_undo(rf, block):
256279 assert resp_fail ["success" ] is False
257280
258281
282+ def test_reset_activity_requires_enable_reset_activity (rf , block ):
283+ block .scenario_data = {
284+ "nodes" : {"start" : {"id" : "start" , "type" : "start" , "choices" : []}},
285+ "start_node_id" : "start" ,
286+ }
287+ block .enable_reset_activity = False
288+ req = rf .post ("/" , data = json .dumps ({}), content_type = "application/json" )
289+ resp = block .reset_activity (req )
290+ result = json .loads (resp .body .decode ("utf-8" ))
291+ assert result ["success" ] is False
292+ assert result ["error" ] == "Reset not allowed"
293+
294+
295+ def test_reset_activity_clears_progress_and_score (rf , block ):
296+ block .scenario_data = {
297+ "nodes" : {
298+ "start" : {
299+ "id" : "start" ,
300+ "type" : "start" ,
301+ "choices" : [{"text" : "Next" , "target_node_id" : "end" }],
302+ },
303+ "end" : {"id" : "end" , "type" : "end" , "choices" : []},
304+ },
305+ "start_node_id" : "start" ,
306+ }
307+ block .enable_reset_activity = True
308+ block .enable_scoring = True
309+ block .current_node_id = "end"
310+ block .history = ["start" ]
311+ block .has_completed = True
312+ block .score = 42.0
313+ req = rf .post ("/" , data = json .dumps ({}), content_type = "application/json" )
314+
315+ resp = block .reset_activity (req )
316+ result = json .loads (resp .body .decode ("utf-8" ))
317+
318+ assert result ["success" ] is True
319+ assert block .current_node_id == "start"
320+ assert block .history == []
321+ assert block .has_completed is False
322+ assert block .score == 0.0
323+ assert result ["current_node" ]["id" ] == "start"
324+ assert result ["has_completed" ] is False
325+ assert result ["score" ] == 0.0
326+
327+
259328def test_get_current_state_includes_expected_fields (rf , block ):
260329 """
261330 get_current_state should return a dict containing:
@@ -273,7 +342,14 @@ def test_get_current_state_includes_expected_fields(rf, block):
273342 resp = block .get_current_state (req )
274343 state = json .loads (resp .body .decode ('utf-8' ))
275344 assert isinstance (state ["nodes" ], dict )
276- for key in ("current_node" , "history" , "has_completed" , "score" ):
345+ for key in (
346+ "current_node" ,
347+ "history" ,
348+ "has_completed" ,
349+ "score" ,
350+ "start_node_id" ,
351+ "enable_reset_activity" ,
352+ ):
277353 assert key in state
278354
279355
@@ -303,3 +379,27 @@ def fake_initialize_js(_self, name, init_data):
303379
304380 assert calls ["name" ] == "BranchingStudioEditor"
305381 assert calls ["init_data" ]["authoring_help_html" ] == "<p>Help</p>"
382+
383+
384+ def test_studio_view_includes_enable_reset_activity_in_init_data (block ):
385+ calls = {}
386+
387+ def fake_initialize_js (_self , name , init_data ):
388+ calls ["name" ] = name
389+ calls ["init_data" ] = init_data
390+
391+ block .enable_reset_activity = True
392+
393+ with mock .patch (
394+ "branching_xblock.branching_xblock.Fragment.initialize_js" ,
395+ autospec = True ,
396+ side_effect = fake_initialize_js ,
397+ ), mock .patch .object (
398+ block .runtime ,
399+ "local_resource_url" ,
400+ return_value = "http://example.com/handlebars.js" ,
401+ ):
402+ block .studio_view ({})
403+
404+ assert calls ["name" ] == "BranchingStudioEditor"
405+ assert calls ["init_data" ]["enable_reset_activity" ] is True
0 commit comments