diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/lib/learn_gitlab | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/lib/learn_gitlab')
-rw-r--r-- | spec/lib/learn_gitlab/onboarding_spec.rb | 46 | ||||
-rw-r--r-- | spec/lib/learn_gitlab/project_spec.rb | 61 |
2 files changed, 107 insertions, 0 deletions
diff --git a/spec/lib/learn_gitlab/onboarding_spec.rb b/spec/lib/learn_gitlab/onboarding_spec.rb new file mode 100644 index 00000000000..6b4be65f3b2 --- /dev/null +++ b/spec/lib/learn_gitlab/onboarding_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe LearnGitlab::Onboarding do + describe '#completed_percentage' do + let(:completed_actions) { {} } + let(:onboarding_progress) { build(:onboarding_progress, namespace: namespace, **completed_actions) } + let(:namespace) { build(:namespace) } + + let_it_be(:tracked_action_columns) do + tracked_actions = described_class::ACTION_ISSUE_IDS.keys + described_class::ACTION_DOC_URLS.keys + tracked_actions.map { |key| OnboardingProgress.column_name(key) } + end + + before do + expect(OnboardingProgress).to receive(:find_by).with(namespace: namespace).and_return(onboarding_progress) + end + + subject { described_class.new(namespace).completed_percentage } + + context 'when no onboarding_progress exists' do + let(:onboarding_progress) { nil } + + it { is_expected.to eq(0) } + end + + context 'when no action has been completed' do + it { is_expected.to eq(0) } + end + + context 'when one action has been completed' do + let(:completed_actions) { Hash[tracked_action_columns.first, Time.current] } + + it { is_expected.to eq(11) } + end + + context 'when all tracked actions have been completed' do + let(:completed_actions) do + tracked_action_columns.to_h { |action| [action, Time.current] } + end + + it { is_expected.to eq(100) } + end + end +end diff --git a/spec/lib/learn_gitlab/project_spec.rb b/spec/lib/learn_gitlab/project_spec.rb new file mode 100644 index 00000000000..523703761bf --- /dev/null +++ b/spec/lib/learn_gitlab/project_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe LearnGitlab::Project do + let_it_be(:current_user) { create(:user) } + let_it_be(:learn_gitlab_project) { create(:project, name: LearnGitlab::Project::PROJECT_NAME) } + let_it_be(:learn_gitlab_board) { create(:board, project: learn_gitlab_project, name: LearnGitlab::Project::BOARD_NAME) } + let_it_be(:learn_gitlab_label) { create(:label, project: learn_gitlab_project, name: LearnGitlab::Project::LABEL_NAME) } + + before do + learn_gitlab_project.add_developer(current_user) + end + + describe '.available?' do + using RSpec::Parameterized::TableSyntax + + where(:project, :board, :label, :expected_result) do + nil | nil | nil | nil + nil | nil | true | nil + nil | true | nil | nil + nil | true | true | nil + true | nil | nil | nil + true | nil | true | nil + true | true | nil | nil + true | true | true | true + end + + with_them do + before do + allow_next_instance_of(described_class) do |learn_gitlab| + allow(learn_gitlab).to receive(:project).and_return(project) + allow(learn_gitlab).to receive(:board).and_return(board) + allow(learn_gitlab).to receive(:label).and_return(label) + end + end + + subject { described_class.new(current_user).available? } + + it { is_expected.to be expected_result } + end + end + + describe '.project' do + subject { described_class.new(current_user).project } + + it { is_expected.to eq learn_gitlab_project } + end + + describe '.board' do + subject { described_class.new(current_user).board } + + it { is_expected.to eq learn_gitlab_board } + end + + describe '.label' do + subject { described_class.new(current_user).label } + + it { is_expected.to eq learn_gitlab_label } + end +end |