summaryrefslogtreecommitdiff
path: root/spec/components
diff options
context:
space:
mode:
Diffstat (limited to 'spec/components')
-rw-r--r--spec/components/pajamas/alert_component_spec.rb54
-rw-r--r--spec/components/pajamas/banner_component_spec.rb42
-rw-r--r--spec/components/pajamas/button_component_spec.rb74
-rw-r--r--spec/components/pajamas/card_component_spec.rb30
-rw-r--r--spec/components/pajamas/checkbox_component_spec.rb10
-rw-r--r--spec/components/pajamas/radio_component_spec.rb6
-rw-r--r--spec/components/pajamas/spinner_component_spec.rb74
-rw-r--r--spec/components/pajamas/toggle_component_spec.rb32
8 files changed, 198 insertions, 124 deletions
diff --git a/spec/components/pajamas/alert_component_spec.rb b/spec/components/pajamas/alert_component_spec.rb
index 1e2845c44a8..c60724c7b78 100644
--- a/spec/components/pajamas/alert_component_spec.rb
+++ b/spec/components/pajamas/alert_component_spec.rb
@@ -14,11 +14,11 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'renders alert body' do
- expect(rendered_component).to have_content(body)
+ expect(page).to have_content(body)
end
it 'renders actions' do
- expect(rendered_component).to have_content(actions)
+ expect(page).to have_content(actions)
end
end
@@ -28,20 +28,20 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'does not set a title' do
- expect(rendered_component).not_to have_selector('.gl-alert-title')
- expect(rendered_component).to have_selector('.gl-alert-icon-no-title')
+ expect(page).not_to have_selector('.gl-alert-title')
+ expect(page).to have_selector('.gl-alert-icon-no-title')
end
it 'renders the default variant' do
- expect(rendered_component).to have_selector('.gl-alert-info')
- expect(rendered_component).to have_selector("[data-testid='information-o-icon']")
- expect(rendered_component).not_to have_selector('.gl-alert-no-icon')
+ expect(page).to have_selector('.gl-alert-info')
+ expect(page).to have_selector("[data-testid='information-o-icon']")
+ expect(page).not_to have_selector('.gl-alert-no-icon')
end
it 'renders a dismiss button' do
- expect(rendered_component).to have_selector('.gl-dismiss-btn.js-close')
- expect(rendered_component).to have_selector("[data-testid='close-icon']")
- expect(rendered_component).not_to have_selector('.gl-alert-not-dismissible')
+ expect(page).to have_selector('.gl-dismiss-btn.js-close')
+ expect(page).to have_selector("[data-testid='close-icon']")
+ expect(page).not_to have_selector('.gl-alert-not-dismissible')
end
end
@@ -61,17 +61,17 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'sets the title' do
- expect(rendered_component).to have_selector('.gl-alert-title')
- expect(rendered_component).to have_content('_title_')
- expect(rendered_component).not_to have_selector('.gl-alert-icon-no-title')
+ 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(rendered_component).to have_selector('._alert_class_')
+ expect(page).to have_selector('._alert_class_')
end
it 'sets the alert_data' do
- expect(rendered_component).to have_selector('[data-feature-id="_feature_id_"][data-dismiss-endpoint="_dismiss_endpoint_"]')
+ expect(page).to have_selector('[data-feature-id="_feature_id_"][data-dismiss-endpoint="_dismiss_endpoint_"]')
end
end
@@ -81,12 +81,12 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'has the "not dismissible" class' do
- expect(rendered_component).to have_selector('.gl-alert-not-dismissible')
+ expect(page).to have_selector('.gl-alert-not-dismissible')
end
it 'does not render the dismiss button' do
- expect(rendered_component).not_to have_selector('.gl-dismiss-btn.js-close')
- expect(rendered_component).not_to have_selector("[data-testid='close-icon']")
+ expect(page).not_to have_selector('.gl-dismiss-btn.js-close')
+ expect(page).not_to have_selector("[data-testid='close-icon']")
end
end
@@ -96,12 +96,12 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'has the hidden icon class' do
- expect(rendered_component).to have_selector('.gl-alert-no-icon')
+ expect(page).to have_selector('.gl-alert-no-icon')
end
it 'does not render the icon' do
- expect(rendered_component).not_to have_selector('.gl-alert-icon')
- expect(rendered_component).not_to have_selector("[data-testid='information-o-icon']")
+ expect(page).not_to have_selector('.gl-alert-icon')
+ expect(page).not_to have_selector("[data-testid='information-o-icon']")
end
end
@@ -118,13 +118,13 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
end
it 'does not have "not dismissible" class' do
- expect(rendered_component).not_to have_selector('.gl-alert-not-dismissible')
+ expect(page).not_to have_selector('.gl-alert-not-dismissible')
end
it 'renders a dismiss button and data' do
- expect(rendered_component).to have_selector('.gl-dismiss-btn.js-close._close_button_class_')
- expect(rendered_component).to have_selector("[data-testid='close-icon']")
- expect(rendered_component).to have_selector('[data-testid="_close_button_testid_"]')
+ expect(page).to have_selector('.gl-dismiss-btn.js-close._close_button_class_')
+ expect(page).to have_selector("[data-testid='close-icon']")
+ expect(page).to have_selector('[data-testid="_close_button_testid_"]')
end
end
@@ -137,8 +137,8 @@ RSpec.describe Pajamas::AlertComponent, :aggregate_failures, type: :component do
with_them do
it 'renders the variant' do
- expect(rendered_component).to have_selector(".gl-alert-#{variant}")
- expect(rendered_component).to have_selector("[data-testid='#{described_class::ICONS[variant]}-icon']")
+ expect(page).to have_selector(".gl-alert-#{variant}")
+ expect(page).to have_selector("[data-testid='#{described_class::ICONS[variant]}-icon']")
end
end
end
diff --git a/spec/components/pajamas/banner_component_spec.rb b/spec/components/pajamas/banner_component_spec.rb
index 5969f06dbad..26468d80c77 100644
--- a/spec/components/pajamas/banner_component_spec.rb
+++ b/spec/components/pajamas/banner_component_spec.rb
@@ -19,22 +19,22 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
end
it 'renders its content' do
- expect(rendered_component).to have_text content
+ expect(page).to have_text content
end
it 'renders its title' do
- expect(rendered_component).to have_css "h1[class='gl-banner-title']", text: title
+ expect(page).to have_css "h1[class='gl-banner-title']", text: title
end
it 'renders a close button' do
- expect(rendered_component).to have_css "button.gl-banner-close"
+ expect(page).to have_css "button.gl-banner-close"
end
describe 'button_text and button_link' do
let(:options) { { button_text: 'Learn more', button_link: '/learn-more' } }
it 'define the primary action' do
- expect(rendered_component).to have_css "a.btn-confirm.gl-button[href='/learn-more']", text: 'Learn more'
+ expect(page).to have_css "a.btn-confirm.gl-button[href='/learn-more']", text: 'Learn more'
end
end
@@ -42,14 +42,14 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
let(:options) { { banner_options: { class: "baz", data: { foo: "bar" } } } }
it 'are on the banner' do
- expect(rendered_component).to have_css ".gl-banner.baz[data-foo='bar']"
+ expect(page).to have_css ".gl-banner.baz[data-foo='bar']"
end
context 'with custom classes' do
let(:options) { { variant: :introduction, banner_options: { class: 'extra special' } } }
it 'don\'t conflict with internal banner_classes' do
- expect(rendered_component).to have_css '.extra.special.gl-banner-introduction.gl-banner'
+ expect(page).to have_css '.extra.special.gl-banner-introduction.gl-banner'
end
end
end
@@ -58,14 +58,14 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
let(:options) { { close_options: { class: "js-foo", data: { uid: "123" } } } }
it 'are on the close button' do
- expect(rendered_component).to have_css "button.gl-banner-close.js-foo[data-uid='123']"
+ expect(page).to have_css "button.gl-banner-close.js-foo[data-uid='123']"
end
end
describe 'embedded' do
context 'by default (false)' do
it 'keeps the banner\'s borders' do
- expect(rendered_component).not_to have_css ".gl-banner.gl-border-none"
+ expect(page).not_to have_css ".gl-banner.gl-border-none"
end
end
@@ -73,7 +73,7 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
let(:options) { { embedded: true } }
it 'removes the banner\'s borders' do
- expect(rendered_component).to have_css ".gl-banner.gl-border-none"
+ expect(page).to have_css ".gl-banner.gl-border-none"
end
end
end
@@ -81,7 +81,7 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
describe 'variant' do
context 'by default (promotion)' do
it 'applies no variant class' do
- expect(rendered_component).to have_css "[class='gl-banner']"
+ expect(page).to have_css "[class='gl-banner']"
end
end
@@ -89,11 +89,11 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
let(:options) { { variant: :introduction } }
it "applies the introduction class to the banner" do
- expect(rendered_component).to have_css ".gl-banner.gl-banner-introduction"
+ expect(page).to have_css ".gl-banner.gl-banner-introduction"
end
it "applies the confirm class to the close button" do
- expect(rendered_component).to have_css ".gl-banner-close.btn-confirm.btn-confirm-tertiary"
+ expect(page).to have_css ".gl-banner-close.btn-confirm.btn-confirm-tertiary"
end
end
@@ -101,21 +101,21 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
let(:options) { { variant: :foobar } }
it 'ignores the unknown variant' do
- expect(rendered_component).to have_css "[class='gl-banner']"
+ expect(page).to have_css "[class='gl-banner']"
end
end
end
describe 'illustration' do
it 'has none by default' do
- expect(rendered_component).not_to have_css ".gl-banner-illustration"
+ expect(page).not_to have_css ".gl-banner-illustration"
end
context 'with svg_path' do
let(:options) { { svg_path: 'logo.svg' } }
it 'renders an image as illustration' do
- expect(rendered_component).to have_css ".gl-banner-illustration img"
+ expect(page).to have_css ".gl-banner-illustration img"
end
end
end
@@ -131,15 +131,15 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
end
it 'renders the slot content as illustration' do
- expect(rendered_component).to have_css ".gl-banner-illustration svg"
+ expect(page).to have_css ".gl-banner-illustration svg"
end
context 'and conflicting svg_path' do
let(:options) { { svg_path: 'logo.svg' } }
it 'uses the slot content' do
- expect(rendered_component).to have_css ".gl-banner-illustration svg"
- expect(rendered_component).not_to have_css ".gl-banner-illustration img"
+ expect(page).to have_css ".gl-banner-illustration svg"
+ expect(page).not_to have_css ".gl-banner-illustration img"
end
end
end
@@ -154,15 +154,15 @@ RSpec.describe Pajamas::BannerComponent, type: :component do
end
it 'renders the slot content as the primary action' do
- expect(rendered_component).to have_css "a.special", text: 'Special'
+ expect(page).to have_css "a.special", text: 'Special'
end
context 'and conflicting button_text and button_link' do
let(:options) { { button_text: 'Not special', button_link: '/' } }
it 'uses the slot content' do
- expect(rendered_component).to have_css "a.special[href='#']", text: 'Special'
- expect(rendered_component).not_to have_css "a.btn[href='/']"
+ expect(page).to have_css "a.special[href='#']", text: 'Special'
+ expect(page).not_to have_css "a.btn[href='/']"
end
end
end
diff --git a/spec/components/pajamas/button_component_spec.rb b/spec/components/pajamas/button_component_spec.rb
index 60c2a2e5a06..a8c96042580 100644
--- a/spec/components/pajamas/button_component_spec.rb
+++ b/spec/components/pajamas/button_component_spec.rb
@@ -17,25 +17,25 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
end
it 'renders its content' do
- expect(rendered_component).to have_text content
+ expect(page).to have_text content
end
it 'adds default styling' do
- expect(rendered_component).to have_css ".btn.btn-default.btn-md.gl-button"
+ expect(page).to have_css ".btn.btn-default.btn-md.gl-button"
end
describe 'button_options' do
let(:options) { { button_options: { id: 'baz', data: { foo: 'bar' } } } }
it 'are added to the button' do
- expect(rendered_component).to have_css ".gl-button#baz[data-foo='bar']"
+ expect(page).to have_css ".gl-button#baz[data-foo='bar']"
end
context 'with custom classes' do
let(:options) { { variant: :danger, category: :tertiary, button_options: { class: 'custom-class' } } }
it 'don\'t conflict with internal button_classes' do
- expect(rendered_component).to have_css '.gl-button.btn-danger.btn-danger-tertiary.custom-class'
+ expect(page).to have_css '.gl-button.btn-danger.btn-danger-tertiary.custom-class'
end
end
@@ -43,7 +43,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { button_options: { type: 'submit' } } }
it 'overrides type' do
- expect(rendered_component).to have_css '[type="submit"]'
+ expect(page).to have_css '[type="submit"]'
end
end
end
@@ -52,14 +52,14 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { button_text_classes: 'custom-text-class' } }
it 'is added to the button text' do
- expect(rendered_component).to have_css ".gl-button-text.custom-text-class"
+ expect(page).to have_css ".gl-button-text.custom-text-class"
end
end
describe 'disabled' do
context 'by default (false)' do
it 'does not have disabled styling and behavior' do
- expect(rendered_component).not_to have_css ".disabled[disabled='disabled'][aria-disabled='true']"
+ expect(page).not_to have_css ".disabled[disabled='disabled'][aria-disabled='true']"
end
end
@@ -67,7 +67,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { disabled: true } }
it 'has disabled styling and behavior' do
- expect(rendered_component).to have_css ".disabled[disabled='disabled'][aria-disabled='true']"
+ expect(page).to have_css ".disabled[disabled='disabled'][aria-disabled='true']"
end
end
end
@@ -75,11 +75,11 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
describe 'loading' do
context 'by default (false)' do
it 'is not disabled' do
- expect(rendered_component).not_to have_css ".disabled[disabled='disabled']"
+ expect(page).not_to have_css ".disabled[disabled='disabled']"
end
it 'does not render a spinner' do
- expect(rendered_component).not_to have_css ".gl-spinner[aria-label='Loading']"
+ expect(page).not_to have_css ".gl-spinner[aria-label='Loading']"
end
end
@@ -87,11 +87,11 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { loading: true } }
it 'is disabled' do
- expect(rendered_component).to have_css ".disabled[disabled='disabled']"
+ expect(page).to have_css ".disabled[disabled='disabled']"
end
it 'renders a spinner' do
- expect(rendered_component).to have_css ".gl-spinner[aria-label='Loading']"
+ expect(page).to have_css ".gl-spinner[aria-label='Loading']"
end
end
end
@@ -99,7 +99,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
describe 'block' do
context 'by default (false)' do
it 'is inline' do
- expect(rendered_component).not_to have_css ".btn-block"
+ expect(page).not_to have_css ".btn-block"
end
end
@@ -107,7 +107,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { block: true } }
it 'is block element' do
- expect(rendered_component).to have_css ".btn-block"
+ expect(page).to have_css ".btn-block"
end
end
end
@@ -115,7 +115,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
describe 'selected' do
context 'by default (false)' do
it 'does not have selected styling and behavior' do
- expect(rendered_component).not_to have_css ".selected"
+ expect(page).not_to have_css ".selected"
end
end
@@ -123,7 +123,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { selected: true } }
it 'has selected styling and behavior' do
- expect(rendered_component).to have_css ".selected"
+ expect(page).to have_css ".selected"
end
end
end
@@ -136,8 +136,8 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
with_them do
it 'renders the button in correct variant && category' do
- expect(rendered_component).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
- expect(rendered_component).to have_css(".#{described_class::VARIANT_CLASSES[variant]}-tertiary")
+ expect(page).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
+ expect(page).to have_css(".#{described_class::VARIANT_CLASSES[variant]}-tertiary")
end
end
end
@@ -149,8 +149,8 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
with_them do
it 'renders the button in correct variant && category' do
- expect(rendered_component).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
- expect(rendered_component).not_to have_css(".#{described_class::VARIANT_CLASSES[variant]}-tertiary")
+ expect(page).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
+ expect(page).not_to have_css(".#{described_class::VARIANT_CLASSES[variant]}-tertiary")
end
end
end
@@ -162,8 +162,8 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
with_them do
it 'renders the button in correct variant && category' do
- expect(rendered_component).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
- expect(rendered_component).not_to have_css(".#{described_class::VARIANT_CLASSES[variant]}-primary")
+ expect(page).to have_css(".#{described_class::VARIANT_CLASSES[variant]}")
+ expect(page).not_to have_css(".#{described_class::VARIANT_CLASSES[variant]}-primary")
end
end
end
@@ -172,7 +172,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
describe 'size' do
context 'by default (medium)' do
it 'applies medium class' do
- expect(rendered_component).to have_css ".btn-md"
+ expect(page).to have_css ".btn-md"
end
end
@@ -180,22 +180,22 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { size: :small } }
it "applies the small class to the button" do
- expect(rendered_component).to have_css ".btn-sm"
+ expect(page).to have_css ".btn-sm"
end
end
end
describe 'icon' do
it 'has none by default' do
- expect(rendered_component).not_to have_css ".gl-icon"
+ expect(page).not_to have_css ".gl-icon"
end
context 'with icon' do
let(:options) { { icon: 'star-o', icon_classes: 'custom-icon' } }
it 'renders an icon with custom CSS class' do
- expect(rendered_component).to have_css "svg.gl-icon.gl-button-icon.custom-icon[data-testid='star-o-icon']"
- expect(rendered_component).not_to have_css ".btn-icon"
+ expect(page).to have_css "svg.gl-icon.gl-button-icon.custom-icon[data-testid='star-o-icon']"
+ expect(page).not_to have_css ".btn-icon"
end
end
@@ -204,7 +204,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { icon: 'star-o' } }
it 'adds a "btn-icon" CSS class' do
- expect(rendered_component).to have_css ".btn.btn-icon"
+ expect(page).to have_css ".btn.btn-icon"
end
end
@@ -213,8 +213,8 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { icon: 'star-o', loading: true } }
it 'renders only a loading icon' do
- expect(rendered_component).not_to have_css "svg.gl-icon.gl-button-icon.custom-icon[data-testid='star-o-icon']"
- expect(rendered_component).to have_css ".gl-spinner[aria-label='Loading']"
+ expect(page).not_to have_css "svg.gl-icon.gl-button-icon.custom-icon[data-testid='star-o-icon']"
+ expect(page).to have_css ".gl-spinner[aria-label='Loading']"
end
end
end
@@ -222,7 +222,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
describe 'type' do
context 'by default (without href)' do
it 'has type "button"' do
- expect(rendered_component).to have_css "button[type='button']"
+ expect(page).to have_css "button[type='button']"
end
end
@@ -233,7 +233,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
with_them do
it 'has the correct type' do
- expect(rendered_component).to have_css "button[type='#{type}']"
+ expect(page).to have_css "button[type='#{type}']"
end
end
end
@@ -242,7 +242,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { type: :madeup } }
it 'has type "button"' do
- expect(rendered_component).to have_css "button[type='button']"
+ expect(page).to have_css "button[type='button']"
end
end
@@ -250,22 +250,22 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do
let(:options) { { href: 'https://example.com', type: :reset } }
it 'ignores type' do
- expect(rendered_component).not_to have_css "[type]"
+ expect(page).not_to have_css "[type]"
end
end
end
describe 'link button' do
it 'renders a button tag with type="button" when "href" is not set' do
- expect(rendered_component).to have_css "button[type='button']"
+ expect(page).to have_css "button[type='button']"
end
context 'when "href" is provided' do
let(:options) { { href: 'https://gitlab.com', target: '_blank' } }
it "renders a link instead of the button" do
- expect(rendered_component).not_to have_css "button[type='button']"
- expect(rendered_component).to have_css "a[href='https://gitlab.com'][target='_blank']"
+ expect(page).not_to have_css "button[type='button']"
+ expect(page).to have_css "a[href='https://gitlab.com'][target='_blank']"
end
end
end
diff --git a/spec/components/pajamas/card_component_spec.rb b/spec/components/pajamas/card_component_spec.rb
index 65522a9023f..38d23cfca9c 100644
--- a/spec/components/pajamas/card_component_spec.rb
+++ b/spec/components/pajamas/card_component_spec.rb
@@ -16,15 +16,15 @@ RSpec.describe Pajamas::CardComponent, :aggregate_failures, type: :component do
end
it 'renders card header' do
- expect(rendered_component).to have_content(header)
+ expect(page).to have_content(header)
end
it 'renders card body' do
- expect(rendered_component).to have_content(body)
+ expect(page).to have_content(body)
end
it 'renders footer' do
- expect(rendered_component).to have_content(footer)
+ expect(page).to have_content(footer)
end
end
@@ -34,13 +34,13 @@ RSpec.describe Pajamas::CardComponent, :aggregate_failures, type: :component do
end
it 'does not have a header or footer' do
- expect(rendered_component).not_to have_selector('.gl-card-header')
- expect(rendered_component).not_to have_selector('.gl-card-footer')
+ expect(page).not_to have_selector('.gl-card-header')
+ expect(page).not_to have_selector('.gl-card-footer')
end
it 'renders the card and body' do
- expect(rendered_component).to have_selector('.gl-card')
- expect(rendered_component).to have_selector('.gl-card-body')
+ expect(page).to have_selector('.gl-card')
+ expect(page).to have_selector('.gl-card-body')
end
end
@@ -58,23 +58,23 @@ RSpec.describe Pajamas::CardComponent, :aggregate_failures, type: :component do
end
it 'renders card options' do
- expect(rendered_component).to have_selector('._card_class_')
- expect(rendered_component).to have_selector('[data-testid="_card_testid_"]')
+ expect(page).to have_selector('._card_class_')
+ expect(page).to have_selector('[data-testid="_card_testid_"]')
end
it 'renders header options' do
- expect(rendered_component).to have_selector('._header_class_')
- expect(rendered_component).to have_selector('[data-testid="_header_testid_"]')
+ expect(page).to have_selector('._header_class_')
+ expect(page).to have_selector('[data-testid="_header_testid_"]')
end
it 'renders body options' do
- expect(rendered_component).to have_selector('._body_class_')
- expect(rendered_component).to have_selector('[data-testid="_body_testid_"]')
+ expect(page).to have_selector('._body_class_')
+ expect(page).to have_selector('[data-testid="_body_testid_"]')
end
it 'renders footer options' do
- expect(rendered_component).to have_selector('._footer_class_')
- expect(rendered_component).to have_selector('[data-testid="_footer_testid_"]')
+ expect(page).to have_selector('._footer_class_')
+ expect(page).to have_selector('[data-testid="_footer_testid_"]')
end
end
end
diff --git a/spec/components/pajamas/checkbox_component_spec.rb b/spec/components/pajamas/checkbox_component_spec.rb
index b2f3a84fbfe..d79c537a30e 100644
--- a/spec/components/pajamas/checkbox_component_spec.rb
+++ b/spec/components/pajamas/checkbox_component_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Pajamas::CheckboxComponent, :aggregate_failures, type: :component
RSpec.shared_examples 'it renders unchecked checkbox with value of `1`' do
it 'renders unchecked checkbox with value of `1`' do
- expect(rendered_component).to have_unchecked_field(label, with: '1')
+ expect(page).to have_unchecked_field(label, with: '1')
end
end
@@ -31,7 +31,7 @@ RSpec.describe Pajamas::CheckboxComponent, :aggregate_failures, type: :component
include_examples 'it does not render help text'
it 'renders hidden input with value of `0`' do
- expect(rendered_component).to have_field('user[view_diffs_file_by_file]', type: 'hidden', with: '0')
+ expect(page).to have_field('user[view_diffs_file_by_file]', type: 'hidden', with: '0')
end
end
@@ -61,15 +61,15 @@ RSpec.describe Pajamas::CheckboxComponent, :aggregate_failures, type: :component
include_examples 'it renders help text'
it 'renders checked checkbox with value of `yes`' do
- expect(rendered_component).to have_checked_field(label, with: checked_value, class: checkbox_options[:class])
+ expect(page).to have_checked_field(label, with: checked_value, class: checkbox_options[:class])
end
it 'adds CSS class to label' do
- expect(rendered_component).to have_selector('label.label-foo-bar')
+ expect(page).to have_selector('label.label-foo-bar')
end
it 'renders hidden input with value of `no`' do
- expect(rendered_component).to have_field('user[view_diffs_file_by_file]', type: 'hidden', with: unchecked_value)
+ expect(page).to have_field('user[view_diffs_file_by_file]', type: 'hidden', with: unchecked_value)
end
end
diff --git a/spec/components/pajamas/radio_component_spec.rb b/spec/components/pajamas/radio_component_spec.rb
index 3885d101c7a..8df432746d0 100644
--- a/spec/components/pajamas/radio_component_spec.rb
+++ b/spec/components/pajamas/radio_component_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe Pajamas::RadioComponent, :aggregate_failures, type: :component do
RSpec.shared_examples 'it renders unchecked radio' do
it 'renders unchecked radio' do
- expect(rendered_component).to have_unchecked_field(label)
+ expect(page).to have_unchecked_field(label)
end
end
@@ -58,11 +58,11 @@ RSpec.describe Pajamas::RadioComponent, :aggregate_failures, type: :component do
include_examples 'it renders help text'
it 'renders checked radio' do
- expect(rendered_component).to have_checked_field(label, class: radio_options[:class])
+ expect(page).to have_checked_field(label, class: radio_options[:class])
end
it 'adds CSS class to label' do
- expect(rendered_component).to have_selector('label.label-foo-bar')
+ expect(page).to have_selector('label.label-foo-bar')
end
end
diff --git a/spec/components/pajamas/spinner_component_spec.rb b/spec/components/pajamas/spinner_component_spec.rb
new file mode 100644
index 00000000000..9aac9a0085c
--- /dev/null
+++ b/spec/components/pajamas/spinner_component_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+RSpec.describe Pajamas::SpinnerComponent, type: :component do
+ let(:options) { {} }
+
+ before do
+ render_inline(described_class.new(**options))
+ end
+
+ describe 'class' do
+ let(:options) { { class: 'gl-my-6' } }
+
+ it 'has the correct custom class' do
+ expect(page).to have_css '.gl-spinner-container.gl-my-6'
+ end
+ end
+
+ describe 'color' do
+ context 'by default' do
+ it 'is dark' do
+ expect(page).to have_css '.gl-spinner.gl-spinner-dark'
+ end
+ end
+
+ context 'set to light' do
+ let(:options) { { color: :light } }
+
+ it 'is light' do
+ expect(page).to have_css '.gl-spinner.gl-spinner-light'
+ end
+ end
+ end
+
+ describe 'inline' do
+ context 'by default' do
+ it 'renders a div' do
+ expect(page).to have_css 'div.gl-spinner'
+ end
+ end
+
+ context 'set to true' do
+ let(:options) { { inline: true } }
+
+ it 'renders a span' do
+ expect(page).to have_css 'span.gl-spinner'
+ end
+ end
+ end
+
+ describe 'label' do
+ context 'by default' do
+ it 'has "Loading" as aria-label' do
+ expect(page).to have_css '.gl-spinner[aria-label="Loading"]'
+ end
+ end
+
+ context 'when set to something else' do
+ let(:options) { { label: "Sending" } }
+
+ it 'has a custom aria-label' do
+ expect(page).to have_css '.gl-spinner[aria-label="Sending"]'
+ end
+ end
+ end
+
+ describe 'size' do
+ let(:options) { { size: :lg } }
+
+ it 'has the correct size class' do
+ expect(page).to have_css '.gl-spinner.gl-spinner-lg'
+ end
+ end
+end
diff --git a/spec/components/pajamas/toggle_component_spec.rb b/spec/components/pajamas/toggle_component_spec.rb
index b2727dec318..6b0a2d26979 100644
--- a/spec/components/pajamas/toggle_component_spec.rb
+++ b/spec/components/pajamas/toggle_component_spec.rb
@@ -8,31 +8,31 @@ RSpec.describe Pajamas::ToggleComponent, type: :component do
end
it 'renders a toggle container with provided class' do
- expect(rendered_component).to have_selector "[class='js-feature-toggle']"
+ expect(page).to have_selector "[class='js-feature-toggle']"
end
it 'does not set a name' do
- expect(rendered_component).not_to have_selector('[data-name]')
+ expect(page).not_to have_selector('[data-name]')
end
it 'sets default is-checked attributes' do
- expect(rendered_component).to have_selector('[data-is-checked="false"]')
+ expect(page).to have_selector('[data-is-checked="false"]')
end
it 'sets default disabled attributes' do
- expect(rendered_component).to have_selector('[data-disabled="false"]')
+ expect(page).to have_selector('[data-disabled="false"]')
end
it 'sets default is-loading attributes' do
- expect(rendered_component).to have_selector('[data-is-loading="false"]')
+ expect(page).to have_selector('[data-is-loading="false"]')
end
it 'does not set a label' do
- expect(rendered_component).not_to have_selector('[data-label]')
+ expect(page).not_to have_selector('[data-label]')
end
it 'does not set a label position' do
- expect(rendered_component).not_to have_selector('[data-label-position]')
+ expect(page).not_to have_selector('[data-label-position]')
end
end
@@ -52,35 +52,35 @@ RSpec.describe Pajamas::ToggleComponent, type: :component do
end
it 'sets the custom class' do
- expect(rendered_component).to have_selector('.js-custom-gl-toggle')
+ expect(page).to have_selector('.js-custom-gl-toggle')
end
it 'sets the custom name' do
- expect(rendered_component).to have_selector('[data-name="toggle-name"]')
+ expect(page).to have_selector('[data-name="toggle-name"]')
end
it 'sets the custom is-checked attributes' do
- expect(rendered_component).to have_selector('[data-is-checked="true"]')
+ expect(page).to have_selector('[data-is-checked="true"]')
end
it 'sets the custom disabled attributes' do
- expect(rendered_component).to have_selector('[data-disabled="true"]')
+ expect(page).to have_selector('[data-disabled="true"]')
end
it 'sets the custom is-loading attributes' do
- expect(rendered_component).to have_selector('[data-is-loading="true"]')
+ expect(page).to have_selector('[data-is-loading="true"]')
end
it 'sets the custom label' do
- expect(rendered_component).to have_selector('[data-label="Custom label"]')
+ expect(page).to have_selector('[data-label="Custom label"]')
end
it 'sets the custom label position' do
- expect(rendered_component).to have_selector('[data-label-position="top"]')
+ expect(page).to have_selector('[data-label-position="top"]')
end
it 'sets custom data attributes' do
- expect(rendered_component).to have_selector('[data-foo="bar"]')
+ expect(page).to have_selector('[data-foo="bar"]')
end
end
@@ -101,7 +101,7 @@ RSpec.describe Pajamas::ToggleComponent, type: :component do
end
with_them do
- it { expect(rendered_component).to have_selector("[data-label-position='#{position}']", count: count) }
+ it { expect(page).to have_selector("[data-label-position='#{position}']", count: count) }
end
end
end