From 22841f590866a13f61cb52e10ef40a27c17d3db8 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Thu, 22 Aug 2024 17:47:26 +0300 Subject: [PATCH] Convert dashboard test into a system test Allows to remove an id used only for testing. --- app/views/dashboards/show.html.erb | 2 +- .../controllers/dashboards_controller_test.rb | 24 ----------------- test/system/dashboard_test.rb | 27 +++++++++++++++++++ 3 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 test/system/dashboard_test.rb diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb index 6b988a8ec..c4b595e9b 100644 --- a/app/views/dashboards/show.html.erb +++ b/app/views/dashboards/show.html.erb @@ -38,7 +38,7 @@
  • <%= link_to t(".friends_diaries"), friends_diary_entries_path %>
  • -
    +
    <%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %>
    <% end %> diff --git a/test/controllers/dashboards_controller_test.rb b/test/controllers/dashboards_controller_test.rb index 84f9610e5..0adf58a9e 100644 --- a/test/controllers/dashboards_controller_test.rb +++ b/test/controllers/dashboards_controller_test.rb @@ -9,28 +9,4 @@ class DashboardsControllerTest < ActionDispatch::IntegrationTest { :controller => "dashboards", :action => "show" } ) end - - def test_show_no_friends - user = create(:user) - session_for(user) - - get dashboard_path - end - - def test_show_with_friends - user = create(:user, :home_lon => 1.1, :home_lat => 1.1) - friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2) - create(:friendship, :befriender => user, :befriendee => friend_user) - create(:changeset, :user => friend_user) - session_for(user) - - get dashboard_path - - # Friends should be visible as we're now logged in - assert_select "div#friends-container" do - assert_select "div" do - assert_select "a[href='/user/#{ERB::Util.u(friend_user.display_name)}']", :count => 1 - end - end - end end diff --git a/test/system/dashboard_test.rb b/test/system/dashboard_test.rb new file mode 100644 index 000000000..bc2e3b4e9 --- /dev/null +++ b/test/system/dashboard_test.rb @@ -0,0 +1,27 @@ +require "application_system_test_case" + +class DashboardSystemTest < ApplicationSystemTestCase + test "show no users if have no friends" do + user = create(:user) + sign_in_as(user) + + visit dashboard_path + assert_text "You have not added any friends yet." + end + + test "show users if have friends" do + user = create(:user, :home_lon => 1.1, :home_lat => 1.1) + friend_user = create(:user, :home_lon => 1.2, :home_lat => 1.2) + create(:friendship, :befriender => user, :befriendee => friend_user) + create(:changeset, :user => friend_user) + sign_in_as(user) + + visit dashboard_path + assert_no_text "You have not added any friends yet." + + friends_heading = find :element, "h2", :text => "My friends" + others_heading = find :element, "h2", :text => "Other nearby users" + + assert_link friend_user.display_name, :below => friends_heading, :above => others_heading + end +end -- 2.39.5