@@ -18,11 +18,25 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest
1818 assert_select "summary" , text : /Introduction to Health/
1919 end
2020
21- test "shows links inside published modules " do
21+ test "links open in a new tab " do
2222 get student_homes_url
2323 assert_response :success
24- link = content_modules ( :one ) . links . first
25- assert_select "a[target='_blank']" , text : /#{ link . title } / if link
24+ assert_select "li a[href='#{ links ( :one ) . url } '][target='_blank'][rel='noopener noreferrer']" , text : /#{ links ( :one ) . title } /
25+ end
26+
27+ test "games link to the play page in the same tab" do
28+ get student_homes_url
29+ assert_response :success
30+ assert_select "li a[href='#{ play_game_path ( games ( :one ) ) } ']:not([target])" , text : games ( :one ) . title
31+ end
32+
33+ test "shows contents in position order" do
34+ contents ( :one ) . update! ( position : 2 )
35+ contents ( :two ) . update! ( position : 1 )
36+
37+ get student_homes_url
38+ titles = listed_titles
39+ assert_operator titles . index ( links ( :one ) . title ) , :< , titles . index ( games ( :one ) . title )
2640 end
2741
2842 test "most recently published module has the open attribute" do
@@ -79,4 +93,11 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest
7993 get student_homes_url ( classroom_program_id : enrollment . id )
8094 assert_select "a[role='tab'][aria-selected='true'][href*='classroom_program_id=#{ enrollment . id } ']"
8195 end
96+
97+ private
98+
99+ # The " ↗" suffix marks external links, so strip it to compare plain titles.
100+ def listed_titles
101+ css_select ( "details li a" ) . map { |a | a . text . delete_suffix ( " ↗" ) }
102+ end
82103end
0 commit comments