debian-mirror-gitlab/spec/components/pajamas/banner_component_spec.rb

170 lines
4.6 KiB
Ruby
Raw Normal View History

2022-07-23 23:45:48 +05:30
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Pajamas::BannerComponent, type: :component do
subject do
described_class.new(**options)
end
let(:title) { "Banner title" }
2022-08-27 11:52:29 +05:30
let(:content) { "Banner content" }
2022-07-23 23:45:48 +05:30
let(:options) { {} }
describe 'basic usage' do
before do
render_inline(subject) do |c|
2023-07-09 08:55:56 +05:30
c.with_title { title }
2022-07-23 23:45:48 +05:30
content
end
end
it 'renders its content' do
2022-08-13 15:12:31 +05:30
expect(page).to have_text content
2022-07-23 23:45:48 +05:30
end
it 'renders its title' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "h1[class='gl-banner-title']", text: title
2022-07-23 23:45:48 +05:30
end
it 'renders a close button' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "button.gl-banner-close"
2022-07-23 23:45:48 +05:30
end
describe 'button_text and button_link' do
let(:options) { { button_text: 'Learn more', button_link: '/learn-more' } }
it 'define the primary action' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "a.btn-confirm.gl-button[href='/learn-more']", text: 'Learn more'
2022-07-23 23:45:48 +05:30
end
end
describe 'banner_options' do
let(:options) { { banner_options: { class: "baz", data: { foo: "bar" } } } }
it 'are on the banner' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner.baz[data-foo='bar']"
2022-07-23 23:45:48 +05:30
end
context 'with custom classes' do
let(:options) { { variant: :introduction, banner_options: { class: 'extra special' } } }
it 'don\'t conflict with internal banner_classes' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css '.extra.special.gl-banner-introduction.gl-banner'
2022-07-23 23:45:48 +05:30
end
end
end
describe 'close_options' do
let(:options) { { close_options: { class: "js-foo", data: { uid: "123" } } } }
it 'are on the close button' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "button.gl-banner-close.js-foo[data-uid='123']"
2022-07-23 23:45:48 +05:30
end
end
describe 'embedded' do
context 'by default (false)' do
it 'keeps the banner\'s borders' do
2022-08-13 15:12:31 +05:30
expect(page).not_to have_css ".gl-banner.gl-border-none"
2022-07-23 23:45:48 +05:30
end
end
context 'when set to true' do
let(:options) { { embedded: true } }
it 'removes the banner\'s borders' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner.gl-border-none"
2022-07-23 23:45:48 +05:30
end
end
end
describe 'variant' do
context 'by default (promotion)' do
it 'applies no variant class' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "[class='gl-banner']"
2022-07-23 23:45:48 +05:30
end
end
context 'when set to introduction' do
let(:options) { { variant: :introduction } }
it "applies the introduction class to the banner" do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner.gl-banner-introduction"
2022-07-23 23:45:48 +05:30
end
it "applies the confirm class to the close button" do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner-close.btn-confirm.btn-confirm-tertiary"
2022-07-23 23:45:48 +05:30
end
end
context 'when set to unknown variant' do
let(:options) { { variant: :foobar } }
it 'ignores the unknown variant' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "[class='gl-banner']"
2022-07-23 23:45:48 +05:30
end
end
end
describe 'illustration' do
it 'has none by default' do
2022-08-13 15:12:31 +05:30
expect(page).not_to have_css ".gl-banner-illustration"
2022-07-23 23:45:48 +05:30
end
context 'with svg_path' do
let(:options) { { svg_path: 'logo.svg' } }
it 'renders an image as illustration' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner-illustration img"
2022-07-23 23:45:48 +05:30
end
end
end
end
context 'with illustration slot' do
before do
render_inline(subject) do |c|
2023-07-09 08:55:56 +05:30
c.with_title { title }
c.with_illustration { "<svg></svg>".html_safe }
2022-07-23 23:45:48 +05:30
content
end
end
it 'renders the slot content as illustration' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner-illustration svg"
2022-07-23 23:45:48 +05:30
end
context 'and conflicting svg_path' do
let(:options) { { svg_path: 'logo.svg' } }
it 'uses the slot content' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css ".gl-banner-illustration svg"
expect(page).not_to have_css ".gl-banner-illustration img"
2022-07-23 23:45:48 +05:30
end
end
end
context 'with primary_action slot' do
before do
render_inline(subject) do |c|
2023-07-09 08:55:56 +05:30
c.with_title { title }
c.with_primary_action { "<a class='special' href='#'>Special</a>".html_safe }
2022-07-23 23:45:48 +05:30
content
end
end
it 'renders the slot content as the primary action' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "a.special", text: 'Special'
2022-07-23 23:45:48 +05:30
end
context 'and conflicting button_text and button_link' do
let(:options) { { button_text: 'Not special', button_link: '/' } }
it 'uses the slot content' do
2022-08-13 15:12:31 +05:30
expect(page).to have_css "a.special[href='#']", text: 'Special'
expect(page).not_to have_css "a.btn[href='/']"
2022-07-23 23:45:48 +05:30
end
end
end
end