Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
thostetler committed Feb 22, 2024
1 parent b65d6ab commit fc57080
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
10 changes: 4 additions & 6 deletions src/js/components/analytics.js
Expand Up @@ -87,10 +87,8 @@ define(['underscore', 'jquery'], function (_, $) {


// if the action is send and the event is event, then we want to send the event to the dataLayer
if (
action === 'send' &&
event === 'event' &&
Array.isArray(window.dataLayer)
if (Array.isArray(window.dataLayer) &&
action === 'send' && event === 'event'
) {
// some events are 'interaction' or 'error', so add that to the event name
window.dataLayer.push({
Expand All @@ -101,14 +99,14 @@ define(['underscore', 'jquery'], function (_, $) {
value2: args[1],
value3: args[2],
});
} else if (action === 'send') {
} else if (Array.isArray(window.dataLayer) && action === 'send') {
window.dataLayer.push({
event,
value1: type,
value2: description,
value3: args[0],
});
} else if (action === 'set') {
} else if (Array.isArray(window.dataLayer) && action === 'set') {
window.dataLayer.push({
event: 'config',
value1: event,
Expand Down
20 changes: 0 additions & 20 deletions test/mocha/js/widgets/resources_widget.spec.js
Expand Up @@ -282,26 +282,6 @@ define([
expect(icon.length).to.eql(1);
done();
});
it('Clicking on a link fires an analytics event', function (done) {
const w = new Widget();
const $el = $(w.view.render().$el).appendTo('#test-area');
this.sb.stub(w, 'emitAnalytics');
w.activate(this.pubsub.beehive);
const mockResponse = ({
toJSON: _.constant({ response: { docs: [{ foo: 'bar' }] }})
});
w.parseResourcesData = this.sb.stub();
w.parseResourcesData.returns({
fullTextSources: [{ url: 'test', name: '0', description: 'bar' }],
dataProducts: []
});
this.pubsub.publish(this.pubsub.DELIVERING_RESPONSE, mockResponse);
const link = $('a', $el);
link.on('click', function (e) { e.preventDefault(); });
link[0].click();
expect(w.emitAnalytics.calledWith('0')).to.eql(true);
done();
});
});
});
});

0 comments on commit fc57080

Please sign in to comment.