From 2f7719abdfde4cb50ed05346b98bac26ea06a8de Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 10 Jun 2022 18:09:28 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/components/pajamas/button_component_spec.rb | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'spec/components/pajamas') diff --git a/spec/components/pajamas/button_component_spec.rb b/spec/components/pajamas/button_component_spec.rb index 0009228e58c..60c2a2e5a06 100644 --- a/spec/components/pajamas/button_component_spec.rb +++ b/spec/components/pajamas/button_component_spec.rb @@ -38,6 +38,14 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do expect(rendered_component).to have_css '.gl-button.btn-danger.btn-danger-tertiary.custom-class' end end + + context 'overriding base attributes' do + let(:options) { { button_options: { type: 'submit' } } } + + it 'overrides type' do + expect(rendered_component).to have_css '[type="submit"]' + end + end end describe 'button_text_classes' do @@ -211,6 +219,42 @@ RSpec.describe Pajamas::ButtonComponent, type: :component do end end + describe 'type' do + context 'by default (without href)' do + it 'has type "button"' do + expect(rendered_component).to have_css "button[type='button']" + end + end + + context 'when set to known type' do + where(:type) { [:button, :reset, :submit] } + + let(:options) { { type: type } } + + with_them do + it 'has the correct type' do + expect(rendered_component).to have_css "button[type='#{type}']" + end + end + end + + context 'when set to unkown type' do + let(:options) { { type: :madeup } } + + it 'has type "button"' do + expect(rendered_component).to have_css "button[type='button']" + end + end + + context 'for links (with href)' do + let(:options) { { href: 'https://example.com', type: :reset } } + + it 'ignores type' do + expect(rendered_component).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']" -- cgit v1.2.3