diff options
Diffstat (limited to 'spec/helpers/learn_gitlab_helper_spec.rb')
-rw-r--r-- | spec/helpers/learn_gitlab_helper_spec.rb | 128 |
1 files changed, 101 insertions, 27 deletions
diff --git a/spec/helpers/learn_gitlab_helper_spec.rb b/spec/helpers/learn_gitlab_helper_spec.rb index 1159fd96d59..7ff79f19eed 100644 --- a/spec/helpers/learn_gitlab_helper_spec.rb +++ b/spec/helpers/learn_gitlab_helper_spec.rb @@ -11,9 +11,6 @@ RSpec.describe LearnGitlabHelper do let_it_be(:namespace) { project.namespace } before do - project.add_developer(user) - - allow(helper).to receive(:user).and_return(user) allow_next_instance_of(LearnGitlab::Project) do |learn_gitlab| allow(learn_gitlab).to receive(:project).and_return(project) end @@ -22,38 +19,115 @@ RSpec.describe LearnGitlabHelper do OnboardingProgress.register(namespace, :git_write) end - describe '.onboarding_actions_data' do + 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( - :issue_created, - :git_write, - :pipeline_created, - :merge_request_created, - :user_added, - :trial_started, - :required_mr_approvals_enabled, - :code_owners_enabled, - :security_scan_enabled - ) + shared_examples 'has all actions' do + it 'has all actions' do + expect(onboarding_actions_data.keys).to contain_exactly( + :issue_created, + :git_write, + :pipeline_created, + :merge_request_created, + :user_added, + :trial_started, + :required_mr_approvals_enabled, + :code_owners_enabled, + :security_scan_enabled + ) + end end - it 'sets correct path and completion status' do - expect(onboarding_actions_data[:git_write]).to eq({ - url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:git_write]), - completed: true, - svg: helper.image_path("learn_gitlab/git_write.svg") + it_behaves_like 'has all actions' + + it 'sets correct paths' do + expect(onboarding_actions_data).to match({ + trial_started: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/2\z}) + ), + issue_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/4\z}) + ), + git_write: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/6\z}) + ), + pipeline_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/7\z}) + ), + user_added: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/8\z}) + ), + merge_request_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/9\z}) + ), + code_owners_enabled: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/10\z}) + ), + required_mr_approvals_enabled: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/11\z}) + ), + security_scan_enabled: a_hash_including( + url: a_string_matching(%r{docs\.gitlab\.com/ee/user/application_security/security_dashboard/#gitlab-security-dashboard-security-center-and-vulnerability-reports\z}) + ) }) - expect(onboarding_actions_data[:pipeline_created]).to eq({ - url: project_issue_url(project, LearnGitlab::Onboarding::ACTION_ISSUE_IDS[:pipeline_created]), - completed: false, - svg: helper.image_path("learn_gitlab/pipeline_created.svg") + end + + it 'sets correct completion statuses' do + expect(onboarding_actions_data).to match({ + issue_created: a_hash_including(completed: false), + git_write: a_hash_including(completed: true), + pipeline_created: a_hash_including(completed: false), + merge_request_created: a_hash_including(completed: false), + user_added: a_hash_including(completed: false), + trial_started: a_hash_including(completed: false), + required_mr_approvals_enabled: a_hash_including(completed: false), + code_owners_enabled: a_hash_including(completed: false), + security_scan_enabled: a_hash_including(completed: false) }) end + + context 'when in the new action URLs experiment' do + before do + stub_experiments(change_continuous_onboarding_link_urls: :candidate) + end + + it_behaves_like 'has all actions' + + it 'sets mostly new paths' do + expect(onboarding_actions_data).to match({ + trial_started: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/2\z}) + ), + issue_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues\z}) + ), + git_write: a_hash_including( + url: a_string_matching(%r{/learn_gitlab\z}) + ), + pipeline_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/pipelines\z}) + ), + user_added: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/project_members\z}) + ), + merge_request_created: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/merge_requests\z}) + ), + code_owners_enabled: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/10\z}) + ), + required_mr_approvals_enabled: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/issues/11\z}) + ), + security_scan_enabled: a_hash_including( + url: a_string_matching(%r{/learn_gitlab/-/security/configuration\z}) + ) + }) + end + end end - describe '.learn_gitlab_enabled?' do + describe '#learn_gitlab_enabled?' do using RSpec::Parameterized::TableSyntax let_it_be(:user) { create(:user) } @@ -89,7 +163,7 @@ RSpec.describe LearnGitlabHelper do end end - describe '.onboarding_sections_data' do + describe '#onboarding_sections_data' do subject(:sections) { helper.onboarding_sections_data } it 'has the right keys' do |