help_pages_spec.rb 2.6 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Help Pages' do
4
  describe 'Get the main help page' do
5
    shared_examples_for 'help page' do |prefix: ''|
6
      it 'prefixes links correctly' do
E
Evan Read 已提交
7
        expect(page).to have_selector(%(div.documentation-index > table tbody tr td a[href="#{prefix}/help/api/README.md"]))
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
      end
    end

    context 'without a trailing slash' do
      before do
        visit help_path
      end

      it_behaves_like 'help page'
    end

    context 'with a trailing slash' do
      before do
        visit help_path + '/'
      end

      it_behaves_like 'help page'
    end
26 27 28 29 30 31 32 33 34

    context 'with a relative installation' do
      before do
        stub_config_setting(relative_url_root: '/gitlab')
        visit help_path
      end

      it_behaves_like 'help page', prefix: '/gitlab'
    end
C
Clement Ho 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    context 'quick link shortcuts', :js do
      before do
        visit help_path
      end

      it 'focuses search bar' do
        find('.js-trigger-search-bar').click

        expect(page).to have_selector('#search:focus')
      end

      it 'opens shortcuts help dialog' do
        find('.js-trigger-shortcut').click

        expect(page).to have_selector('#modal-shortcuts')
      end
    end
53
  end
54

R
Rémy Coutable 已提交
55
  context 'in a production environment with version check enabled', :js do
56 57
    before do
      allow(Rails.env).to receive(:production?) { true }
58
      stub_application_setting(version_check_enabled: true)
59 60
      allow_any_instance_of(VersionCheck).to receive(:url) { '/version-check-url' }

61
      sign_in(create(:user))
62 63 64
      visit help_path
    end

R
Rémy Coutable 已提交
65 66
    it 'has a version check image' do
      expect(find('.js-version-status-badge', visible: false)['src']).to end_with('/version-check-url')
67 68
    end

R
Rémy Coutable 已提交
69 70
    it 'hides the version check image if the image request fails' do
      # We use '--load-images=yes' with poltergeist so the image fails to load
P
Phil Hughes 已提交
71
      expect(page).to have_selector('.js-version-status-badge', visible: false)
72 73
    end
  end
R
Robin Bobbitt 已提交
74 75 76

  describe 'when help page is customized' do
    before do
77 78 79
      stub_application_setting(help_page_hide_commercial_content: true,
                               help_page_text: 'My Custom Text',
                               help_page_support_url: 'http://example.com/help')
R
Robin Bobbitt 已提交
80

81
      sign_in(create(:user))
R
Robin Bobbitt 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
      visit help_path
    end

    it 'should display custom help page text' do
      expect(page).to have_text "My Custom Text"
    end

    it 'should hide marketing content when enabled' do
      expect(page).not_to have_link "Get a support subscription"
    end

    it 'should use a custom support url' do
      expect(page).to have_link "See our website for getting help", href: "http://example.com/help"
    end
  end
97
end