diff --git a/app/views/account/users/index.html.slim b/app/views/account/users/index.html.slim index fab9c17ef..2ae08e07a 100644 --- a/app/views/account/users/index.html.slim +++ b/app/views/account/users/index.html.slim @@ -15,15 +15,16 @@ div class="container home" td = t '.table.edit' td = t '.table.ban' td = t '.table.delete' - - @users.each do |user| - tr id="user-info-#{user.id}" - td = user.email - td = user.last_sign_in_at - td = link_to icon('fa-solid', 'eye'), account_user_path(id: user.id) - td = link_to icon('fa-solid', 'edit'), edit_account_user_path(id: user.id) - td = link_to (icon('fa-solid', user.blocked? ? 'lock' : 'lock-open')), - account_user_path(id: user, user: {blocked: user.blocked? ? false : true}), - onclick: "alert('Are you sure?')", method: :patch - td = link_to account_user_path(id: user), method: :delete, - data: { confirm: t('.confirm_delete') } do - i.fa.fa-trash.mx-2 + tbody id="users" + - @users.each do |user| + tr id="user-info-#{user.id}" + td = user.email + td = user.last_sign_in_at + td = link_to icon('fa-solid', 'eye'), account_user_path(id: user.id) + td = link_to icon('fa-solid', 'edit'), edit_account_user_path(id: user.id) + td = link_to (icon('fa-solid', user.blocked? ? 'lock' : 'lock-open')), + account_user_path(id: user, user: {blocked: user.blocked? ? false : true}), + onclick: "alert('Are you sure?')", method: :patch + td = link_to account_user_path(id: user), method: :delete, + data: { confirm: t('.confirm_delete') } do + i.fa.fa-trash.mx-2 diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index eb923acb2..4336bf37f 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -4,10 +4,7 @@ describe "visit admin page", js: true do let(:time_login) { Time.new(2020, 0o1, 0o1).utc } - let!(:another_user) do - create(:user, email: "test1@gmail.com", password: "12345878", - last_sign_in_at: time_login) - end + let!(:users) { create_list(:user, 5, last_sign_in_at: time_login) } before do @admin = create(:user, :admin) @@ -16,18 +13,34 @@ it "visits admin page" do visit account_users_path - expect(page).to have_content "test1@gmail.com" + expect(page).to have_content users.first.email expect(page).to have_content time_login end + context "with sorting" do + it "by id asc" do + visit account_users_path(sort: "id asc") + + expect(page.find("#users > :first-child > :first-child")).to have_content User.first.email + expect(page.find("#users > :last-child > :first-child")).to have_content User.last.email + end + + it "by id desc" do + visit account_users_path(sort: "id desc") + + expect(page.find("#users > :first-child > :first-child")).to have_content User.last.email + expect(page.find("#users > :last-child > :first-child")).to have_content User.first.email + end + end + context "when user clicks show icon" do it "redirects to user info page" do visit account_users_path - within(:css, "#user-info-#{another_user.id}") do + within(:css, "#user-info-#{users.first.id}") do find(".fa-eye", visible: :all).click sleep 3 end - expect(page).to have_current_path(account_user_path(id: another_user.id)) + expect(page).to have_current_path(account_user_path(id: users.first.id)) expect(page).to have_content "Email" expect(page).to have_content "First name" expect(page).to have_content "Last name" @@ -41,11 +54,11 @@ context "when user clicks edit icon" do it "redirects to user edit info page" do visit account_users_path - within(:css, "#user-info-#{another_user.id}") do - click_link(href: edit_account_user_path(id: another_user.id)) + within(:css, "#user-info-#{users.first.id}") do + click_link(href: edit_account_user_path(id: users.first.id)) sleep 3 end - expect(page).to have_current_path(edit_account_user_path(id: another_user.id)) + expect(page).to have_current_path(edit_account_user_path(id: users.first.id)) expect(page).to have_content "First name" expect(page).to have_content "Last name" expect(page).to have_content "Country" @@ -56,14 +69,14 @@ context "when edit user`s info correctly" do it "redirects to user info page" do - visit edit_account_user_path(id: another_user.id) + visit edit_account_user_path(id: users.first.id) find("#user_first_name").set("John") find("#user_last_name").set("Doe") select "Albania", from: "user_country" find("#user_password").set("111111111") find("#user_password_confirmation").set("111111111") find_button("commit").click - expect(page).to have_current_path(account_user_path(id: another_user.id)) + expect(page).to have_current_path(account_user_path(id: users.first.id)) expect(page).to have_content "John" expect(page).to have_content "Doe" expect(page).to have_content "AL" @@ -72,7 +85,7 @@ context "when edit user`s info wrongly" do it "show error messages" do - visit edit_account_user_path(id: another_user.id) + visit edit_account_user_path(id: users.first.id) find("#user_first_name").set("J") find("#user_last_name").set("D") select "Albania", from: "user_country" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 531b87a0c..5441fdd06 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -81,10 +81,10 @@ config.include Devise::Test::IntegrationHelpers, type: :helper config.include Devise::Test::ControllerHelpers, type: :controller + config.include Capybara::DSL, type: :request + config.add_formatter "Fuubar" config.fuubar_output_pending_results = false - - Webdrivers::Chromedriver.required_version = "114.0.5735.90" end Shoulda::Matchers.configure do |config| diff --git a/spec/requests/account/users_spec.rb b/spec/requests/account/users_spec.rb index 6c575aa3a..7dd35f711 100644 --- a/spec/requests/account/users_spec.rb +++ b/spec/requests/account/users_spec.rb @@ -13,7 +13,6 @@ expect(response).to be_successful expect(response).to render_template(:index) - expect(response.body).to include(I18n.t("account.users.index.main_header")) end end