@@ -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