Skip to content

Commit

Permalink
feat(mon-pix): add metricks on shared participation detail
Browse files Browse the repository at this point in the history
  • Loading branch information
machestla committed Nov 15, 2024
1 parent 6d6ef0a commit 512b4d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@route="campaigns.entry-point"
@model={{@model.campaignCode}}
@variant="secondary"
{{on "click" this.trackAccess}}
>
{{t "pages.campaign-participation-overview.card.see-more"}}
</PixButtonLink>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';

export default class Ended extends Component {
@service metrics;

get hasStages() {
return this.args.model.totalStagesCount > 0;
}
Expand All @@ -12,4 +15,14 @@ export default class Ended extends Component {
get total() {
return this.args.model.totalStagesCount - 1;
}

@action
trackAccess() {
this.metrics.add({
event: 'custom-event',
'pix-event-category': 'Campaign participation',
'pix-event-action': `Voir le détail d'une participation partagée`,
'pix-event-name': `Voir le détail d'une participation partagée`,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Service from '@ember/service';
import { setupTest } from 'ember-qunit';
import createGlimmerComponent from 'mon-pix/tests/helpers/create-glimmer-component';
import { module, test } from 'qunit';
import sinon from 'sinon';

module('Unit | Component | Campaign-participation-overview | card | ended', function (hooks) {
setupTest(hooks);

let component;
const intl = Service.create({ t: sinon.spy() });
const campaignParticipationOverview = {
isShared: true,
createdAt: '2020-12-10T15:16:20.109Z',
sharedAt: '2020-12-18T15:16:20.109Z',
status: 'SHARED',
campaignTitle: 'My campaign',
organizationName: 'My organization',
};

module('#trackAccess', function () {
test('should push event on click', function (assert) {
// given
const metrics = this.owner.lookup('service:metrics');
metrics.add = sinon.stub();
component = createGlimmerComponent('campaign-participation-overview/card/ended', {
campaignParticipationOverview,
});
component.intl = intl;

const currentRouteName = 'current.route.name';
component.router = { currentRouteName };

// when
component.trackAccess();

// then
sinon.assert.calledWithExactly(metrics.add, {
event: 'custom-event',
'pix-event-category': 'Campaign participation',
'pix-event-action': `Voir le détail d'une participation partagée`,
'pix-event-name': `Voir le détail d'une participation partagée`,
});
assert.ok(true);
});
});
});

0 comments on commit 512b4d9

Please sign in to comment.