Skip to content

Commit

Permalink
Tests for learning path nav box
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacall committed Oct 25, 2024
1 parent 6eed8ca commit 9898a1b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/controllers/learning_paths_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,15 @@ class LearningPathsControllerTest < ActionController::TestCase
response_events = body.dig('data', 'relationships', 'events', 'data')
assert_equal [events[1].id, events[0].id], response_events.map { |e| e['id'].to_i }
end

test 'should include back-reference to learning path in item links' do
get :show, params: { id: @learning_path }

assert_response :success
topic_link = @learning_path.topic_links.first
topic_item = topic_link.topic.items.first

assert_select '.link-overlay[href=?]',
material_path(topic_item.resource, lp: [topic_link, topic_item].map(&:id).join(':'))
end
end
66 changes: 66 additions & 0 deletions test/controllers/materials_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class MaterialsControllerTest < ActionController::TestCase
assert_select 'fa-commenting-o', count: 0
assert_select '.broken-link-notice', count: 0
assert_select '.archived-notice', count: 0
assert_select '.learning-path-navigation', count: 0
end
end

Expand Down Expand Up @@ -1475,4 +1476,69 @@ class MaterialsControllerTest < ActionController::TestCase
get :show, params: { id: material }
assert_response :forbidden
end

test 'should show learning path nav and link to next item' do
learning_path = learning_paths(:one)
topic_link = learning_path.topic_links.first
topic_item = topic_link.topic.material_items.first
material = topic_item.resource

get :show, params: { id: material, lp: [topic_link, topic_item].map(&:id).join(':') }

assert_response :success
assert assigns(:learning_path_topic_link)
assert assigns(:learning_path_topic_item)

next_item = assigns(:learning_path_topic_item).next_item
assert next_item

assert_select '.learning-path-navigation'
assert_select 'strong', text: 'Next:'
assert_select 'strong', text: 'Next topic:', count: 0
assert_select '.learning-path-navigation a[href=?]',
material_path(next_item.resource, lp: [topic_link, next_item].map(&:id).join(':'))
end

test 'learning path nav should link to next topic' do
learning_path = learning_paths(:one)
topic_link = learning_path.topic_links.first
topic_item = topic_link.topic.material_items.last
material = topic_item.resource

get :show, params: { id: material, lp: [topic_link, topic_item].map(&:id).join(':') }

assert_response :success
assert assigns(:learning_path_topic_link)
assert assigns(:learning_path_topic_item)

next_topic = assigns(:learning_path_topic_link).next_topic
assert next_topic
refute assigns(:learning_path_topic_item).next_item

assert_select '.learning-path-navigation'
assert_select 'strong', text: 'Next:', count: 0
assert_select 'strong', text: 'Next topic:'
assert_select '.learning-path-navigation a[href=?]',
learning_path_path(learning_path, anchor: "topic-#{next_topic.id}")
end

test 'learning path nav should indicate if final item in learning path' do
learning_path = learning_paths(:one)
topic_link = learning_path.topic_links.last
topic_item = topic_link.topic.material_items.last
material = topic_item.resource

get :show, params: { id: material, lp: [topic_link, topic_item].map(&:id).join(':') }

assert_response :success
assert assigns(:learning_path_topic_link)
assert assigns(:learning_path_topic_item)
refute assigns(:learning_path_topic_link).next_topic
refute assigns(:learning_path_topic_item).next_item

assert_select '.learning-path-navigation'
assert_select 'strong', text: 'Next:', count: 0
assert_select 'strong', text: 'Next topic:', count: 0
assert_select 'span.empty', text: 'End of learning path'
end
end

0 comments on commit 9898a1b

Please sign in to comment.