Commit 16d12491 authored by Alexis Reigel's avatar Alexis Reigel

add status filter to admin runners page

parent bbc305b1
......@@ -5,6 +5,7 @@ class Admin::RunnersController < Admin::ApplicationController
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
@runners = Ci::Runner.order(sort)
@runners = @runners.search(params[:search]) if params[:search].present?
@runners = @runners.public_send(params[:status]) if params[:status].present? && Ci::Runner::AVAILABLE_STATUSES.include?(params[:status])
@runners = @runners.page(params[:page]).per(30)
@active_runners_cnt = Ci::Runner.online.count
end
......
- active_status = params[:status].presence
- toggle_text = 'Status'
- if active_status
= hidden_field_tag :status, params[:status]
- toggle_text = params[:status].titleize
= dropdown_tag(toggle_text, options: { wrapper_class: 'dropdown-menu-selectable', title: 'Statuses' }) do
%ul
%li= link_to 'Any Status', admin_runners_path(safe_params.slice(:search)), class: ('is-active' unless active_status)
%li.divider
- Ci::Runner::AVAILABLE_STATUSES.each do |status|
%li= link_to status.titleize, admin_runners_path(safe_params.slice(:search).merge(status: status)), class: ('is-active' if active_status == status)
......@@ -42,14 +42,18 @@
locals: { registration_token: Gitlab::CurrentSettings.runners_registration_token }
.append-bottom-20.clearfix
.float-left
= form_tag admin_runners_path, id: 'runners-search', class: 'form-inline', method: :get do
.form-group
= search_field_tag :search, params[:search], class: 'form-control input-short', placeholder: 'Runner description or token', spellcheck: false
= submit_tag 'Search', class: 'btn'
= form_tag admin_runners_path, id: 'runners-search', method: :get do
.float-left
.form-inline
.form-group
= search_field_tag :search, params[:search], class: 'form-control input-short', placeholder: 'Runner description or token', spellcheck: false
= submit_tag 'Search', class: 'btn'
.float-left.prepend-left-10
= render 'statuses'
.float-right.light
Runners currently online: #{@active_runners_cnt}
.float-right.light
Runners currently online: #{@active_runners_cnt}
%br
......
......@@ -12,13 +12,11 @@ describe "Admin Runners" do
let(:pipeline) { create(:ci_pipeline) }
context "when there are runners" do
before do
it 'has all necessary texts' do
runner = FactoryBot.create(:ci_runner, contacted_at: Time.now)
FactoryBot.create(:ci_build, pipeline: pipeline, runner_id: runner.id)
visit admin_runners_path
end
it 'has all necessary texts' do
expect(page).to have_text "Setup a shared Runner manually"
expect(page).to have_text "Runners currently online: 1"
end
......@@ -27,25 +25,105 @@ describe "Admin Runners" do
before do
FactoryBot.create :ci_runner, description: 'runner-foo'
FactoryBot.create :ci_runner, description: 'runner-bar'
visit admin_runners_path
end
it 'shows correct runner when description matches' do
search_form = find('#runners-search')
search_form.fill_in 'search', with: 'runner-foo'
search_form.click_button 'Search'
within '#runners-search' do
fill_in 'search', with: 'runner-foo'
click_button 'Search'
end
expect(page).to have_content("runner-foo")
expect(page).not_to have_content("runner-bar")
end
it 'shows no runner when description does not match' do
search_form = find('#runners-search')
search_form.fill_in 'search', with: 'runner-baz'
search_form.click_button 'Search'
within '#runners-search' do
fill_in 'search', with: 'runner-baz'
click_button 'Search'
end
expect(page).to have_text 'No runners found'
end
end
describe 'filter by status', :js do
it 'shows correct runner when status matches' do
FactoryBot.create :ci_runner, description: 'runner-active', active: true
FactoryBot.create :ci_runner, description: 'runner-paused', active: false
visit admin_runners_path
expect(page).to have_content 'runner-active'
expect(page).to have_content 'runner-paused'
click_button 'Status'
click_link 'Active'
expect(page).to have_content 'runner-active'
expect(page).not_to have_content 'runner-paused'
end
it 'shows no runner when status does not match' do
FactoryBot.create :ci_runner, :online, description: 'runner-active', active: true
FactoryBot.create :ci_runner, :online, description: 'runner-paused', active: false
visit admin_runners_path
click_button 'Status'
click_link 'Offline'
expect(page).not_to have_content 'runner-active'
expect(page).not_to have_content 'runner-paused'
expect(page).to have_text 'No runners found'
end
end
describe 'filter by status and enter search term', :js do
before do
FactoryBot.create :ci_runner, description: 'runner-a-1', active: true
FactoryBot.create :ci_runner, description: 'runner-a-2', active: false
FactoryBot.create :ci_runner, description: 'runner-b-1', active: true
visit admin_runners_path
end
it 'shows correct runner when status is selected first and then search term is entered' do
click_button 'Status'
click_link 'Active'
expect(page).to have_content 'runner-a-1'
expect(page).to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2'
within '#runners-search' do
fill_in 'search', with: 'runner-a'
click_button 'Search'
end
expect(page).to have_content 'runner-a-1'
expect(page).not_to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2'
end
it 'shows correct runner when search term is entered first and then status is selected' do
within '#runners-search' do
fill_in 'search', with: 'runner-a'
click_button 'Search'
end
expect(page).to have_content 'runner-a-1'
expect(page).to have_content 'runner-a-2'
expect(page).not_to have_content 'runner-b-1'
click_button 'Status'
click_link 'Active'
expect(page).to have_content 'runner-a-1'
expect(page).not_to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2'
end
end
end
context "when there are no runners" do
......
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