From a4068557f4e8f0622798ccf824ac314e2008a57b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 27 Jul 2022 12:10:44 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/components/pajamas/button_component_spec.rb | 54 +++++++++++++++--------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'spec/components/pajamas') diff --git a/spec/components/pajamas/button_component_spec.rb b/spec/components/pajamas/button_component_spec.rb index a8c96042580..00423fd22a4 100644 --- a/spec/components/pajamas/button_component_spec.rb +++ b/spec/components/pajamas/button_component_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do let(:content) { "Button content" } let(:options) { {} } - describe 'basic usage' do + RSpec.shared_examples 'basic button behavior' do before do render_inline(subject) do |c| content @@ -59,7 +59,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do describe 'disabled' do context 'by default (false)' do it 'does not have disabled styling and behavior' do - expect(page).not_to have_css ".disabled[disabled='disabled'][aria-disabled='true']" + expect(page).not_to have_css ".disabled[disabled][aria-disabled]" 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(page).to have_css ".disabled[disabled='disabled'][aria-disabled='true']" + expect(page).to have_css ".disabled[disabled][aria-disabled]" end end end @@ -75,7 +75,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do describe 'loading' do context 'by default (false)' do it 'is not disabled' do - expect(page).not_to have_css ".disabled[disabled='disabled']" + expect(page).not_to have_css ".disabled[disabled]" end it 'does not render a spinner' do @@ -87,7 +87,7 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do let(:options) { { loading: true } } it 'is disabled' do - expect(page).to have_css ".disabled[disabled='disabled']" + expect(page).to have_css ".disabled[disabled]" end it 'renders a spinner' do @@ -218,9 +218,13 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do end end end + end + + context 'button component renders a button' do + include_examples 'basic button behavior' describe 'type' do - context 'by default (without href)' do + context 'by default' do it 'has type "button"' do expect(page).to have_css "button[type='button']" end @@ -238,34 +242,42 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do end end - context 'when set to unkown type' do + context 'when set to unknown type' do let(:options) { { type: :madeup } } it 'has type "button"' do expect(page).to have_css "button[type='button']" end end + end + end - context 'for links (with href)' do - let(:options) { { href: 'https://example.com', type: :reset } } + context 'button component renders a link' do + let(:options) { { href: 'https://gitlab.com', target: '_blank' } } - it 'ignores type' do - expect(page).not_to have_css "[type]" - end - end + it "renders a link instead of the button" do + expect(page).not_to have_css "button[type='button']" + expect(page).to have_css "a[href='https://gitlab.com'][target='_blank']" end - describe 'link button' do - it 'renders a button tag with type="button" when "href" is not set' do - expect(page).to have_css "button[type='button']" + include_examples 'basic button behavior' + + describe 'type' do + let(:options) { { href: 'https://example.com', type: :reset } } + + it 'ignores type' do + expect(page).not_to have_css "[type]" end + end + + describe 'method' do + where(:method) { [:get, :post, :put, :delete, :patch] } - context 'when "href" is provided' do - let(:options) { { href: 'https://gitlab.com', target: '_blank' } } + let(:options) { { href: 'https://gitlab.com', method: method } } - it "renders a link instead of the button" do - expect(page).not_to have_css "button[type='button']" - expect(page).to have_css "a[href='https://gitlab.com'][target='_blank']" + with_them do + it 'has the correct data-method attribute' do + expect(page).to have_css "a[data-method='#{method}']" end end end -- cgit v1.2.3