diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/components | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/components')
4 files changed, 95 insertions, 11 deletions
diff --git a/spec/components/pajamas/alert_component_spec.rb b/spec/components/pajamas/alert_component_spec.rb index c60724c7b78..4a90a9e0b88 100644 --- a/spec/components/pajamas/alert_component_spec.rb +++ b/spec/components/pajamas/alert_component_spec.rb @@ -45,11 +45,37 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do end end + describe 'title' do + before do + render_inline described_class.new(title: title) + end + + context 'with non-empty string' do + let(:title) { '_title_' } + + it 'sets the title' do + expect(page).to have_selector('.gl-alert-title') + expect(page).to have_content(title) + expect(page).not_to have_selector('.gl-alert-icon-no-title') + end + end + + context 'with nil, empty or blank string' do + where(:title) { [nil, '', ' '] } + + with_them do + it 'does not set a title' do + expect(page).not_to have_selector('.gl-alert-title') + expect(page).to have_selector('.gl-alert-icon-no-title') + end + end + end + end + context 'with custom options' do context 'with simple options' do before do render_inline described_class.new( - title: '_title_', alert_options: { class: '_alert_class_', data: { @@ -60,12 +86,6 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do ) end - it 'sets the title' do - expect(page).to have_selector('.gl-alert-title') - expect(page).to have_content('_title_') - expect(page).not_to have_selector('.gl-alert-icon-no-title') - end - it 'sets the alert_class' do expect(page).to have_selector('._alert_class_') end @@ -129,7 +149,7 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do end context 'with setting variant type' do - where(:variant) { [:warning, :success, :danger, :tip] } + where(:variant) { [:warning, "success", :danger, "tip"] } before do render_inline described_class.new(variant: variant) @@ -138,7 +158,18 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do with_them do it 'renders the variant' do expect(page).to have_selector(".gl-alert-#{variant}") - expect(page).to have_selector("[data-testid='#{described_class::ICONS[variant]}-icon']") + expect(page).to have_selector("[data-testid='#{described_class::VARIANT_ICONS[variant.to_sym]}-icon']") + end + end + + context "with unknown or nil variant" do + where(:variant) { [:foo, nil] } + + with_them do + it "adds the default variant class" do + expect(page).to have_selector(".gl-alert-info") + expect(page).to have_selector("[data-testid='information-o-icon']") + end end end end diff --git a/spec/components/pajamas/progress_component_spec.rb b/spec/components/pajamas/progress_component_spec.rb new file mode 100644 index 00000000000..5172f459a84 --- /dev/null +++ b/spec/components/pajamas/progress_component_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Pajamas::ProgressComponent, type: :component do + before do + render_inline(described_class.new(value: value, variant: variant)) + end + + let(:value) { 33 } + let(:variant) { nil } + + describe "value" do + it "sets the width of the progressbar" do + expect(page).to have_css ".progress-bar[style='width: #{value}%;']" + end + end + + describe "variant" do + where(:variant) { [:primary, :success] } + + with_them do + it "adds variant class" do + expect(page).to have_css ".progress-bar.bg-#{variant}" + end + end + + context "with unknown variant" do + let(:variant) { :nope } + + it "adds the default variant class" do + expect(page).to have_css ".progress-bar.bg-primary" + end + end + end +end diff --git a/spec/components/previews/pajamas/alert_component_preview.rb b/spec/components/previews/pajamas/alert_component_preview.rb index 9a6b77715f5..e1889032c8b 100644 --- a/spec/components/previews/pajamas/alert_component_preview.rb +++ b/spec/components/previews/pajamas/alert_component_preview.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true module Pajamas class AlertComponentPreview < ViewComponent::Preview + # @param title text # @param body text # @param dismissible toggle # @param variant select [info, warning, success, danger, tip] - def default(body: nil, dismissible: true, variant: :info) + def default(title: "Alert title (optional)", body: "Alert message goes here.", dismissible: true, variant: :info) render(Pajamas::AlertComponent.new( - title: "Title", + title: title, dismissible: dismissible, variant: variant.to_sym )) do |c| diff --git a/spec/components/previews/pajamas/progress_component_preview.rb b/spec/components/previews/pajamas/progress_component_preview.rb new file mode 100644 index 00000000000..4de07872a80 --- /dev/null +++ b/spec/components/previews/pajamas/progress_component_preview.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Pajamas + class ProgressComponentPreview < ViewComponent::Preview + # Progress + # --- + # + # See its design reference [here](https://design.gitlab.com/components/progress-bar). + # + # @param value number + # @param variant select [primary, success] + def default(value: 50, variant: :primary) + render Pajamas::ProgressComponent.new(value: value, variant: variant) + end + end +end |