diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-25 09:09:05 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-25 09:09:05 +0000 |
commit | 012ed4e4f69ab58f9d9b58140865a734fa5a9c88 (patch) | |
tree | 5ffb4f87d8b495a89662f0e5218c9dd3f4ae0f38 /spec/components | |
parent | 5b9a8005eaf815a0cae80a8482ff3f272d33e042 (diff) | |
download | gitlab-ce-012ed4e4f69ab58f9d9b58140865a734fa5a9c88.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/components')
-rw-r--r-- | spec/components/pajamas/avatar_component_spec.rb | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/spec/components/pajamas/avatar_component_spec.rb b/spec/components/pajamas/avatar_component_spec.rb new file mode 100644 index 00000000000..3b4e4e49fc2 --- /dev/null +++ b/spec/components/pajamas/avatar_component_spec.rb @@ -0,0 +1,135 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Pajamas::AvatarComponent, type: :component do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:group) { create(:group) } + + let(:options) { {} } + + before do + render_inline(described_class.new(record, **options)) + end + + describe "avatar shape" do + context "for a User" do + let(:record) { user } + + it "has a circle shape" do + expect(page).to have_css ".gl-avatar.gl-avatar-circle" + end + end + + context "for a Project" do + let(:record) { project } + + it "has default shape (rect)" do + expect(page).to have_css ".gl-avatar" + expect(page).not_to have_css ".gl-avatar-circle" + end + end + + context "for a Group" do + let(:record) { group } + + it "has default shape (rect)" do + expect(page).to have_css ".gl-avatar" + expect(page).not_to have_css ".gl-avatar-circle" + end + end + end + + describe "avatar image" do + context "when it has an uploaded image" do + let(:record) { project } + + before do + allow(record).to receive(:avatar_url).and_return "/example.png" + render_inline(described_class.new(record, **options)) + end + + it "uses the avatar_url as image src" do + expect(page).to have_css "img.gl-avatar[src='/example.png?width=64']" + end + + it "uses a srcset for higher resolution on retina displays" do + expect(page).to have_css "img.gl-avatar[srcset='/example.png?width=64 1x, /example.png?width=128 2x']" + end + + it "uses lazy loading" do + expect(page).to have_css "img.gl-avatar[loading='lazy']" + end + + context "with size option" do + let(:options) { { size: 16 } } + + it "uses that size as param for image src and srcset" do + expect(page).to have_css( + "img.gl-avatar[src='/example.png?width=16'][srcset='/example.png?width=16 1x, /example.png?width=32 2x']" + ) + end + end + end + + context "when a project or group has no uploaded image" do + let(:record) { project } + + it "uses an identicon with the record's initial" do + expect(page).to have_css "div.gl-avatar.gl-avatar-identicon", text: record.name[0].upcase + end + + context "when the record has no id" do + let(:record) { build :group } + + it "uses an identicon with default background color" do + expect(page).to have_css "div.gl-avatar.gl-avatar-identicon-bg1" + end + end + end + + context "when a user has no uploaded image" do + let(:record) { user } + + it "uses a gravatar" do + expect(rendered_component).to match /gravatar\.com/ + end + end + end + + describe "options" do + let(:record) { user } + + describe "alt" do + context "with a value" do + let(:options) { { alt: "Profile picture" } } + + it "uses given value as alt text" do + expect(page).to have_css ".gl-avatar[alt='Profile picture']" + end + end + + context "without a value" do + it "uses the record's name as alt text" do + expect(page).to have_css ".gl-avatar[alt='#{record.name}']" + end + end + end + + describe "class" do + let(:options) { { class: 'gl-m-4' } } + + it 'has the correct custom class' do + expect(page).to have_css '.gl-avatar.gl-m-4' + end + end + + describe "size" do + let(:options) { { size: 96 } } + + it 'has the correct size class' do + expect(page).to have_css '.gl-avatar.gl-avatar-s96' + end + end + end +end |