Commit 7336ec90 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '346260_render_manual_quarterly_co_term_banner' into 'master'

Render manual quarterly co-term banner

See merge request gitlab-org/gitlab!76256
parents 944d6ed5 5300d93e
......@@ -4,6 +4,7 @@
- billable_users_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer nofollow">'.html_safe % { url: billable_users_url }
= render_if_exists 'shared/manual_renewal_banner'
= render_if_exists 'shared/manual_quarterly_reconciliation_banner'
= render_if_exists 'shared/qrtly_reconciliation_alert'
= render 'admin/dashboard/security_newsletter_callout'
......
# frozen_string_literal: true
module ManualQuarterlyCoTermBannerHelper
def manual_quarterly_co_term_banner
return unless current_user&.can_admin_all_resources?
upcoming_reconciliation = GitlabSubscriptions::UpcomingReconciliation.next
Gitlab::ManualQuarterlyCoTermBanner.new(actionable: upcoming_reconciliation)
end
end
......@@ -2,5 +2,6 @@
- page_title _('Subscription')
= render_if_exists 'shared/manual_renewal_banner'
= render_if_exists 'shared/manual_quarterly_reconciliation_banner'
#js-show-subscription-page{ data: cloud_license_view_data }
- payload = manual_quarterly_co_term_banner
- return unless payload&.display?
= content_for :page_level_alert do
= render 'shared/global_alert',
title: payload.subject,
variant: payload.display_error_version? ? :danger : :warning,
close_button_class: 'js-close',
alert_class: 'gl-my-5',
alert_data: { testid: 'close-manual-quarterly-co-term-banner' } do
.gl-alert-body
= payload.body
.gl-alert-actions
= link_to s_('SubscriptionBanner|Export license usage file'), admin_license_usage_export_path(format: :csv), class: 'btn gl-alert-action gl-button btn-confirm'
= link_to s_('SubscriptionBanner|Upload new license'), new_admin_license_path, class: 'btn gl-alert-action gl-button btn-default'
......@@ -100,4 +100,5 @@ RSpec.describe 'Admin Dashboard' do
end
include_examples 'manual renewal banner', path_to_visit: :admin_subscription_path
include_examples 'manual quarterly co-term banner', path_to_visit: :admin_subscription_path
end
......@@ -225,6 +225,7 @@ RSpec.describe 'Admin views Subscription', :js do
end
include_examples 'manual renewal banner', path_to_visit: :admin_subscription_path
include_examples 'manual quarterly co-term banner', path_to_visit: :admin_subscription_path
private
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ManualQuarterlyCoTermBannerHelper do
describe '#manual_quarterly_co_term_banner' do
subject(:manual_quarterly_co_term_banner) { helper.manual_quarterly_co_term_banner }
let_it_be(:current_user) { create(:admin) }
before do
allow(helper).to receive(:current_user).and_return(current_user)
end
context 'when current user is empty' do
let(:current_user) { nil }
it 'does not return a banner payload' do
expect(manual_quarterly_co_term_banner).to eq(nil)
end
end
context 'when current user cannot admin all resources' do
it 'does not return a banner payload' do
expect(manual_quarterly_co_term_banner).to eq(nil)
end
end
context 'when current user can admin all resources' do
before do
allow(current_user).to receive(:can_admin_all_resources?).and_return(true)
allow_next_instance_of(Gitlab::ManualQuarterlyCoTermBanner) do |banner|
allow(banner).to receive(:display?).and_return(display_banner)
end
end
context 'when no banner instance is returned' do
let(:display_banner) { false }
it 'does not return a banner payload' do
aggregate_failures do
expect(manual_quarterly_co_term_banner).to be_an_instance_of(Gitlab::ManualQuarterlyCoTermBanner)
expect(manual_quarterly_co_term_banner.subject).to eq(nil)
end
end
end
context 'when a banner instance is returned' do
let(:display_banner) { true }
let(:upcoming_reconciliation) do
create(:upcoming_reconciliation, :self_managed, next_reconciliation_date: next_reconciliation_date)
end
before do
allow(GitlabSubscriptions::UpcomingReconciliation).to receive(:next).and_return(upcoming_reconciliation)
end
context 'when reconciliation is overdue' do
let!(:next_reconciliation_date) { Date.yesterday }
it 'returns a banner payload' do
aggregate_failures do
expect(manual_quarterly_co_term_banner).to be_an_instance_of(Gitlab::ManualQuarterlyCoTermBanner)
expect(manual_quarterly_co_term_banner.body).to include('GitLab must now reconcile your subscription')
expect(manual_quarterly_co_term_banner.display_error_version?).to eq(true)
end
end
end
context 'when reconciliation is upcoming' do
let(:next_reconciliation_date) { Date.current + 60.days }
it 'returns a banner payload' do
aggregate_failures do
expect(manual_quarterly_co_term_banner).to be_an_instance_of(Gitlab::ManualQuarterlyCoTermBanner)
expect(manual_quarterly_co_term_banner.body).to include('GitLab must reconcile your subscription')
expect(manual_quarterly_co_term_banner.display_error_version?).to eq(false)
end
end
end
end
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'manual quarterly co-term banner' do |path_to_visit:|
shared_examples 'a visible dismissible manual quarterly co-term banner' do
context 'when dismissed' do
before do
page.within(find('[data-testid="close-manual-quarterly-co-term-banner"]', match: :first)) do
click_button 'Dismiss'
end
end
it_behaves_like 'a hidden manual quarterly co-term banner'
context 'when visiting again' do
before do
visit current_path
end
it 'displays a banner' do
expect(page).to have_selector('[data-testid="close-manual-quarterly-co-term-banner"]')
end
end
end
end
shared_examples 'a hidden manual quarterly co-term banner' do
it 'does not display a banner' do
expect(page).not_to have_selector('[data-testid="close-manual-quarterly-co-term-banner"]')
end
end
describe 'manual quarterly co-term banner', :js do
let_it_be(:reminder_days) { Gitlab::ManualQuarterlyCoTermBanner::REMINDER_DAYS }
before do
allow(Gitlab::CurrentSettings).to receive(:should_check_namespace_plan?) { should_check_namespace_plan? }
create(:upcoming_reconciliation, type, next_reconciliation_date: reconciliation_date)
visit(send(path_to_visit))
end
context 'when on Gitlab.com' do
let(:reconciliation_date) { Date.current }
let(:should_check_namespace_plan?) { true }
let(:type) { :saas }
it_behaves_like 'a hidden manual quarterly co-term banner'
end
context 'when on self-managed' do
let(:should_check_namespace_plan?) { false }
let(:type) { :self_managed }
context 'when reconciliation is upcoming' do
context 'within notification window' do
let(:reconciliation_date) { Date.current + reminder_days }
it_behaves_like 'a visible dismissible manual quarterly co-term banner'
end
context 'outside of notification window' do
let(:reconciliation_date) { Date.tomorrow + reminder_days }
it_behaves_like 'a hidden manual quarterly co-term banner'
end
end
context 'when reconciliation date was passed' do
let(:reconciliation_date) { Date.current }
it_behaves_like 'a visible dismissible manual quarterly co-term banner'
end
context 'when reconciliation date is outside of the notification window' do
let(:reconciliation_date) { 1.month.from_now.to_date }
it_behaves_like 'a hidden manual quarterly co-term banner'
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment