2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'layouts/_flash' do
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:template) { 'layouts/_flash' }
|
|
|
|
let_it_be(:flash_container_no_margin_class) { 'flash-container-no-margin' }
|
|
|
|
|
|
|
|
let(:locals) { {} }
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
before do
|
|
|
|
allow(view).to receive(:flash).and_return(flash)
|
2022-11-25 23:54:43 +05:30
|
|
|
render(template: template, locals: locals)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'default' do
|
|
|
|
it 'does not render flash container no margin class' do
|
|
|
|
expect(rendered).not_to have_selector(".#{flash_container_no_margin_class}")
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'closable flash messages' do
|
2022-08-13 15:12:31 +05:30
|
|
|
where(:flash_type) do
|
|
|
|
%w[alert notice success]
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:flash) { { flash_type => 'This is a closable flash message' } }
|
|
|
|
|
|
|
|
it 'shows a close button' do
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(rendered).to include('js-close')
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'non closable flash messages' do
|
2022-08-13 15:12:31 +05:30
|
|
|
where(:flash_type) do
|
|
|
|
%w[error message toast warning]
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2020-10-24 23:57:45 +05:30
|
|
|
let(:flash) { { flash_type => 'This is a non closable flash message' } }
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it 'does not show a close button' do
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(rendered).not_to include('js-close')
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
describe 'with flash_class in locals' do
|
|
|
|
let(:locals) { { flash_container_no_margin: true } }
|
|
|
|
|
|
|
|
it 'adds class to flash-container' do
|
|
|
|
expect(rendered).to have_selector(".flash-container.#{flash_container_no_margin_class}")
|
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|