debian-mirror-gitlab/spec/features/user_can_display_performance_bar_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

161 lines
4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe 'User can display performance bar', :js do
2018-03-17 18:26:18 +05:30
shared_examples 'performance bar cannot be displayed' do
2017-09-10 17:25:29 +05:30
it 'does not show the performance bar by default' do
2018-05-09 12:01:36 +05:30
expect(page).not_to have_css('#js-peek')
2017-09-10 17:25:29 +05:30
end
context 'when user press `pb`' do
before do
find('body').native.send_keys('pb')
end
it 'does not show the performance bar by default' do
2018-05-09 12:01:36 +05:30
expect(page).not_to have_css('#js-peek')
2017-09-10 17:25:29 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
shared_examples 'performance bar can be displayed' do
2017-09-10 17:25:29 +05:30
it 'does not show the performance bar by default' do
2018-05-09 12:01:36 +05:30
expect(page).not_to have_css('#js-peek')
2017-09-10 17:25:29 +05:30
end
context 'when user press `pb`' do
before do
find('body').native.send_keys('pb')
end
it 'shows the performance bar' do
2018-05-09 12:01:36 +05:30
expect(page).to have_css('#js-peek')
2017-09-10 17:25:29 +05:30
end
end
end
2018-03-17 18:26:18 +05:30
shared_examples 'performance bar is enabled by default in development' do
before do
2019-12-04 20:38:33 +05:30
stub_rails_env('development')
2018-03-17 18:26:18 +05:30
end
it 'shows the performance bar by default' do
refresh # Because we're stubbing Rails.env after the 1st visit to root_path
2018-05-09 12:01:36 +05:30
expect(page).to have_css('#js-peek')
2018-03-17 18:26:18 +05:30
end
end
2021-06-08 01:23:25 +05:30
let_it_be(:group) { create(:group) }
2017-09-10 17:25:29 +05:30
2021-04-17 20:07:23 +05:30
before do
allow(GitlabPerformanceBarStatsWorker).to receive(:perform_in)
end
2017-09-10 17:25:29 +05:30
context 'when user is logged-out' do
before do
visit root_path
end
context 'when the performance_bar feature is disabled' do
before do
stub_application_setting(performance_bar_allowed_group_id: nil)
end
2018-03-17 18:26:18 +05:30
it_behaves_like 'performance bar cannot be displayed'
2017-09-10 17:25:29 +05:30
end
context 'when the performance_bar feature is enabled' do
before do
stub_application_setting(performance_bar_allowed_group_id: group.id)
end
2018-03-17 18:26:18 +05:30
it_behaves_like 'performance bar cannot be displayed'
2017-09-10 17:25:29 +05:30
end
end
context 'when user is logged-in' do
before do
user = create(:user)
sign_in(user)
group.add_guest(user)
visit root_path
end
context 'when the performance_bar feature is disabled' do
before do
stub_application_setting(performance_bar_allowed_group_id: nil)
end
2018-03-17 18:26:18 +05:30
it_behaves_like 'performance bar cannot be displayed'
it_behaves_like 'performance bar is enabled by default in development'
2017-09-10 17:25:29 +05:30
end
context 'when the performance_bar feature is enabled' do
before do
stub_application_setting(performance_bar_allowed_group_id: group.id)
end
2018-03-17 18:26:18 +05:30
it_behaves_like 'performance bar is enabled by default in development'
it_behaves_like 'performance bar can be displayed'
2021-04-17 20:07:23 +05:30
it 'does not show Stats link by default' do
find('body').native.send_keys('pb')
expect(page).not_to have_link('Stats', visible: :all)
end
context 'when GITLAB_PERFORMANCE_BAR_STATS_URL environment variable is set' do
let(:stats_url) { 'https://log.gprd.gitlab.net/app/dashboards#/view/' }
before do
stub_env('GITLAB_PERFORMANCE_BAR_STATS_URL', stats_url)
end
it 'shows Stats link' do
find('body').native.send_keys('pb')
expect(page).to have_link('Stats', href: stats_url, visible: :all)
end
end
2017-09-10 17:25:29 +05:30
end
end
2021-06-08 01:23:25 +05:30
context 'flamegraphs' do
let_it_be(:user) { create(:user) }
before_all do
group.add_guest(user)
end
context 'when user has access' do
before do
stub_application_setting(performance_bar_allowed_group_id: group.id)
Warden.on_next_request do |proxy|
proxy.set_user(user)
end
end
it 'renders flamegraph when requested' do
visit root_path(performance_bar: 'flamegraph')
page.within_frame 'speedscope-iframe' do
expect(page).to have_content('Flamegraph for /')
end
end
end
context 'when user does not have access' do
it 'renders the original page' do
visit root_path(performance_bar: 'flamegraph')
expect(page).not_to have_selector('iframe#speedscope-iframe')
end
end
end
2017-09-10 17:25:29 +05:30
end