diff options
-rw-r--r-- | app/controllers/admin/runners_controller.rb | 1 | ||||
-rw-r--r-- | app/views/admin/runners/_statuses.html.haml | 13 | ||||
-rw-r--r-- | app/views/admin/runners/index.html.haml | 18 | ||||
-rw-r--r-- | spec/features/admin/admin_runners_spec.rb | 96 |
4 files changed, 112 insertions, 16 deletions
diff --git a/app/controllers/admin/runners_controller.rb b/app/controllers/admin/runners_controller.rb index 6c76c55a9d4..ef2f9fadca0 100644 --- a/app/controllers/admin/runners_controller.rb +++ b/app/controllers/admin/runners_controller.rb @@ -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 diff --git a/app/views/admin/runners/_statuses.html.haml b/app/views/admin/runners/_statuses.html.haml new file mode 100644 index 00000000000..4e91b6be6c4 --- /dev/null +++ b/app/views/admin/runners/_statuses.html.haml @@ -0,0 +1,13 @@ +- 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) diff --git a/app/views/admin/runners/index.html.haml b/app/views/admin/runners/index.html.haml index 9280ff4d478..81dfc23641b 100644 --- a/app/views/admin/runners/index.html.haml +++ b/app/views/admin/runners/index.html.haml @@ -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 diff --git a/spec/features/admin/admin_runners_spec.rb b/spec/features/admin/admin_runners_spec.rb index 5623e47eadf..d44cea47a9f 100644 --- a/spec/features/admin/admin_runners_spec.rb +++ b/spec/features/admin/admin_runners_spec.rb @@ -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 |