Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 21f2cf5

Browse files
committed
✅ Adding unit test for block based feedback
1 parent 059758a commit 21f2cf5

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

runestone/hparsons/js/horizontal-parsons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15513,7 +15513,7 @@ class HParsonsElement extends HTMLElement {
1551315513
sheet.innerHTML += '.hparsons-input {padding: 15px;}\n';
1551415514
sheet.innerHTML += '.hparsons-tip { font-style: italic; }\n';
1551515515
sheet.innerHTML += '.parsons-block {display: inline-block; font-family: monospace; border-color:gray; margin: 0 1px; position: relative; border-radius: 10px; background-color: #efefef; border: 1px solid #d3d3d3; padding: 5px 10px; margin-top: 5px;}\n';
15516-
sheet.innerHTML += '.parsons-block.incorrectPosition {background-color: #ffbaba; border: 1px solid red;}\n';
15516+
sheet.innerHTML += '.drop-area .parsons-block.incorrectPosition {background-color: #ffbaba; border: 1px solid red;}\n';
1551715517
sheet.innerHTML += '.parsons-block:hover, .parsons-block:focus { border-color: black;}\n';
1551815518
sheet.innerHTML += '.drop-area { background-color: #ffa; padding: 0 5px; height: 42px; margin: 2px 0;}\n';
1551915519
sheet.innerHTML += '.drop-area.incorrect { background-color: #f2dede; border-color: #f2b6b6}\n';

runestone/hparsons/test/test_hparsons.py

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,75 @@ def test_run_SQL(selenium_utils_get):
109109
res = selenium_utils_get.driver.find_element(By.ID, f"{div_id}_sql_out")
110110
assert res
111111
out = selenium_utils_get.driver.find_element(By.ID, f"{div_id}_stdout")
112-
assert "You passed 2 out of 3 tests" in out.text
112+
assert "You passed 2 out of 3 tests" in out.text
113+
114+
115+
"""
116+
Test Block Based feedback is correct:
117+
1-1. Click on three blocks to form a solution that does not have enough blocks
118+
1-2. Click on run button to check the result is hinting missing blocks
119+
2-1. Click on more blocks to form an incorrect solution
120+
2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
121+
3-1. Click to change to the correct answer
122+
3-2. Click on run button to check the result is hinting that they completed in 3 attempts
123+
3-3. Check the run button is disabled
124+
4-1. Click on reset button
125+
4-2. Form a correct solution
126+
4-3. Click on run button to check the result is hinting completed in one attempt
127+
"""
128+
def test_run_block(selenium_utils_get):
129+
div_id = "test_hparsons_block_1"
130+
hp_question = find_hp_question(selenium_utils_get, div_id)
131+
hp = hp_question.find_element(By.CSS_SELECTOR, 'horizontal-parsons')
132+
drag_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drag-area')
133+
drop_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drop-area')
134+
run_btn = hp_question.find_elements(By.TAG_NAME, 'button')[0]
135+
reset_btn = hp_question.find_elements(By.TAG_NAME, 'button')[1]
136+
137+
# 1-1. Click on three blocks to form a solution that does not have enough blocks
138+
for code_piece in ['SELECT', '*', 'test']:
139+
blocks = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
140+
for block in blocks:
141+
if block.text == code_piece:
142+
block.click()
143+
# 1-2. Click on run button to check the result is hinting missing blocks
144+
run_btn.click()
145+
feedback_area = hp_question.find_element(By.CLASS_NAME, 'alert')
146+
assert 'Your program is too short.' in feedback_area.text
147+
148+
# 2-1. Click on more blocks to form an incorrect solution
149+
block = drag_area.find_element(By.CSS_SELECTOR, '.parsons-block')
150+
block.click()
151+
# 2-2. Click on run button to check the result is hinting incorrect, and incorrect blocks are highlight correctly
152+
run_btn.click()
153+
time.sleep(1)
154+
feedback_area = hp_question.find_element(By.CLASS_NAME, 'alert')
155+
assert 'Highlighted blocks in your program are wrong or are in the wrong order.' in feedback_area.text
156+
highlighted_blocks = []
157+
for block in drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block.incorrectPosition'):
158+
highlighted_blocks.append(block.text)
159+
assert set(highlighted_blocks) == set(['FROM'])
160+
161+
# 3-1. Click to change to the correct answer
162+
drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[2].click()
163+
drag_area.find_element(By.CSS_SELECTOR, '.parsons-block').click()
164+
# 3-2. Click on run button to check the result is hinting that they completed in 3 attempts
165+
run_btn.click()
166+
feedback_area = hp_question.find_element(By.CLASS_NAME, 'alert')
167+
assert 'It took you 3 tries to solve this.' in feedback_area.text
168+
# 3-3. Check the run button is disabled
169+
assert run_btn.get_attribute('disabled') == 'true'
170+
171+
# 4-1. Click on reset button
172+
reset_btn.click()
173+
# 4-2. Form a correct solution
174+
for code_piece in ['SELECT', '*', 'FROM', 'test']:
175+
blocks = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
176+
for block in blocks:
177+
if block.text == code_piece:
178+
block.click()
179+
# 4-3. Click on run button to check the result is hinting completed in one attempt
180+
run_btn.click()
181+
feedback_area = hp_question.find_element(By.CLASS_NAME, 'alert')
182+
assert 'It took you only one try to solve this.' in feedback_area.text
183+

0 commit comments

Comments
 (0)