Commit f499165e authored by Luke Duncalfe's avatar Luke Duncalfe

Merge branch '321191-track-group-coverage-views-usage-ping-in-vue-instead' into 'master'

Track group coverage visits in vue instead

See merge request gitlab-org/gitlab!55687
parents 415f0254 ef2efb83
<script>
import Api from '~/api';
import { s__ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import DownloadTestCoverage from './download_test_coverage.vue';
import TestCoverageSummary from './test_coverage_summary.vue';
import TestCoverageTable from './test_coverage_table.vue';
export const VISIT_EVENT_FEATURE_FLAG = 'usageDataITestingGroupCodeCoverageVisitTotal';
export const VISIT_EVENT_NAME = 'i_testing_group_code_coverage_visit_total';
export default {
name: 'GroupRepositoryAnalytics',
components: {
......@@ -13,6 +17,11 @@ export default {
DownloadTestCoverage,
},
mixins: [glFeatureFlagsMixin()],
mounted() {
if (this.glFeatures[VISIT_EVENT_FEATURE_FLAG]) {
Api.trackRedisHllUserEvent(VISIT_EVENT_NAME);
}
},
text: {
codeCoverageHeader: s__('RepositoriesAnalytics|Test Code Coverage'),
},
......
# frozen_string_literal: true
class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::ApplicationController
include RedisTracking
layout 'group'
before_action :load_group
before_action -> { check_feature_availability!(:group_repository_analytics) }
before_action -> { authorize_view_by_action!(:read_group_repository_analytics) }
before_action only: [:show] do
push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_visit_total, @group, default_enabled: :yaml)
push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_project_click_total, @group, default_enabled: :yaml)
end
track_redis_hll_event :show, name: 'i_testing_group_code_coverage_visit_total'
def show
track_event(**pageview_tracker_params)
......
---
title: Track group coverage usage ping event in Vue template
merge_request: 55687
author:
type: changed
......@@ -33,19 +33,6 @@ RSpec.describe Groups::Analytics::RepositoryAnalyticsController do
)
end
context 'unique users tracking' do
before do
allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event)
end
it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { group_id: group } }
let(:target_id) { 'i_testing_group_code_coverage_visit_total' }
let(:expected_type) { instance_of(String) }
end
end
context 'when license is missing' do
before do
stub_licensed_features(feature_name => false)
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import DownloadTestCoverage from 'ee/analytics/repository_analytics/components/download_test_coverage.vue';
import GroupRepositoryAnalytics from 'ee/analytics/repository_analytics/components/group_repository_analytics.vue';
import GroupRepositoryAnalytics, {
VISIT_EVENT_FEATURE_FLAG,
VISIT_EVENT_NAME,
} from 'ee/analytics/repository_analytics/components/group_repository_analytics.vue';
import Api from '~/api';
const localVue = createLocalVue();
jest.mock('~/api.js');
describe('Group repository analytics app', () => {
let wrapper;
const createComponent = () => {
wrapper = shallowMount(GroupRepositoryAnalytics, { localVue });
const createComponent = (glFeatures = {}) => {
wrapper = shallowMount(GroupRepositoryAnalytics, { localVue, provide: { glFeatures } });
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('test coverage', () => {
beforeEach(() => {
createComponent();
});
it('renders test coverage header', () => {
const header = wrapper.find('[data-testid="test-coverage-header"]');
......@@ -31,4 +35,26 @@ describe('Group repository analytics app', () => {
expect(wrapper.find(DownloadTestCoverage).exists()).toBe(true);
});
});
describe('usage ping events', () => {
describe('with the feature flag enabled', () => {
beforeEach(() => {
createComponent({ [VISIT_EVENT_FEATURE_FLAG]: true });
});
it('tracks a visit event on mount', () => {
expect(Api.trackRedisHllUserEvent).toHaveBeenCalledWith(VISIT_EVENT_NAME);
});
});
describe('with the feature flag disabled', () => {
beforeEach(() => {
createComponent({ [VISIT_EVENT_FEATURE_FLAG]: false });
});
it('does not track a visit event on mount', () => {
expect(Api.trackRedisHllUserEvent).not.toHaveBeenCalled();
});
});
});
});
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