2021-02-16 04:09:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe LearnGitlabHelper do
|
|
|
|
include AfterNextHelpers
|
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
2021-04-30 08:12:30 -04:00
|
|
|
let_it_be(:project) { create(:project, name: LearnGitlab::Project::PROJECT_NAME, namespace: user.namespace) }
|
2021-02-16 04:09:36 -05:00
|
|
|
let_it_be(:namespace) { project.namespace }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
allow(helper).to receive(:user).and_return(user)
|
2021-04-30 08:12:30 -04:00
|
|
|
allow_next_instance_of(LearnGitlab::Project) do |learn_gitlab|
|
2021-02-16 04:09:36 -05:00
|
|
|
allow(learn_gitlab).to receive(:project).and_return(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
OnboardingProgress.onboard(namespace)
|
|
|
|
OnboardingProgress.register(namespace, :git_write)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.onboarding_actions_data' do
|
|
|
|
subject(:onboarding_actions_data) { helper.onboarding_actions_data(project) }
|
|
|
|
|
|
|
|
it 'has all actions' do
|
|
|
|
expect(onboarding_actions_data.keys).to contain_exactly(
|
2021-04-13 14:11:28 -04:00
|
|
|
:issue_created,
|
2021-02-16 04:09:36 -05:00
|
|
|
:git_write,
|
|
|
|
:pipeline_created,
|
|
|
|
:merge_request_created,
|
|
|
|
:user_added,
|
|
|
|
:trial_started,
|
|
|
|
:required_mr_approvals_enabled,
|
|
|
|
:code_owners_enabled,
|
|
|
|
:security_scan_enabled
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets correct path and completion status' do
|
|
|
|
expect(onboarding_actions_data[:git_write]).to eq({
|
2021-04-30 08:12:30 -04:00
|
|
|
url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:git_write]),
|
2021-02-23 13:10:40 -05:00
|
|
|
completed: true,
|
|
|
|
svg: helper.image_path("learn_gitlab/git_write.svg")
|
2021-02-16 04:09:36 -05:00
|
|
|
})
|
|
|
|
expect(onboarding_actions_data[:pipeline_created]).to eq({
|
2021-04-30 08:12:30 -04:00
|
|
|
url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:pipeline_created]),
|
2021-02-23 13:10:40 -05:00
|
|
|
completed: false,
|
|
|
|
svg: helper.image_path("learn_gitlab/pipeline_created.svg")
|
2021-02-16 04:09:36 -05:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
describe '.learn_gitlab_enabled?' do
|
2021-02-16 04:09:36 -05:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: user.namespace) }
|
|
|
|
|
|
|
|
let(:params) { { namespace_id: project.namespace.to_param, project_id: project } }
|
|
|
|
|
2021-09-13 11:10:34 -04:00
|
|
|
subject { helper.learn_gitlab_enabled?(project) }
|
2021-02-16 04:09:36 -05:00
|
|
|
|
2021-09-01 05:10:58 -04:00
|
|
|
where(:onboarding, :learn_gitlab_available, :result) do
|
|
|
|
true | true | true
|
|
|
|
true | false | false
|
|
|
|
false | true | false
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(OnboardingProgress).to receive(:onboarding?).with(project.namespace).and_return(onboarding)
|
2021-04-30 08:12:30 -04:00
|
|
|
allow_next(LearnGitlab::Project, user).to receive(:available?).and_return(learn_gitlab_available)
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when signed in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(result) }
|
|
|
|
end
|
2021-05-04 20:10:41 -04:00
|
|
|
end
|
2021-02-16 04:09:36 -05:00
|
|
|
|
2021-05-04 20:10:41 -04:00
|
|
|
context 'when not signed in' do
|
|
|
|
it { is_expected.to eq(false) }
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
end
|
2021-04-30 17:10:23 -04:00
|
|
|
|
2021-05-06 14:10:06 -04:00
|
|
|
describe '.onboarding_sections_data' do
|
|
|
|
subject(:sections) { helper.onboarding_sections_data }
|
|
|
|
|
|
|
|
it 'has the right keys' do
|
|
|
|
expect(sections.keys).to contain_exactly(:deploy, :plan, :workspace)
|
|
|
|
end
|
|
|
|
it 'has the svg' do
|
|
|
|
expect(sections.values.map { |section| section.keys }).to eq([[:svg]] * 3)
|
|
|
|
end
|
|
|
|
end
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|