BigW Consortium Gitlab

user_can_display_performance_bar_spec.rb 2.53 KB
Newer Older
1 2
require 'rails_helper'

3
describe 'User can display performance bar', :js do
4
  shared_examples 'performance bar cannot be displayed' do
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    it 'does not show the performance bar by default' do
      expect(page).not_to have_css('#peek')
    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
        expect(page).not_to have_css('#peek')
      end
    end
  end

20
  shared_examples 'performance bar can be displayed' do
21 22 23 24 25 26 27 28 29
    it 'does not show the performance bar by default' do
      expect(page).not_to have_css('#peek')
    end

    context 'when user press `pb`' do
      before do
        find('body').native.send_keys('pb')
      end

30 31
      it 'shows the performance bar' do
        expect(page).to have_css('#peek')
32 33 34 35
      end
    end
  end

36 37 38 39 40 41 42 43 44 45 46 47
  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

      expect(page).to have_css('#peek')
    end
  end

48 49
  let(:group) { create(:group) }

50 51 52 53 54
  context 'when user is logged-out' do
    before do
      visit root_path
    end

55
    context 'when the performance_bar feature is disabled' do
56
      before do
57
        stub_application_setting(performance_bar_allowed_group_id: nil)
58 59
      end

60
      it_behaves_like 'performance bar cannot be displayed'
61 62
    end

63
    context 'when the performance_bar feature is enabled' do
64
      before do
65
        stub_application_setting(performance_bar_allowed_group_id: group.id)
66 67
      end

68
      it_behaves_like 'performance bar cannot be displayed'
69 70 71 72 73
    end
  end

  context 'when user is logged-in' do
    before do
74 75
      user = create(:user)

76
      sign_in(user)
77
      group.add_guest(user)
78 79 80 81

      visit root_path
    end

82
    context 'when the performance_bar feature is disabled' do
83
      before do
84
        stub_application_setting(performance_bar_allowed_group_id: nil)
85 86
      end

87 88
      it_behaves_like 'performance bar cannot be displayed'
      it_behaves_like 'performance bar is enabled by default in development'
89 90
    end

91
    context 'when the performance_bar feature is enabled' do
92
      before do
93
        stub_application_setting(performance_bar_allowed_group_id: group.id)
94 95
      end

96 97
      it_behaves_like 'performance bar is enabled by default in development'
      it_behaves_like 'performance bar can be displayed'
98 99 100
    end
  end
end