2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-08 12:59:55 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-06-16 15:27:57 +00:00
|
|
|
describe 'User can display performance bar', :js do
|
2018-01-16 18:13:31 +00:00
|
|
|
shared_examples 'performance bar cannot be displayed' do
|
2017-06-08 12:59:55 +00:00
|
|
|
it 'does not show the performance bar by default' do
|
2018-03-19 19:06:09 +00:00
|
|
|
expect(page).not_to have_css('#js-peek')
|
2017-06-08 12:59:55 +00:00
|
|
|
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-03-19 19:06:09 +00:00
|
|
|
expect(page).not_to have_css('#js-peek')
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
shared_examples 'performance bar can be displayed' do
|
2017-06-08 12:59:55 +00:00
|
|
|
it 'does not show the performance bar by default' do
|
2018-03-19 19:06:09 +00:00
|
|
|
expect(page).not_to have_css('#js-peek')
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user press `pb`' do
|
|
|
|
before do
|
|
|
|
find('body').native.send_keys('pb')
|
|
|
|
end
|
|
|
|
|
2017-06-16 15:27:57 +00:00
|
|
|
it 'shows the performance bar' do
|
2018-03-19 19:06:09 +00:00
|
|
|
expect(page).to have_css('#js-peek')
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
shared_examples 'performance bar is enabled by default in development' do
|
|
|
|
before do
|
|
|
|
allow(Rails.env).to receive(:development?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the performance bar by default' do
|
|
|
|
refresh # Because we're stubbing Rails.env after the 1st visit to root_path
|
|
|
|
|
2018-03-19 19:06:09 +00:00
|
|
|
expect(page).to have_css('#js-peek')
|
2018-01-16 18:13:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-07 15:30:50 +00:00
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
2017-06-08 12:59:55 +00:00
|
|
|
context 'when user is logged-out' do
|
|
|
|
before do
|
|
|
|
visit root_path
|
|
|
|
end
|
|
|
|
|
2017-07-06 16:57:02 +00:00
|
|
|
context 'when the performance_bar feature is disabled' do
|
2017-06-08 12:59:55 +00:00
|
|
|
before do
|
2017-07-07 15:30:50 +00:00
|
|
|
stub_application_setting(performance_bar_allowed_group_id: nil)
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
it_behaves_like 'performance bar cannot be displayed'
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2017-07-06 16:57:02 +00:00
|
|
|
context 'when the performance_bar feature is enabled' do
|
2017-06-08 12:59:55 +00:00
|
|
|
before do
|
2017-07-07 15:30:50 +00:00
|
|
|
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
it_behaves_like 'performance bar cannot be displayed'
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is logged-in' do
|
|
|
|
before do
|
2017-07-07 15:30:50 +00:00
|
|
|
user = create(:user)
|
|
|
|
|
2017-07-07 20:45:53 +00:00
|
|
|
sign_in(user)
|
2017-07-07 15:30:50 +00:00
|
|
|
group.add_guest(user)
|
2017-06-08 12:59:55 +00:00
|
|
|
|
|
|
|
visit root_path
|
|
|
|
end
|
|
|
|
|
2017-07-06 16:57:02 +00:00
|
|
|
context 'when the performance_bar feature is disabled' do
|
2017-06-08 12:59:55 +00:00
|
|
|
before do
|
2017-07-07 15:30:50 +00:00
|
|
|
stub_application_setting(performance_bar_allowed_group_id: nil)
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
it_behaves_like 'performance bar cannot be displayed'
|
|
|
|
it_behaves_like 'performance bar is enabled by default in development'
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2017-07-06 16:57:02 +00:00
|
|
|
context 'when the performance_bar feature is enabled' do
|
2017-06-08 12:59:55 +00:00
|
|
|
before do
|
2017-07-07 15:30:50 +00:00
|
|
|
stub_application_setting(performance_bar_allowed_group_id: group.id)
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
|
2018-01-16 18:13:31 +00:00
|
|
|
it_behaves_like 'performance bar is enabled by default in development'
|
|
|
|
it_behaves_like 'performance bar can be displayed'
|
2017-06-08 12:59:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|