diff options
Diffstat (limited to 'spec/components/pajamas/button_component_spec.rb')
-rw-r--r-- | spec/components/pajamas/button_component_spec.rb | 74 |
1 files changed, 37 insertions, 37 deletions
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 |