Commit 477359a2 authored by Doug Stull's avatar Doug Stull Committed by Heinrich Lee Yu

Track notification dot

- needed for metrics
parent 27b453cb
- return unless show_user_notification_dot?(project, namespace) - return unless show_user_notification_dot?(project, namespace)
-# Tracking events from the template is not ideal and we are moving this to the client in https://gitlab.com/gitlab-org/gitlab/-/issues/213712
- track_event('show_buy_ci_minutes_notification', label: current_user.namespace.actual_plan_name, property: 'user_dropdown')
%span.header-user-notification-dot.rounded-circle.position-relative %span.header-user-notification-dot.rounded-circle.position-relative
# frozen_string_literal: true
require 'spec_helper'
describe 'User notification dot', :aggregate_failures do
let_it_be(:user) { create(:user) }
let(:project) { create(:project, namespace: group, creator: user, shared_runners_enabled: true) }
let(:group) { create(:group) }
let!(:user_pipelines) { create(:ci_pipeline, user: user, project: project) }
before do
stub_experiment_for_user(ci_notification_dot: true)
group.add_developer(user)
sign_in(user)
end
context 'when ci minutes are below threshold' do
before do
group.update(last_ci_minutes_usage_notification_level: 30, shared_runners_minutes_limit: 10)
allow_any_instance_of(EE::Namespace).to receive(:shared_runners_remaining_minutes).and_return(2)
end
it 'shows notification dot' do
expect_next_instance_of(ProjectsController) do |ctrl|
expect(ctrl).to receive(:track_event)
.with('show_buy_ci_minutes_notification', label: 'free', property: 'user_dropdown')
end
visit project_path(project)
expect(page).to have_css('span', class: 'header-user-notification-dot')
end
end
context 'when ci minutes are not below threshold' do
let(:group) { create(:group, :with_not_used_build_minutes_limit) }
it 'shows notification dot' do
expect_next_instance_of(ProjectsController) do |ctrl|
expect(ctrl).not_to receive(:track_event)
end
visit project_path(project)
expect(page).not_to have_css('span', class: 'header-user-notification-dot')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'layouts/application' do
let_it_be(:user) { create(:user) }
let(:show_notification_dot) { false }
before do
allow(view).to receive(:experiment_enabled?).and_return(false)
allow(view).to receive(:session).and_return({})
allow(view).to receive(:user_signed_in?).and_return(true)
allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_user_mode).and_return(Gitlab::Auth::CurrentUserMode.new(user))
allow(view).to receive(:show_user_notification_dot?).and_return(show_notification_dot)
end
describe 'layouts/_user_notification_dot' do
context 'when we show the notification dot' do
let(:show_notification_dot) { true }
it 'has the notification dot' do
expect(view).to receive(:track_event).with('show_buy_ci_minutes_notification', label: 'free', property: 'user_dropdown')
render
expect(rendered).to have_css('span', class: 'header-user-notification-dot')
end
end
context 'when we do not show the notification dot' do
it 'does not have the notification dot' do
render
expect(rendered).not_to have_css('span', class: 'header-user-notification-dot')
end
end
end
end
...@@ -9,6 +9,13 @@ module Gitlab ...@@ -9,6 +9,13 @@ module Gitlab
module ControllerConcern module ControllerConcern
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do
# Tracking events from the template is not ideal and we are moving this to the client in https://gitlab.com/gitlab-org/gitlab/-/issues/213712
# In the meantime, using this method from the view is frowned upon and this line will likely be removed
# in the near future
helper_method :track_event
end
protected protected
def track_event(action = action_name, **args) def track_event(action = action_name, **args)
......
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