Commit 133fa2a8 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch '234013-remove-known-fields-from-trial-sign-up-form' into 'master'

Remove known fields from trial sign up form

See merge request gitlab-org/gitlab!45634
parents c4f79a2f 55b52046
......@@ -13,6 +13,7 @@ class TrialsController < ApplicationController
feature_category :purchase
def new
record_experiment_user(:remove_known_trial_form_fields)
end
def select
......@@ -34,6 +35,7 @@ class TrialsController < ApplicationController
@result = GitlabSubscriptions::ApplyTrialService.new.execute(apply_trial_params)
if @result&.dig(:success)
record_experiment_conversion_event(:remove_known_trial_form_fields)
redirect_to group_url(@namespace, { trial: true })
else
render :select
......
......@@ -10,15 +10,24 @@
= render 'errors'
= form_tag create_lead_trials_path(glm_params), method: :post do |f|
.form-group
= label_tag :first_name, _('First name'), for: :first_name, class: 'col-form-label'
= text_field_tag :first_name, params[:first_name] || current_user.first_name, class: 'form-control', required: true
.form-group
= label_tag :last_name, _('Last name'), for: :last_name, class: 'col-form-label'
= text_field_tag :last_name, params[:last_name] || current_user.last_name, class: 'form-control', required: true
.form-group
= label_tag :company_name, _('Company name'), for: :company_name, class: 'col-form-label'
= text_field_tag :company_name, params[:company_name], class: 'form-control', required: true
- if experiment_enabled?(:remove_known_trial_form_fields) && current_user.first_name.present?
= hidden_field_tag :first_name, current_user.first_name
- else
.form-group
= label_tag :first_name, _('First name'), for: :first_name, class: 'col-form-label'
= text_field_tag :first_name, params[:first_name] || current_user.first_name, class: 'form-control', required: true
- if experiment_enabled?(:remove_known_trial_form_fields) && current_user.last_name.present?
= hidden_field_tag :last_name, current_user.last_name
- else
.form-group
= label_tag :last_name, _('Last name'), for: :last_name, class: 'col-form-label'
= text_field_tag :last_name, params[:last_name] || current_user.last_name, class: 'form-control', required: true
- if experiment_enabled?(:remove_known_trial_form_fields) && current_user.organization.present?
= hidden_field_tag :company_name, current_user.organization
- else
.form-group
= label_tag :company_name, _('Company name'), for: :company_name, class: 'col-form-label'
= text_field_tag :company_name, params[:company_name] || current_user.organization, class: 'form-control', required: true
.form-group.gl-select2-html5-required-fix
= label_tag :company_size, _('Number of employees'), for: :company_size, class: 'col-form-label'
= select_tag :company_size, company_size_options_for_select(params[:company_size]), include_blank: true, class: 'select2', required: true
......
......@@ -3,7 +3,14 @@
require 'spec_helper'
RSpec.describe TrialsController do
let_it_be(:user) { create(:user, email_opted_in: true) }
let_it_be(:user) { create(:user, email_opted_in: true, last_name: 'Doe') }
let_it_be(:experiment_user_context) do
{
first_name_present: user.first_name.present?,
last_name_present: user.last_name.present?,
company_name_present: user.organization.present?
}
end
let(:dev_env_or_com) { true }
let(:logged_in) { true }
......@@ -47,6 +54,12 @@ RSpec.describe TrialsController do
response
end
it 'calls record_experiment_user for the remove_known_trial_form_fields experiment' do
expect(controller).to receive(:record_experiment_user).with(:remove_known_trial_form_fields)
subject
end
it_behaves_like 'an authenticated endpoint'
it_behaves_like 'a dot-com only feature'
end
......@@ -183,6 +196,11 @@ RSpec.describe TrialsController do
let(:apply_trial_result) { true }
it { is_expected.to redirect_to("/#{namespace.path}?trial=true") }
it 'calls the record conversion method for the remove_known_trial_form_fields experiment' do
expect(controller).to receive(:record_experiment_conversion_event).with(:remove_known_trial_form_fields)
subject
end
context 'with a new Group' do
let(:post_params) { { new_group_name: 'GitLab' } }
......@@ -197,6 +215,11 @@ RSpec.describe TrialsController do
let(:apply_trial_result) { false }
it { is_expected.to render_template(:select) }
it 'does not call the record conversion method for the remove_known_trial_form_fields experiment' do
expect(controller).not_to receive(:record_experiment_conversion_event).with(:remove_known_trial_form_fields)
subject
end
context 'with a new Group' do
let(:post_params) { { new_group_name: 'admin' } }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'trials/new.html.haml' do
include ApplicationHelper
let_it_be(:remove_known_trial_form_fields_enabled) { false }
let_it_be(:user) { build(:user) }
before do
allow(view).to receive(:current_user) { user }
allow(view).to receive(:experiment_enabled?).with(:remove_known_trial_form_fields).and_return(remove_known_trial_form_fields_enabled)
render
end
subject { rendered }
it 'has fields for first, last and company names' do
is_expected.to have_field('first_name')
is_expected.to have_field('last_name')
is_expected.to have_field('company_name')
end
context 'remove_known_trial_form_fields experiment is enabled' do
let_it_be(:remove_known_trial_form_fields_enabled) { true }
context 'the user has already values in first, last and company names' do
let_it_be(:user) { build(:user, first_name: 'John', last_name: 'Doe', organization: 'ACME') }
it 'has hidden fields' do
is_expected.to have_field('first_name', type: :hidden)
is_expected.to have_field('last_name', type: :hidden)
is_expected.to have_field('company_name', type: :hidden)
end
end
context 'the user empty values for first, last and company names' do
let_it_be(:user) { build(:user, first_name: '', last_name: '', organization: '') }
it 'has fields' do
is_expected.to have_field('first_name')
is_expected.to have_field('last_name')
is_expected.to have_field('company_name')
end
end
end
end
......@@ -80,6 +80,9 @@ module Gitlab
},
jobs_empty_state: {
tracking_category: 'Growth::Activation::Experiment::JobsEmptyState'
},
remove_known_trial_form_fields: {
tracking_category: 'Growth::Conversion::Experiment::RemoveKnownTrialFormFields'
}
}.freeze
......
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