2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-11 09:21:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe DashboardHelper do
|
2017-12-11 09:21:06 -05:00
|
|
|
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-07-03 14:29:17 -04:00
|
|
|
expect(helper.dashboard_nav_links).to include(*menu_items)
|
2017-12-11 09:21:06 -05:00
|
|
|
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-05-11 00:16:19 -04:00
|
|
|
|
2019-04-19 05:44:21 -04:00
|
|
|
describe '#feature_entry' do
|
2019-10-29 05:06:10 -04:00
|
|
|
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-04-19 05:44:21 -04:00
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
shared_examples "a feature without link" do
|
|
|
|
it do
|
|
|
|
is_expected.not_to have_link('Demo')
|
|
|
|
is_expected.not_to have_link('Documentation')
|
2019-04-19 05:44:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
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-04-19 05:44:21 -04:00
|
|
|
context 'when explicitly enabled' do
|
2019-10-29 05:06:10 -04:00
|
|
|
context 'without links' do
|
|
|
|
subject { feature_entry('Demo', enabled: true) }
|
2019-04-19 05:44:21 -04:00
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
it_behaves_like 'a feature is enabled'
|
|
|
|
it_behaves_like 'a feature without link'
|
2019-04-19 05:44:21 -04:00
|
|
|
end
|
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
context 'with configure link' do
|
|
|
|
subject { feature_entry('Demo', href: 'demo.link', enabled: true) }
|
2019-04-19 05:44:21 -04:00
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
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-04-19 05:44:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when disabled' do
|
2019-10-29 05:06:10 -04:00
|
|
|
subject { feature_entry('Demo', href: 'demo.link', enabled: false) }
|
2019-04-19 05:44:21 -04:00
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
it_behaves_like 'a feature is disabled'
|
|
|
|
it_behaves_like 'a feature without link'
|
2019-04-19 05:44:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-11 00:16:19 -04:00
|
|
|
describe '.has_start_trial?' do
|
|
|
|
subject { helper.has_start_trial? }
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
2017-12-11 09:21:06 -05:00
|
|
|
end
|