1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Monitor dropdown sidebar', :js, feature_category: :shared do
let_it_be_with_reload(:project) { create(:project, :internal, :repository) }
let_it_be(:user) { create(:user) }
let(:role) { nil }
before do
project.add_role(user, role) if role
sign_in(user)
project.update!(service_desk_enabled: true)
allow(Gitlab::ServiceDesk).to receive(:supported?).and_return(true)
end
shared_examples 'shows common Monitor menu item based on the access level' do
using RSpec::Parameterized::TableSyntax
let(:enabled) { Featurable::PRIVATE }
let(:disabled) { Featurable::DISABLED }
where(:monitor_level, :render) do
ref(:enabled) | true
ref(:disabled) | false
end
with_them do
it 'renders when expected to' do
project.project_feature.update_attribute(:monitor_access_level, monitor_level)
visit project_issues_path(project)
click_button('Monitor')
within_testid('super-sidebar') do
if render
expect(page).to have_link('Incidents')
else
expect(page).not_to have_link('Incidents', visible: :all)
end
end
end
end
end
context 'when user is not a member' do
let(:access_level) { ProjectFeature::PUBLIC }
before do
project.project_feature.update_attribute(:monitor_access_level, access_level)
visit project_issues_path(project)
click_button('Monitor')
end
it 'has the correct `Monitor` and `Operate` menu items' do
expect(page).to have_link('Incidents', href: project_incidents_path(project))
click_button('Operate')
expect(page).to have_link('Environments', href: project_environments_path(project))
expect(page).not_to have_link('Alerts', href: project_alert_management_index_path(project), visible: :all)
expect(page).not_to have_link('Error Tracking', href: project_error_tracking_index_path(project), visible: :all)
expect(page).not_to have_link('Kubernetes clusters', href: project_clusters_path(project), visible: :all)
end
context 'when monitor project feature is PRIVATE' do
let(:access_level) { ProjectFeature::PRIVATE }
it 'does not show common items of the `Monitor` menu' do
expect(page).not_to have_link('Error Tracking', href: project_incidents_path(project), visible: :all)
end
end
context 'when monitor project feature is DISABLED' do
let(:access_level) { ProjectFeature::DISABLED }
it 'does not show the `Incidents` menu' do
expect(page).not_to have_link('Error Tracking', href: project_incidents_path(project), visible: :all)
end
end
end
context 'when user has guest role' do
let(:role) { :guest }
it 'has the correct `Monitor` and `Operate` menu items' do
visit project_issues_path(project)
click_button('Monitor')
expect(page).to have_link('Incidents', href: project_incidents_path(project))
click_button('Operate')
expect(page).to have_link('Environments', href: project_environments_path(project))
expect(page).not_to have_link('Alerts', href: project_alert_management_index_path(project), visible: :all)
expect(page).not_to have_link('Error Tracking', href: project_error_tracking_index_path(project), visible: :all)
expect(page).not_to have_link('Kubernetes clusters', href: project_clusters_path(project), visible: :all)
end
it_behaves_like 'shows common Monitor menu item based on the access level'
end
context 'when user has reporter role' do
let(:role) { :reporter }
it 'has the correct `Monitor` and `Operate` menu items' do
visit project_issues_path(project)
click_button('Monitor')
expect(page).to have_link('Incidents', href: project_incidents_path(project))
expect(page).to have_link('Error Tracking', href: project_error_tracking_index_path(project))
click_button('Operate')
expect(page).to have_link('Environments', href: project_environments_path(project))
expect(page).not_to have_link('Alerts', href: project_alert_management_index_path(project), visible: :all)
expect(page).not_to have_link('Kubernetes clusters', href: project_clusters_path(project), visible: :all)
end
it_behaves_like 'shows common Monitor menu item based on the access level'
end
context 'when user has developer role' do
let(:role) { :developer }
it 'has the correct `Monitor` and `Operate` menu items' do
visit project_issues_path(project)
click_button('Monitor')
expect(page).to have_link('Alerts', href: project_alert_management_index_path(project))
expect(page).to have_link('Incidents', href: project_incidents_path(project))
expect(page).to have_link('Error Tracking', href: project_error_tracking_index_path(project))
click_button('Operate')
expect(page).to have_link('Environments', href: project_environments_path(project))
expect(page).to have_link('Kubernetes clusters', href: project_clusters_path(project))
end
it_behaves_like 'shows common Monitor menu item based on the access level'
end
context 'when user has maintainer role' do
let(:role) { :maintainer }
it 'has the correct `Monitor` and `Operate` menu items' do
visit project_issues_path(project)
click_button('Monitor')
expect(page).to have_link('Alerts', href: project_alert_management_index_path(project))
expect(page).to have_link('Incidents', href: project_incidents_path(project))
expect(page).to have_link('Error Tracking', href: project_error_tracking_index_path(project))
click_button('Operate')
expect(page).to have_link('Environments', href: project_environments_path(project))
expect(page).to have_link('Kubernetes clusters', href: project_clusters_path(project))
end
it_behaves_like 'shows common Monitor menu item based on the access level'
end
end
|