Commit 1be3a7aa authored by Miranda Fluharty's avatar Miranda Fluharty Committed by Vitaly Slobodin

Use data-testid to find expand button in spec

Find expand button with data-testid="report-section-expand-button"
instead of using the class .qa-expand-report-button
parent a4b0fa69
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { once } from 'lodash';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import { componentNames } from './issue_body'; import { componentNames } from './issue_body';
...@@ -8,6 +9,7 @@ import SummaryRow from './summary_row.vue'; ...@@ -8,6 +9,7 @@ import SummaryRow from './summary_row.vue';
import IssuesList from './issues_list.vue'; import IssuesList from './issues_list.vue';
import Modal from './modal.vue'; import Modal from './modal.vue';
import createStore from '../store'; import createStore from '../store';
import Tracking from '~/tracking';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { summaryTextBuilder, reportTextBuilder, statusIcon } from '../store/utils'; import { summaryTextBuilder, reportTextBuilder, statusIcon } from '../store/utils';
...@@ -21,7 +23,7 @@ export default { ...@@ -21,7 +23,7 @@ export default {
Modal, Modal,
GlButton, GlButton,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin(), Tracking.mixin()],
props: { props: {
endpoint: { endpoint: {
type: String, type: String,
...@@ -58,6 +60,11 @@ export default { ...@@ -58,6 +60,11 @@ export default {
showViewFullReport() { showViewFullReport() {
return this.pipelinePath.length; return this.pipelinePath.length;
}, },
handleToggleEvent() {
return once(() => {
this.track(this.$options.expandEvent);
});
},
}, },
created() { created() {
this.setEndpoint(this.endpoint); this.setEndpoint(this.endpoint);
...@@ -102,6 +109,7 @@ export default { ...@@ -102,6 +109,7 @@ export default {
return report.resolved_failures.concat(report.resolved_errors); return report.resolved_failures.concat(report.resolved_errors);
}, },
}, },
expandEvent: 'expand_test_report_widget',
}; };
</script> </script>
<template> <template>
...@@ -111,7 +119,9 @@ export default { ...@@ -111,7 +119,9 @@ export default {
:loading-text="groupedSummaryText" :loading-text="groupedSummaryText"
:error-text="groupedSummaryText" :error-text="groupedSummaryText"
:has-issues="reports.length > 0" :has-issues="reports.length > 0"
:should-emit-toggle-event="true"
class="mr-widget-section grouped-security-reports mr-report" class="mr-widget-section grouped-security-reports mr-report"
@toggleEvent="handleToggleEvent"
> >
<template v-if="showViewFullReport" #actionButtons> <template v-if="showViewFullReport" #actionButtons>
<gl-button <gl-button
......
...@@ -189,6 +189,7 @@ export default { ...@@ -189,6 +189,7 @@ export default {
<button <button
v-if="isCollapsible" v-if="isCollapsible"
type="button" type="button"
data-testid="report-section-expand-button"
class="js-collapse-btn btn float-right btn-sm align-self-center qa-expand-report-button" class="js-collapse-btn btn float-right btn-sm align-self-center qa-expand-report-button"
@click="toggleCollapsed" @click="toggleCollapsed"
> >
......
import { mount, createLocalVue } from '@vue/test-utils'; import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { mockTracking } from 'helpers/tracking_helper';
import GroupedTestReportsApp from '~/reports/components/grouped_test_reports_app.vue'; import GroupedTestReportsApp from '~/reports/components/grouped_test_reports_app.vue';
import { getStoreConfig } from '~/reports/store'; import { getStoreConfig } from '~/reports/store';
...@@ -39,6 +40,7 @@ describe('Grouped test reports app', () => { ...@@ -39,6 +40,7 @@ describe('Grouped test reports app', () => {
}; };
const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]'); const findHeader = () => wrapper.find('[data-testid="report-section-code-text"]');
const findExpandButton = () => wrapper.find('[data-testid="report-section-expand-button"]');
const findFullTestReportLink = () => wrapper.find('[data-testid="group-test-reports-full-link"]'); const findFullTestReportLink = () => wrapper.find('[data-testid="group-test-reports-full-link"]');
const findSummaryDescription = () => wrapper.find('[data-testid="test-summary-row-description"]'); const findSummaryDescription = () => wrapper.find('[data-testid="test-summary-row-description"]');
const findIssueDescription = () => wrapper.find('[data-testid="test-issue-body-description"]'); const findIssueDescription = () => wrapper.find('[data-testid="test-issue-body-description"]');
...@@ -96,6 +98,35 @@ describe('Grouped test reports app', () => { ...@@ -96,6 +98,35 @@ describe('Grouped test reports app', () => {
}); });
}); });
describe('`Expand` button', () => {
let trackingSpy;
beforeEach(() => {
setReports(newFailedTestReports);
mountComponent();
document.body.dataset.page = 'projects:merge_requests:show';
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
});
it('tracks an event on click', () => {
findExpandButton().trigger('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'expand_test_report_widget', {});
});
it('only tracks the first expansion', () => {
expect(trackingSpy).not.toHaveBeenCalled();
const button = findExpandButton();
button.trigger('click');
button.trigger('click');
button.trigger('click');
expect(trackingSpy).toHaveBeenCalledTimes(1);
});
});
describe('with new failed result', () => { describe('with new failed result', () => {
beforeEach(() => { beforeEach(() => {
setReports(newFailedTestReports); setReports(newFailedTestReports);
......
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