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

avatars_helper_spec.rb « helpers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4632c679972f92bac4f41445365d55739e2f1fe0 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'rails_helper'

describe AvatarsHelper do
  include ApplicationHelper

  let(:user) { create(:user) }

  describe '#user_avatar' do
    subject { helper.user_avatar(user: user) }

    it "links to the user's profile" do
      is_expected.to include("href=\"#{user_path(user)}\"")
    end

    it "has the user's name as title" do
      is_expected.to include("title=\"#{user.name}\"")
    end

    it "contains the user's avatar image" do
      is_expected.to include(CGI.escapeHTML(user.avatar_url(size: 16)))
    end
  end

  describe '#user_avatar_without_link' do
    let(:options) { { user: user } }
    subject { helper.user_avatar_without_link(options) }

    it 'displays user avatar' do
      is_expected.to eq image_tag(
        LazyImageTagHelper.placeholder_image,
        class: 'avatar s16 has-tooltip  lazy',
        alt: "#{user.name}'s avatar",
        title: user.name,
        data: { container: 'body', src: avatar_icon(user, 16) }
      )
    end

    context 'with css_class parameter' do
      let(:options) { { user: user, css_class: '.cat-pics' } }

      it 'uses provided css_class' do
        is_expected.to eq image_tag(
          LazyImageTagHelper.placeholder_image,
          class: "avatar s16 #{options[:css_class]} has-tooltip  lazy",
          alt: "#{user.name}'s avatar",
          title: user.name,
          data: { container: 'body', src: avatar_icon(user, 16) }
        )
      end
    end

    context 'with size parameter' do
      let(:options) { { user: user, size: 99 } }

      it 'uses provided size' do
        is_expected.to eq image_tag(
          LazyImageTagHelper.placeholder_image,
          class: "avatar s#{options[:size]} has-tooltip  lazy",
          alt: "#{user.name}'s avatar",
          title: user.name,
          data: { container: 'body', src: avatar_icon(user, options[:size]) }
        )
      end
    end

    context 'with url parameter' do
      let(:options) { { user: user, url: '/over/the/rainbow.png' } }

      it 'uses provided url' do
        is_expected.to eq image_tag(
          LazyImageTagHelper.placeholder_image,
          class: 'avatar s16 has-tooltip  lazy',
          alt: "#{user.name}'s avatar",
          title: user.name,
          data: { container: 'body', src: options[:url] }
        )
      end
    end

    context 'with has_tooltip parameter' do
      context 'with has_tooltip set to true' do
        let(:options) { { user: user, has_tooltip: true } }

        it 'adds has-tooltip' do
          is_expected.to eq image_tag(
            LazyImageTagHelper.placeholder_image,
            class: 'avatar s16 has-tooltip  lazy',
            alt: "#{user.name}'s avatar",
            title: user.name,
            data: { container: 'body', src: avatar_icon(user, 16) }
          )
        end
      end

      context 'with has_tooltip set to false' do
        let(:options) { { user: user, has_tooltip: false } }

        it 'does not add has-tooltip or data container' do
          is_expected.to eq image_tag(
            LazyImageTagHelper.placeholder_image,
            class: 'avatar s16  lazy',
            alt: "#{user.name}'s avatar",
            title: user.name,
            data: { src: avatar_icon(user, 16) }
          )
        end
      end
    end

    context 'with user_name parameter' do
      let(:options) { { user_name: 'Tinky Winky', user_email: 'no@f.un' } }

      context 'with user parameter' do
        let(:options) { { user: user, user_name: 'Tinky Winky' } }

        it 'prefers user parameter' do
          is_expected.to eq image_tag(
            LazyImageTagHelper.placeholder_image,
            class: 'avatar s16 has-tooltip  lazy',
            alt: "#{user.name}'s avatar",
            title: user.name,
            data: { container: 'body', src: avatar_icon(user, 16) }
          )
        end
      end

      it 'uses user_name and user_email parameter if user is not present' do
        is_expected.to eq image_tag(
          LazyImageTagHelper.placeholder_image,
          class: 'avatar s16 has-tooltip  lazy',
          alt: "#{options[:user_name]}'s avatar",
          title: options[:user_name],
          data: { container: 'body', src: avatar_icon(options[:user_email], 16) }
        )
      end
    end
  end
end