2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe DashboardHelper do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:user) { build(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#dashboard_nav_links' do
|
|
|
|
it 'has all the expected links by default' do
|
|
|
|
menu_items = [:projects, :groups, :activity, :milestones, :snippets]
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(helper.dashboard_nav_links).to include(*menu_items)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain cross project elements when the user cannot read cross project' do
|
|
|
|
expect(helper).to receive(:can?).with(user, :read_cross_project) { false }
|
|
|
|
|
|
|
|
expect(helper.dashboard_nav_links).not_to include(:activity, :milestones)
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe '#feature_entry' do
|
2019-12-26 22:10:19 +05:30
|
|
|
shared_examples "a feature is enabled" do
|
|
|
|
it { is_expected.to include('<p aria-label="Demo: status on">') }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "a feature is disabled" do
|
|
|
|
it { is_expected.to include('<p aria-label="Demo: status off">') }
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
shared_examples "a feature without link" do
|
|
|
|
it do
|
|
|
|
is_expected.not_to have_link('Demo')
|
|
|
|
is_expected.not_to have_link('Documentation')
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
shared_examples "a feature with configuration" do
|
|
|
|
it { is_expected.to have_link('Demo', href: 'demo.link') }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "a feature with documentation" do
|
|
|
|
it { is_expected.to have_link('Documentation', href: 'doc.link') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when implicitly enabled' do
|
|
|
|
subject { feature_entry('Demo') }
|
|
|
|
|
|
|
|
it_behaves_like 'a feature is enabled'
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'when explicitly enabled' do
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'without links' do
|
|
|
|
subject { feature_entry('Demo', enabled: true) }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it_behaves_like 'a feature is enabled'
|
|
|
|
it_behaves_like 'a feature without link'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'with configure link' do
|
|
|
|
subject { feature_entry('Demo', href: 'demo.link', enabled: true) }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it_behaves_like 'a feature with configuration'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with configure and documentation links' do
|
|
|
|
subject { feature_entry('Demo', href: 'demo.link', doc_href: 'doc.link', enabled: true) }
|
|
|
|
|
|
|
|
it_behaves_like 'a feature with configuration'
|
|
|
|
it_behaves_like 'a feature with documentation'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when disabled' do
|
2019-12-26 22:10:19 +05:30
|
|
|
subject { feature_entry('Demo', href: 'demo.link', enabled: false) }
|
2019-10-12 21:52:04 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it_behaves_like 'a feature is disabled'
|
|
|
|
it_behaves_like 'a feature without link'
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
describe '.has_start_trial?' do
|
|
|
|
subject { helper.has_start_trial? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe '#reviewer_mrs_dashboard_path' do
|
|
|
|
subject { helper.reviewer_mrs_dashboard_path }
|
|
|
|
|
|
|
|
it { is_expected.to eq(merge_requests_dashboard_path(reviewer_username: user.username)) }
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|