Commit c984d1a6 authored by Miguel Rincon's avatar Miguel Rincon

Add group runners test cases

This change ports the existing test cases that covered
Group -> Settings -> CI/CD -> Runners to the new UI at Group -> Runners

Some tests are refactored so they are reused by admin runners feature
tests as well.
parent 9f1bdb0a
......@@ -3,11 +3,11 @@
require 'spec_helper'
RSpec.describe "Admin Runners" do
include StubENV
include Spec::Support::Helpers::Features::RunnersHelpers
let_it_be(:admin) { create(:admin) }
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
admin = create(:admin)
sign_in(admin)
gitlab_enable_admin_mode_sign_in(admin)
......@@ -20,47 +20,54 @@ RSpec.describe "Admin Runners" do
let_it_be(:namespace) { create(:namespace) }
let_it_be(:project) { create(:project, namespace: namespace, creator: user) }
context "when there are runners" do
it 'has all necessary texts' do
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: Time.zone.now)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.week.ago)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.year.ago)
context "runners registration" do
before do
visit admin_runners_path
expect(page).to have_text "Register an instance runner"
expect(page).to have_text "Online runners 1"
expect(page).to have_text "Offline runners 2"
expect(page).to have_text "Stale runners 1"
end
it 'with an instance runner shows an instance badge' do
runner = create(:ci_runner, :instance)
it_behaves_like "shows and resets runner registration token" do
let(:dropdown_text) { 'Register an instance runner' }
let(:registration_token) { Gitlab::CurrentSettings.runners_registration_token }
end
end
visit admin_runners_path
context "when there are runners" do
context "with an instance runner" do
let!(:instance_runner) { create(:ci_runner, :instance) }
within "[data-testid='runner-row-#{runner.id}']" do
expect(page).to have_selector '.badge', text: 'shared'
before do
visit admin_runners_path
end
end
it 'with a group runner shows a group badge' do
runner = create(:ci_runner, :group, groups: [group])
it_behaves_like 'shows runner in list' do
let(:runner) { instance_runner }
end
visit admin_runners_path
it_behaves_like 'pauses, resumes and deletes a runner' do
let(:runner) { instance_runner }
end
within "[data-testid='runner-row-#{runner.id}']" do
expect(page).to have_selector '.badge', text: 'group'
it 'shows an instance badge' do
within_runner_row(instance_runner.id) do
expect(page).to have_selector '.badge', text: 'shared'
end
end
end
it 'with a project runner shows a project badge' do
runner = create(:ci_runner, :project, projects: [project])
context "with multiple runners" do
before do
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: Time.zone.now)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.week.ago)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.year.ago)
visit admin_runners_path
visit admin_runners_path
end
within "[data-testid='runner-row-#{runner.id}']" do
expect(page).to have_selector '.badge', text: 'specific'
it 'has all necessary texts' do
expect(page).to have_text "Register an instance runner"
expect(page).to have_text "Online runners 1"
expect(page).to have_text "Offline runners 2"
expect(page).to have_text "Stale runners 1"
end
end
......@@ -72,44 +79,8 @@ RSpec.describe "Admin Runners" do
visit admin_runners_path
within "[data-testid='runner-row-#{runner.id}'] [data-label='Jobs']" do
expect(page).to have_content '2'
end
end
describe 'delete runner' do
let!(:runner) { create(:ci_runner, description: 'runner-foo') }
before do
visit admin_runners_path
within "[data-testid='runner-row-#{runner.id}']" do
click_on 'Delete runner'
end
end
it 'shows a confirmation modal' do
expect(page).to have_text "Delete runner ##{runner.id} (#{runner.short_sha})?"
expect(page).to have_text "Are you sure you want to continue?"
end
it 'deletes a runner' do
within '.modal' do
click_on 'Delete runner'
end
expect(page.find('.gl-toast')).to have_text(/Runner .+ deleted/)
expect(page).not_to have_content 'runner-foo'
end
it 'cancels runner deletion' do
within '.modal' do
click_on 'Cancel'
end
wait_for_requests
expect(page).to have_content 'runner-foo'
within_runner_row(runner.id) do
expect(find("[data-label='Jobs']")).to have_content '2'
end
end
......@@ -249,7 +220,7 @@ RSpec.describe "Admin Runners" do
expect(page).not_to have_content 'runner-paused'
expect(page).to have_content 'runner-never-contacted'
within "[data-testid='runner-row-#{never_contacted.id}']" do
within_runner_row(never_contacted.id) do
expect(page).to have_selector '.badge', text: 'never contacted'
end
end
......@@ -447,15 +418,7 @@ RSpec.describe "Admin Runners" do
visit admin_runners_path
end
it 'has all necessary texts including no runner message' do
expect(page).to have_text "Register an instance runner"
expect(page).to have_text "Online runners 0"
expect(page).to have_text "Offline runners 0"
expect(page).to have_text "Stale runners 0"
expect(page).to have_text 'No runners found'
end
it_behaves_like "shows no runners"
it 'shows tabs with total counts equal to 0' do
expect(page).to have_link('All 0')
......@@ -484,17 +447,6 @@ RSpec.describe "Admin Runners" do
expect(page).to have_current_path(admin_runners_path('paused[]': 'true') )
end
end
describe "runners registration" do
before do
visit admin_runners_path
end
it_behaves_like "shows and resets runner registration token" do
let(:dropdown_text) { 'Register an instance runner' }
let(:registration_token) { Gitlab::CurrentSettings.runners_registration_token }
end
end
end
describe "Runner show page", :js do
......@@ -644,57 +596,4 @@ RSpec.describe "Admin Runners" do
end
end
end
private
def search_bar_selector
'[data-testid="runners-filtered-search"]'
end
# The filters must be clicked first to be able to receive events
# See: https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1493
def focus_filtered_search
page.within(search_bar_selector) do
page.find('.gl-filtered-search-term-token').click
end
end
def input_filtered_search_keys(search_term)
focus_filtered_search
page.within(search_bar_selector) do
page.find('input').send_keys(search_term)
click_on 'Search'
end
wait_for_requests
end
def open_filtered_search_suggestions(filter)
focus_filtered_search
page.within(search_bar_selector) do
click_on filter
end
wait_for_requests
end
def input_filtered_search_filter_is_only(filter, value)
focus_filtered_search
page.within(search_bar_selector) do
click_on filter
# For OPERATOR_IS_ONLY, clicking the filter
# immediately preselects "=" operator
page.find('input').send_keys(value)
page.find('input').send_keys(:enter)
click_on 'Search'
end
wait_for_requests
end
end
......@@ -3,10 +3,11 @@
require 'spec_helper'
RSpec.describe "Group Runners" do
include Spec::Support::Helpers::Features::RunnersHelpers
let_it_be(:group_owner) { create(:user) }
let_it_be(:group) { create(:group) }
let!(:group_registration_token) { group.runners_token }
let_it_be(:project) { create(:project, group: group) }
before do
group.add_owner(group_owner)
......@@ -14,7 +15,9 @@ RSpec.describe "Group Runners" do
end
describe "Group runners page", :js do
describe "runners registration" do
let!(:group_registration_token) { group.runners_token }
context "runners registration" do
before do
visit group_runners_path(group)
end
......@@ -24,5 +27,142 @@ RSpec.describe "Group Runners" do
let(:registration_token) { group_registration_token }
end
end
context "with no runners" do
before do
visit group_runners_path(group)
end
it_behaves_like "shows no runners"
it 'shows tabs with total counts equal to 0' do
expect(page).to have_link('All 0')
expect(page).to have_link('Group 0')
expect(page).to have_link('Project 0')
end
end
context "with an online group runner" do
let!(:group_runner) do
create(:ci_runner, :group, groups: [group], description: 'runner-foo', contacted_at: Time.zone.now)
end
before do
visit group_runners_path(group)
end
it_behaves_like 'shows runner in list' do
let(:runner) { group_runner }
end
it_behaves_like 'pauses, resumes and deletes a runner' do
let(:runner) { group_runner }
end
it 'shows a group badge' do
within_runner_row(group_runner.id) do
expect(page).to have_selector '.badge', text: 'group'
end
end
it 'can edit runner information' do
within_runner_row(group_runner.id) do
expect(find_link('Edit')[:href]).to end_with(edit_group_runner_path(group, group_runner))
end
end
end
context "with an online project runner" do
let!(:project_runner) do
create(:ci_runner, :project, projects: [project], description: 'runner-bar', contacted_at: Time.zone.now)
end
before do
visit group_runners_path(group)
end
it_behaves_like 'shows runner in list' do
let(:runner) { project_runner }
end
it_behaves_like 'pauses, resumes and deletes a runner' do
let(:runner) { project_runner }
end
it 'shows a project (specific) badge' do
within_runner_row(project_runner.id) do
expect(page).to have_selector '.badge', text: 'specific'
end
end
it 'can edit runner information' do
within_runner_row(project_runner.id) do
expect(find_link('Edit')[:href]).to end_with(edit_group_runner_path(group, project_runner))
end
end
end
context 'with a multi-project runner' do
let(:project) { create(:project, group: group) }
let(:project_2) { create(:project, group: group) }
let!(:runner) { create(:ci_runner, :project, projects: [project, project_2], description: 'group-runner') }
it 'user cannot remove the project runner' do
visit group_runners_path(group)
within_runner_row(runner.id) do
expect(page).to have_button 'Delete runner', disabled: true
end
end
end
context 'filtered search' do
before do
visit group_runners_path(group)
end
it 'allows user to search by paused and status', :js do
focus_filtered_search
page.within(search_bar_selector) do
expect(page).to have_link('Paused')
expect(page).to have_content('Status')
end
end
end
end
describe "Group runner edit page", :js do
let!(:runner) do
create(:ci_runner, :group, groups: [group], description: 'runner-foo', contacted_at: Time.zone.now)
end
it 'user edits the runner to be protected' do
visit edit_group_runner_path(group, runner)
expect(page.find_field('runner[access_level]')).not_to be_checked
check 'runner_access_level'
click_button 'Save changes'
expect(page).to have_content 'Protected Yes'
end
context 'when a runner has a tag' do
before do
runner.update!(tag_list: ['tag'])
end
it 'user edits runner not to run untagged jobs' do
visit edit_group_runner_path(group, runner)
expect(page.find_field('runner[run_untagged]')).to be_checked
uncheck 'runner_run_untagged'
click_button 'Save changes'
expect(page).to have_content 'Can run untagged jobs No'
end
end
end
end
# frozen_string_literal: true
module Spec
module Support
module Helpers
module Features
module RunnersHelpers
def within_runner_row(runner_id)
within "[data-testid='runner-row-#{runner_id}']" do
yield
end
end
def search_bar_selector
'[data-testid="runners-filtered-search"]'
end
# The filters must be clicked first to be able to receive events
# See: https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1493
def focus_filtered_search
page.within(search_bar_selector) do
page.find('.gl-filtered-search-term-token').click
end
end
def input_filtered_search_keys(search_term)
focus_filtered_search
page.within(search_bar_selector) do
page.find('input').send_keys(search_term)
click_on 'Search'
end
wait_for_requests
end
def open_filtered_search_suggestions(filter)
focus_filtered_search
page.within(search_bar_selector) do
click_on filter
end
wait_for_requests
end
def input_filtered_search_filter_is_only(filter, value)
focus_filtered_search
page.within(search_bar_selector) do
click_on filter
# For OPERATOR_IS_ONLY, clicking the filter
# immediately preselects "=" operator
page.find('input').send_keys(value)
page.find('input').send_keys(:enter)
click_on 'Search'
end
wait_for_requests
end
end
end
end
end
end
......@@ -2,6 +2,7 @@
RSpec.shared_examples 'shows and resets runner registration token' do
include Spec::Support::Helpers::ModalHelpers
include Spec::Support::Helpers::Features::RunnersHelpers
before do
click_on dropdown_text
......@@ -60,3 +61,81 @@ RSpec.shared_examples 'shows and resets runner registration token' do
end
end
end
RSpec.shared_examples 'shows no runners' do
it 'shows counts with 0' do
expect(page).to have_text "Online runners 0"
expect(page).to have_text "Offline runners 0"
expect(page).to have_text "Stale runners 0"
end
it 'shows "no runners" message' do
expect(page).to have_text 'No runners found'
end
end
RSpec.shared_examples 'shows runner in list' do
it 'does not show empty state' do
expect(page).not_to have_content 'No runners found'
end
it 'shows runner row' do
within_runner_row(runner.id) do
expect(page).to have_text "##{runner.id}"
expect(page).to have_text runner.short_sha
expect(page).to have_text runner.description
end
end
end
RSpec.shared_examples 'pauses, resumes and deletes a runner' do
include Spec::Support::Helpers::ModalHelpers
it 'pauses and resumes runner' do
within_runner_row(runner.id) do
click_button "Pause"
expect(page).to have_text 'paused'
expect(page).to have_button 'Resume'
expect(page).not_to have_button 'Pause'
click_button "Resume"
expect(page).not_to have_text 'paused'
expect(page).not_to have_button 'Resume'
expect(page).to have_button 'Pause'
end
end
describe 'deletes runner' do
before do
within_runner_row(runner.id) do
click_on 'Delete runner'
end
end
it 'shows a confirmation modal' do
expect(page).to have_text "Delete runner ##{runner.id} (#{runner.short_sha})?"
expect(page).to have_text "Are you sure you want to continue?"
end
it 'deletes a runner' do
within_modal do
click_on 'Delete runner'
end
expect(page.find('.gl-toast')).to have_text(/Runner .+ deleted/)
expect(page).not_to have_content runner.description
end
it 'cancels runner deletion' do
within_modal do
click_on 'Cancel'
end
wait_for_requests
expect(page).to have_content runner.description
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