BigW Consortium Gitlab

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

3
describe 'User can display performance bar', :js do
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
  shared_examples 'performance bar is disabled' do
    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

  shared_examples 'performance bar is enabled' do
    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
  let(:group) { create(:group) }

38 39 40 41 42
  context 'when user is logged-out' do
    before do
      visit root_path
    end

43
    context 'when the performance_bar feature is disabled' do
44
      before do
45
        stub_application_setting(performance_bar_allowed_group_id: nil)
46 47 48 49 50
      end

      it_behaves_like 'performance bar is disabled'
    end

51
    context 'when the performance_bar feature is enabled' do
52
      before do
53
        stub_application_setting(performance_bar_allowed_group_id: group.id)
54 55 56 57 58 59 60 61
      end

      it_behaves_like 'performance bar is disabled'
    end
  end

  context 'when user is logged-in' do
    before do
62 63
      user = create(:user)

64
      sign_in(user)
65
      group.add_guest(user)
66 67 68 69

      visit root_path
    end

70
    context 'when the performance_bar feature is disabled' do
71
      before do
72
        stub_application_setting(performance_bar_allowed_group_id: nil)
73 74 75 76 77
      end

      it_behaves_like 'performance bar is disabled'
    end

78
    context 'when the performance_bar feature is enabled' do
79
      before do
80
        stub_application_setting(performance_bar_allowed_group_id: group.id)
81 82 83 84 85 86
      end

      it_behaves_like 'performance bar is enabled'
    end
  end
end