summaryrefslogtreecommitdiff
path: root/spec/components/pajamas
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 09:40:42 +0000
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/components/pajamas
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
downloadgitlab-ce-ee664acb356f8123f4f6b00b73c1e1cf0866c7fb.tar.gz
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/components/pajamas')
-rw-r--r--spec/components/pajamas/alert_component_spec.rb49
-rw-r--r--spec/components/pajamas/progress_component_spec.rb36
2 files changed, 76 insertions, 9 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