Commit b6755388 authored by Mark Florian's avatar Mark Florian

Merge branch...

Merge branch '333944-add-snowplow-tracking-to-audit-events-date-range-segmented-control' into 'master'

Add Snowplow tracking to audit events date range segmented control

See merge request gitlab-org/gitlab!66443
parents 40e9b568 5266f5b0
<script> <script>
import { GlButtonGroup, GlButton } from '@gitlab/ui'; import { GlButtonGroup, GlButton } from '@gitlab/ui';
import { datesMatch, dateAtFirstDayOfMonth, getDateInPast } from '~/lib/utils/datetime_utility'; import { datesMatch, dateAtFirstDayOfMonth, getDateInPast } from '~/lib/utils/datetime_utility';
import { convertToSnakeCase } from '~/lib/utils/text_utility';
import { n__, s__ } from '~/locale'; import { n__, s__ } from '~/locale';
import { CURRENT_DATE } from '../constants'; import { CURRENT_DATE } from '../constants';
...@@ -41,6 +42,9 @@ export default { ...@@ -41,6 +42,9 @@ export default {
const { dateRange } = this; const { dateRange } = this;
return datesMatch(startDate, dateRange.startDate) && datesMatch(endDate, dateRange.endDate); return datesMatch(startDate, dateRange.startDate) && datesMatch(endDate, dateRange.endDate);
}, },
trackingLabel({ text }) {
return `date_range_button_${convertToSnakeCase(text)}`;
},
}, },
DATE_RANGE_OPTIONS, DATE_RANGE_OPTIONS,
}; };
...@@ -52,6 +56,8 @@ export default { ...@@ -52,6 +56,8 @@ export default {
v-for="(dateRangeOption, idx) in $options.DATE_RANGE_OPTIONS" v-for="(dateRangeOption, idx) in $options.DATE_RANGE_OPTIONS"
:key="idx" :key="idx"
:selected="isCurrentDateRange(dateRangeOption)" :selected="isCurrentDateRange(dateRangeOption)"
data-track-action="click_date_range_button"
:data-track-label="trackingLabel(dateRangeOption)"
@click="onDateRangeClicked(dateRangeOption)" @click="onDateRangeClicked(dateRangeOption)"
>{{ dateRangeOption.text }}</gl-button >{{ dateRangeOption.text }}</gl-button
> >
......
---
description: Clicks a date range button in audit events
category: admin:audit_logs:index
action: click_date_range_button
label_description: Notes which date range was selected
property_description:
value_description:
extra_properties:
identifiers:
product_section: dev
product_stage: manage
product_group: compliance
product_category: audit_events
milestone: "14.2"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66443
distributions:
- ee
tiers:
- premium
import { GlButtonGroup, GlButton } from '@gitlab/ui'; import { GlButtonGroup, GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import DateRangeButtons from 'ee/audit_events/components/date_range_buttons.vue'; import DateRangeButtons from 'ee/audit_events/components/date_range_buttons.vue';
import { CURRENT_DATE } from 'ee/audit_events/constants'; import { CURRENT_DATE } from 'ee/audit_events/constants';
import { getDateInPast } from '~/lib/utils/datetime_utility'; import { getDateInPast } from '~/lib/utils/datetime_utility';
...@@ -14,9 +13,24 @@ describe('DateRangeButtons component', () => { ...@@ -14,9 +13,24 @@ describe('DateRangeButtons component', () => {
}); });
}; };
const findButtonGroup = () => wrapper.findComponent(GlButtonGroup);
const findButtons = (f) => findButtonGroup().findAllComponents(GlButton).filter(f);
const findSelectedButtons = () => findButtons((b) => b.props('selected'));
const findUnSelectedButtons = () => findButtons((b) => !b.props('selected'));
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; });
it('sets the tracking data on the button', () => {
createComponent({
dateRange: { startDate: getDateInPast(CURRENT_DATE, 7), endDate: CURRENT_DATE },
});
expect(findSelectedButtons().at(0).attributes()).toMatchObject({
'data-track-action': 'click_date_range_button',
'data-track-label': 'date_range_button_last_7_days',
});
}); });
it('shows the selected the option that matches the provided dateRange property', () => { it('shows the selected the option that matches the provided dateRange property', () => {
...@@ -24,7 +38,7 @@ describe('DateRangeButtons component', () => { ...@@ -24,7 +38,7 @@ describe('DateRangeButtons component', () => {
dateRange: { startDate: getDateInPast(CURRENT_DATE, 7), endDate: CURRENT_DATE }, dateRange: { startDate: getDateInPast(CURRENT_DATE, 7), endDate: CURRENT_DATE },
}); });
expect(wrapper.find(GlButtonGroup).find('[selected="true"]').text()).toBe('Last 7 days'); expect(findSelectedButtons().at(0).text()).toBe('Last 7 days');
}); });
it('shows no date range as selected when the dateRange property does not match any option', () => { it('shows no date range as selected when the dateRange property does not match any option', () => {
...@@ -35,19 +49,19 @@ describe('DateRangeButtons component', () => { ...@@ -35,19 +49,19 @@ describe('DateRangeButtons component', () => {
}, },
}); });
expect(wrapper.find(GlButtonGroup).find('[selected="true"]').exists()).toBe(false); expect(findSelectedButtons()).toHaveLength(0);
}); });
it('emits an "input" event with the dateRange when a new date range is selected', async () => { it('emits an "input" event with the dateRange when a new date range is selected', async () => {
createComponent({ createComponent({
dateRange: { startDate: getDateInPast(CURRENT_DATE, 1), endDate: CURRENT_DATE }, dateRange: { startDate: getDateInPast(CURRENT_DATE, 7), endDate: CURRENT_DATE },
}); });
wrapper.find(GlButtonGroup).find(GlButton).vm.$emit('click'); findUnSelectedButtons().at(0).vm.$emit('click');
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
expect(wrapper.emitted().input[0]).toEqual([ expect(wrapper.emitted().input[0]).toEqual([
{ {
startDate: getDateInPast(CURRENT_DATE, 7), startDate: getDateInPast(CURRENT_DATE, 14),
endDate: CURRENT_DATE, endDate: CURRENT_DATE,
}, },
]); ]);
......
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