Commit 1a82c5da authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'onboarding-experiment-apply-novice-filter' into 'master'

Onboarding experiment apply novice filter

See merge request gitlab-org/gitlab!34761
parents 1a638c32 12bb6f3c
......@@ -33,12 +33,13 @@ module Registrations
def hide_advanced_issues
return unless current_user.user_preference.novice?
return unless learn_gitlab.available?
settings = cookies[:onboarding_issues_settings]
return unless settings
Boards::UpdateService.new(learn_gitlab.project, current_user, label_ids: [learn_gitlab.label.id]).execute(learn_gitlab.board)
end
modified_settings = Gitlab::Json.parse(settings).merge(hideAdvanced: true)
cookies[:onboarding_issues_settings] = modified_settings.to_json
def learn_gitlab
@learn_gitlab ||= LearnGitlab.new(current_user)
end
end
end
# frozen_string_literal: true
class LearnGitlab
PROJECT_NAME = 'Learn GitLab'.freeze
BOARD_NAME = 'GitLab onboarding'.freeze
LABEL_NAME = 'Novice'.freeze
def initialize(current_user)
@current_user = current_user
end
def available?
project && board && label
end
def project
@project ||= current_user.projects.find_by_name(PROJECT_NAME)
end
def board
return unless project
@board ||= project.boards.find_by_name(BOARD_NAME)
end
def label
return unless project
@label ||= project.labels.find_by_name(LABEL_NAME)
end
private
attr_reader :current_user
end
......@@ -99,34 +99,51 @@ describe Registrations::ExperienceLevelsController do
end
describe 'applying the chosen level' do
context "when an 'onboarding_issues_settings' cookie does not exist" do
let(:params) { super().merge(experience_level: :novice) }
it 'does not change the cookie' do
expect { subject }.not_to change { cookies[:onboarding_issues_settings] }
end
end
context "when an 'onboarding_issues_settings' cookie does exist" do
context 'when a "Learn GitLab" project is available' do
before do
request.cookies[:onboarding_issues_settings] = '{}'
allow_next_instance_of(LearnGitlab) do |learn_gitlab|
allow(learn_gitlab).to receive(:available?).and_return(true)
allow(learn_gitlab).to receive(:label).and_return(double(id: 1))
end
end
context 'when novice' do
let(:params) { super().merge(experience_level: :novice) }
it "adds a 'hideAdvanced' setting to the cookie" do
expect { subject }.to change { Gitlab::Json.parse(cookies[:onboarding_issues_settings])['hideAdvanced'] }.from(nil).to(true)
it 'adds a BoardLabel' do
expect_next_instance_of(Boards::UpdateService) do |service|
expect(service).to receive(:execute)
end
subject
end
end
context 'when experienced' do
let(:params) { super().merge(experience_level: :experienced) }
it 'does not change the cookie' do
expect { subject }.not_to change { cookies[:onboarding_issues_settings] }
it 'does not add a BoardLabel' do
expect(Boards::UpdateService).not_to receive(:new)
subject
end
end
end
context 'when no "Learn GitLab" project exists' do
let(:params) { super().merge(experience_level: :novice) }
before do
allow_next_instance_of(LearnGitlab) do |learn_gitlab|
allow(learn_gitlab).to receive(:available?).and_return(false)
end
end
it 'does not add a BoardLabel' do
expect(Boards::UpdateService).not_to receive(:new)
subject
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe LearnGitlab do
let_it_be(:current_user) { create(:user) }
let_it_be(:learn_gitlab_project) { create(:project, name: LearnGitlab::PROJECT_NAME) }
let_it_be(:learn_gitlab_board) { create(:board, project: learn_gitlab_project, name: LearnGitlab::BOARD_NAME) }
let_it_be(:learn_gitlab_label) { create(:label, project: learn_gitlab_project, name: LearnGitlab::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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment