Commit 2ea69008 authored by James Lopez's avatar James Lopez

Merge branch '50626-searching-users-by-the-admin-panel-wipes-query-when-using-sort' into 'master'

Resolve "Searching users by the admin panel wipes query when using sort"

Closes #50626

See merge request gitlab-org/gitlab-ce!23439
parents 40df6352 ad551e5e
...@@ -120,6 +120,18 @@ module SortingHelper ...@@ -120,6 +120,18 @@ module SortingHelper
} }
end end
def users_sort_options_hash
{
sort_value_name => sort_title_name,
sort_value_recently_signin => sort_title_recently_signin,
sort_value_oldest_signin => sort_title_oldest_signin,
sort_value_recently_created => sort_title_recently_created,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_recently_updated => sort_title_recently_updated,
sort_value_oldest_updated => sort_title_oldest_updated
}
end
def sortable_item(item, path, sorted_by) def sortable_item(item, path, sorted_by)
link_to item, path, class: sorted_by == item ? 'is-active' : '' link_to item, path, class: sorted_by == item ? 'is-active' : ''
end end
......
...@@ -9,28 +9,20 @@ ...@@ -9,28 +9,20 @@
.search-holder .search-holder
.search-field-holder .search-field-holder
= search_field_tag :search_query, params[:search_query], placeholder: 'Search by name, email or username', class: 'form-control search-text-input js-search-input', spellcheck: false = search_field_tag :search_query, params[:search_query], placeholder: 'Search by name, email or username', class: 'form-control search-text-input js-search-input', spellcheck: false
- if @sort.present?
= hidden_field_tag :sort, @sort
= icon("search", class: "search-icon") = icon("search", class: "search-icon")
.dropdown = button_tag 'Search users' if Rails.env.test?
- toggle_text = if @sort.present? then sort_options_hash[@sort] else sort_title_name end .dropdown.user-sort-dropdown
- toggle_text = if @sort.present? then users_sort_options_hash[@sort] else sort_title_name end
= dropdown_toggle(toggle_text, { toggle: 'dropdown' }) = dropdown_toggle(toggle_text, { toggle: 'dropdown' })
%ul.dropdown-menu.dropdown-menu-right %ul.dropdown-menu.dropdown-menu-right
%li.dropdown-header %li.dropdown-header
Sort by Sort by
%li %li
= link_to admin_users_path(sort: sort_value_name, filter: params[:filter]) do - users_sort_options_hash.each do |value, title|
= sort_title_name = link_to admin_users_path(sort: value, filter: params[:filter], search_query: params[:search_query]) do
= link_to admin_users_path(sort: sort_value_recently_signin, filter: params[:filter]) do = title
= sort_title_recently_signin
= link_to admin_users_path(sort: sort_value_oldest_signin, filter: params[:filter]) do
= sort_title_oldest_signin
= link_to admin_users_path(sort: sort_value_recently_created, filter: params[:filter]) do
= sort_title_recently_created
= link_to admin_users_path(sort: sort_value_oldest_created, filter: params[:filter]) do
= sort_title_oldest_created
= link_to admin_users_path(sort: sort_value_recently_updated, filter: params[:filter]) do
= sort_title_recently_updated
= link_to admin_users_path(sort: sort_value_oldest_updated, filter: params[:filter]) do
= sort_title_oldest_updated
= link_to 'New user', new_admin_user_path, class: 'btn btn-success btn-search' = link_to 'New user', new_admin_user_path, class: 'btn btn-success btn-search'
.top-area.scrolling-tabs-container.inner-page-scroll-tabs .top-area.scrolling-tabs-container.inner-page-scroll-tabs
......
---
title: Allow search and sort users at same time on admin users page
merge_request: 23439
author:
type: fixed
require 'spec_helper' require 'spec_helper'
describe "Admin::Users" do describe "Admin::Users" do
include Spec::Support::Helpers::Features::ListRowsHelpers
let!(:user) do let!(:user) do
create(:omniauth_user, provider: 'twitter', extern_uid: '123456') create(:omniauth_user, provider: 'twitter', extern_uid: '123456')
end end
...@@ -30,6 +32,51 @@ describe "Admin::Users" do ...@@ -30,6 +32,51 @@ describe "Admin::Users" do
expect(page).to have_button('Delete user and contributions') expect(page).to have_button('Delete user and contributions')
end end
describe 'search and sort' do
before do
create(:user, name: 'Foo Bar')
create(:user, name: 'Foo Baz')
create(:user, name: 'Dmitriy')
end
it 'searches users by name' do
visit admin_users_path(search_query: 'Foo')
expect(page).to have_content('Foo Bar')
expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
it 'sorts users by name' do
visit admin_users_path
sort_by('Name')
expect(first_row.text).to include('Dmitriy')
expect(second_row.text).to include('Foo Bar')
end
it 'sorts search results only' do
visit admin_users_path(search_query: 'Foo')
sort_by('Name')
expect(page).not_to have_content('Dmitriy')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'searches with respect of sorting' do
visit admin_users_path(sort: 'Name')
fill_in :search_query, with: 'Foo'
click_button('Search users')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
end
describe 'Two-factor Authentication filters' do describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do it 'counts users who have enabled 2FA' do
create(:user, :two_factor) create(:user, :two_factor)
...@@ -566,4 +613,10 @@ describe "Admin::Users" do ...@@ -566,4 +613,10 @@ describe "Admin::Users" do
def check_breadcrumb(content) def check_breadcrumb(content)
expect(find('.breadcrumbs-sub-title')).to have_content(content) expect(find('.breadcrumbs-sub-title')).to have_content(content)
end end
def sort_by(text)
page.within('.user-sort-dropdown') do
click_link text
end
end
end end
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Groups > Members > List members' do describe 'Groups > Members > List members' do
include Select2Helper include Select2Helper
include Spec::Support::Helpers::Features::ListRowsHelpers
let(:user1) { create(:user, name: 'John Doe') } let(:user1) { create(:user, name: 'John Doe') }
let(:user2) { create(:user, name: 'Mary Jane') } let(:user2) { create(:user, name: 'Mary Jane') }
...@@ -43,12 +44,4 @@ describe 'Groups > Members > List members' do ...@@ -43,12 +44,4 @@ describe 'Groups > Members > List members' do
let(:user_with_status) { user2 } let(:user_with_status) { user2 }
end end
end end
def first_row
page.all('ul.content-list > li')[0]
end
def second_row
page.all('ul.content-list > li')[1]
end
end end
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Groups > Members > Manage members' do describe 'Groups > Members > Manage members' do
include Select2Helper include Select2Helper
include Spec::Support::Helpers::Features::ListRowsHelpers
let(:user1) { create(:user, name: 'John Doe') } let(:user1) { create(:user, name: 'John Doe') }
let(:user2) { create(:user, name: 'Mary Jane') } let(:user2) { create(:user, name: 'Mary Jane') }
...@@ -119,14 +120,6 @@ describe 'Groups > Members > Manage members' do ...@@ -119,14 +120,6 @@ describe 'Groups > Members > Manage members' do
end end
end end
def first_row
page.all('ul.content-list > li')[0]
end
def second_row
page.all('ul.content-list > li')[1]
end
def add_user(id, role) def add_user(id, role)
page.within ".users-group-form" do page.within ".users-group-form" do
select2(id, from: "#user_ids", multiple: true) select2(id, from: "#user_ids", multiple: true)
......
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Project members list' do describe 'Project members list' do
include Select2Helper include Select2Helper
include Spec::Support::Helpers::Features::ListRowsHelpers
let(:user1) { create(:user, name: 'John Doe') } let(:user1) { create(:user, name: 'John Doe') }
let(:user2) { create(:user, name: 'Mary Jane') } let(:user2) { create(:user, name: 'Mary Jane') }
...@@ -83,14 +84,6 @@ describe 'Project members list' do ...@@ -83,14 +84,6 @@ describe 'Project members list' do
end end
end end
def first_row
page.all('ul.content-list > li')[0]
end
def second_row
page.all('ul.content-list > li')[1]
end
def add_user(id, role) def add_user(id, role)
page.within ".users-project-form" do page.within ".users-project-form" do
select2(id, from: "#user_ids", multiple: true) select2(id, from: "#user_ids", multiple: true)
......
# frozen_string_literal: true
# These helpers allow you to access rows in the list
#
# Usage:
# describe "..." do
# include Spec::Support::Helpers::Features::ListRowsHelpers
# ...
#
# expect(first_row.text).to include("John Doe")
# expect(second_row.text).to include("John Smith")
#
module Spec
module Support
module Helpers
module Features
module ListRowsHelpers
def first_row
page.all('ul.content-list > li')[0]
end
def second_row
page.all('ul.content-list > li')[1]
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment