diff options
Diffstat (limited to 'spec/components')
-rw-r--r-- | spec/components/pajamas/card_component_spec.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/components/pajamas/card_component_spec.rb b/spec/components/pajamas/card_component_spec.rb new file mode 100644 index 00000000000..65522a9023f --- /dev/null +++ b/spec/components/pajamas/card_component_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe Pajamas::CardComponent, :aggregate_failures, type: :component do + let(:header) { 'Card header' } + let(:body) { 'Card body' } + let(:footer) { 'Card footer' } + + context 'slots' do + before do + render_inline described_class.new do |c| + c.header { header } + c.body { body } + c.footer { footer } + end + end + + it 'renders card header' do + expect(rendered_component).to have_content(header) + end + + it 'renders card body' do + expect(rendered_component).to have_content(body) + end + + it 'renders footer' do + expect(rendered_component).to have_content(footer) + end + end + + context 'with defaults' do + before do + render_inline described_class.new + 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') + 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') + end + end + + context 'with custom options' do + before do + render_inline described_class.new( + card_options: { class: '_card_class_', data: { testid: '_card_testid_' } }, + header_options: { class: '_header_class_', data: { testid: '_header_testid_' } }, + body_options: { class: '_body_class_', data: { testid: '_body_testid_' } }, + footer_options: { class: '_footer_class_', data: { testid: '_footer_testid_' } }) do |c| + c.header { header } + c.body { body } + c.footer { footer } + end + end + + it 'renders card options' do + expect(rendered_component).to have_selector('._card_class_') + expect(rendered_component).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_"]') + end + + it 'renders body options' do + expect(rendered_component).to have_selector('._body_class_') + expect(rendered_component).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_"]') + end + end +end |