user_can_display_performance_bar_spec.rb 2.54 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
    it 'does not show the performance bar by default' do
6
      expect(page).not_to have_css('#js-peek')
7 8 9 10 11 12 13 14
    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
15
        expect(page).not_to have_css('#js-peek')
16 17 18 19
      end
    end
  end

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

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

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

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

44
      expect(page).to have_css('#js-peek')
45 46 47
    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