From 9898a1b1da89f5d81dc37de20fb7dca71a9e87e4 Mon Sep 17 00:00:00 2001 From: Finn Bacall Date: Fri, 25 Oct 2024 17:36:03 +0100 Subject: [PATCH] Tests for learning path nav box --- .../learning_paths_controller_test.rb | 11 ++++ test/controllers/materials_controller_test.rb | 66 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/test/controllers/learning_paths_controller_test.rb b/test/controllers/learning_paths_controller_test.rb index 81a21b72b..2733fded6 100644 --- a/test/controllers/learning_paths_controller_test.rb +++ b/test/controllers/learning_paths_controller_test.rb @@ -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 diff --git a/test/controllers/materials_controller_test.rb b/test/controllers/materials_controller_test.rb index aa7e41464..1289c4cb9 100644 --- a/test/controllers/materials_controller_test.rb +++ b/test/controllers/materials_controller_test.rb @@ -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 @@ -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