2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe WhatsNewHelper do
|
2021-04-29 21:17:54 +05:30
|
|
|
include Devise::Test::ControllerHelpers
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe '#whats_new_version_digest' do
|
|
|
|
let(:digest) { 'digest' }
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it 'calls ReleaseHighlight.most_recent_version_digest' do
|
|
|
|
expect(ReleaseHighlight).to receive(:most_recent_version_digest).and_return(digest)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(helper.whats_new_version_digest).to eq(digest)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#whats_new_most_recent_release_items_count' do
|
|
|
|
subject { helper.whats_new_most_recent_release_items_count }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'when recent release items exist' do
|
|
|
|
it 'returns the count from the most recent file' do
|
2021-02-22 17:27:13 +05:30
|
|
|
allow(ReleaseHighlight).to receive(:most_recent_item_count).and_return(1)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(subject).to eq(1)
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'when recent release items do NOT exist' do
|
2021-02-22 17:27:13 +05:30
|
|
|
it 'returns nil' do
|
|
|
|
allow(ReleaseHighlight).to receive(:most_recent_item_count).and_return(nil)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe '#display_whats_new?' do
|
|
|
|
subject { helper.display_whats_new? }
|
|
|
|
|
|
|
|
it 'returns true when gitlab.com' do
|
2022-05-07 20:08:51 +05:30
|
|
|
allow(Gitlab).to receive(:org_or_com?).and_return(true)
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-managed' do
|
|
|
|
before do
|
2022-05-07 20:08:51 +05:30
|
|
|
allow(Gitlab).to receive(:org_or_com?).and_return(false)
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it 'returns true if user is signed in' do
|
|
|
|
sign_in(create(:user))
|
|
|
|
|
|
|
|
expect(subject).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if user isn't signed in" do
|
|
|
|
expect(subject).to be false
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
context 'depending on whats_new_variant' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:variant, :result) do
|
|
|
|
:all_tiers | true
|
|
|
|
:current_tier | true
|
|
|
|
:disabled | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns correct result depending on variant' do
|
2022-05-07 20:08:51 +05:30
|
|
|
allow(Gitlab).to receive(:org_or_com?).and_return(true)
|
2021-06-08 01:23:25 +05:30
|
|
|
Gitlab::CurrentSettings.update!(whats_new_variant: ApplicationSetting.whats_new_variants[variant])
|
|
|
|
|
|
|
|
expect(subject).to eq(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#whats_new_variants' do
|
|
|
|
it 'returns ApplicationSetting.whats_new_variants' do
|
|
|
|
expect(helper.whats_new_variants).to eq(ApplicationSetting.whats_new_variants)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#whats_new_variants_label' do
|
|
|
|
let(:labels) do
|
|
|
|
[
|
|
|
|
helper.whats_new_variants_label('all_tiers'),
|
|
|
|
helper.whats_new_variants_label('current_tier'),
|
|
|
|
helper.whats_new_variants_label('disabled'),
|
|
|
|
helper.whats_new_variants_label(nil)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns different labels depending on variant' do
|
|
|
|
expect(labels.uniq.size).to eq(labels.size)
|
|
|
|
expect(labels[3]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#whats_new_variants_description' do
|
|
|
|
let(:descriptions) do
|
|
|
|
[
|
|
|
|
helper.whats_new_variants_description('all_tiers'),
|
|
|
|
helper.whats_new_variants_description('current_tier'),
|
|
|
|
helper.whats_new_variants_description('disabled'),
|
|
|
|
helper.whats_new_variants_description(nil)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns different descriptions depending on variant' do
|
|
|
|
expect(descriptions.uniq.size).to eq(descriptions.size)
|
|
|
|
expect(descriptions[3]).to be_nil
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|