help_pages_spec.rb 2.5 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
describe 'Help Pages' do
6
  describe 'Get the main help page' do
7
    shared_examples_for 'help page' do |prefix: ''|
8
      it 'prefixes links correctly' do
Evan Read's avatar
Evan Read committed
9
        expect(page).to have_selector(%(div.documentation-index > table tbody tr td a[href="#{prefix}/help/api/README.md"]))
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
      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
28 29 30 31 32 33 34 35 36

    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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

    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
55
  end
56

57
  context 'in a production environment with version check enabled' do
58
    before do
59
      stub_application_setting(version_check_enabled: true)
60 61 62

      allow(Rails.env).to receive(:production?).and_return(true)
      allow(VersionCheck).to receive(:url).and_return('/version-check-url')
63

64
      sign_in(create(:user))
65 66 67
      visit help_path
    end

68
    it 'has a version check image' do
69 70 71
      # Check `data-src` due to lazy image loading
      expect(find('.js-version-status-badge', visible: false)['data-src'])
        .to end_with('/version-check-url')
72 73
    end
  end
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')
80

81
      sign_in(create(:user))
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