Welcome to mirror list, hosted at ThFree Co, Russian Federation.

_signup_box.html.haml_spec.rb « shared « devise « views « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13beb87c38304dd5272b1d66b7244af68ad9b3c9 (plain)
1
2
3
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'devise/shared/_signup_box' do
  let(:button_text) { '_button_text_' }
  let(:terms_path) { '_terms_path_' }

  let(:translation_com) do
    s_("SignUp|By clicking %{button_text} or registering through a third party you "\
      "accept the GitLab%{link_start} Terms of Use and acknowledge the Privacy Statement "\
      "and Cookie Policy%{link_end}")
  end

  let(:translation_non_com) do
    s_("SignUp|By clicking %{button_text} or registering through a third party you "\
      "accept the%{link_start} Terms of Use and acknowledge the Privacy Statement and "\
      "Cookie Policy%{link_end}")
  end

  before do
    stub_devise
    allow(view).to receive(:arkose_labs_enabled?).and_return(false)
    allow(view).to receive(:show_omniauth_providers).and_return(false)
    allow(view).to receive(:url).and_return('_url_')
    allow(view).to receive(:terms_path).and_return(terms_path)
    allow(view).to receive(:button_text).and_return(button_text)
    allow(view).to receive(:signup_username_data_attributes).and_return({})
    stub_template 'devise/shared/_error_messages.html.haml' => ''
  end

  def text(translation)
    format(
      translation,
      button_text: button_text,
      link_start: "<a href='#{terms_path}' target='_blank' rel='noreferrer noopener'>",
      link_end: '</a>'
    )
  end

  context 'when terms are enforced' do
    before do
      allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enforce_terms?).and_return(true)
    end

    context 'when on .com' do
      before do
        allow(Gitlab).to receive(:com?).and_return(true)
      end

      it 'shows expected GitLab text' do
        render

        expect(rendered).to include(text(translation_com))
      end
    end

    context 'when not on .com' do
      before do
        allow(Gitlab).to receive(:com?).and_return(false)
      end

      it 'shows expected text without GitLab' do
        render

        expect(rendered).to include(text(translation_non_com))
      end
    end
  end

  context 'when terms are not enforced' do
    before do
      allow(Gitlab::CurrentSettings.current_application_settings).to receive(:enforce_terms?).and_return(false)
      allow(Gitlab).to receive(:com?).and_return(true)
    end

    it 'shows expected text with placeholders' do
      render

      expect(rendered).not_to include(text(translation_com))
    end
  end

  def stub_devise
    allow(view).to receive(:devise_mapping).and_return(Devise.mappings[:user])
    allow(view).to receive(:resource).and_return(spy)
    allow(view).to receive(:resource_name).and_return(:user)
  end
end