From ee344980f8a1e5b409ad5afe8258372afed3848d Mon Sep 17 00:00:00 2001 From: Brian Jacobel Date: Wed, 29 Mar 2017 15:42:58 -0400 Subject: [PATCH] Add events to course outline, and add JS tests --- .../tests/lms/test_lms_courseware.py | 1 + .../js/course_outline_factory.js | 13 ++++++++++- .../js/spec/course_outline_factory_spec.js | 22 ++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/common/test/acceptance/tests/lms/test_lms_courseware.py b/common/test/acceptance/tests/lms/test_lms_courseware.py index e5b2e4b52b..1ff38c818f 100644 --- a/common/test/acceptance/tests/lms/test_lms_courseware.py +++ b/common/test/acceptance/tests/lms/test_lms_courseware.py @@ -592,6 +592,7 @@ class CoursewareMultipleVerticalsTest(CoursewareMultipleVerticalsTestBase): selected_events ) + # TODO: Delete as part of TNL-6546 / LEARNER-71 def test_link_clicked_events(self): """ Given that I am a user in the courseware diff --git a/openedx/features/course_experience/static/course_experience/js/course_outline_factory.js b/openedx/features/course_experience/static/course_experience/js/course_outline_factory.js index 3f2d3643c5..f2bbcb11ee 100644 --- a/openedx/features/course_experience/static/course_experience/js/course_outline_factory.js +++ b/openedx/features/course_experience/static/course_experience/js/course_outline_factory.js @@ -3,9 +3,10 @@ define([ 'jquery', + 'logger', 'edx-ui-toolkit/js/utils/constants' ], - function($, constants) { + function($, Logger, constants) { return function(root) { // In the future this factory could instantiate a Backbone view or React component that handles events $(root).keydown(function(event) { @@ -23,6 +24,16 @@ break; } }); + + $('a:not([href^="#"])').click(function(event) { + Logger.log( + 'edx.ui.lms.link_clicked', + { + current_url: window.location.href, + target_url: event.currentTarget.href + } + ); + }); }; } ); diff --git a/openedx/features/course_experience/static/course_experience/js/spec/course_outline_factory_spec.js b/openedx/features/course_experience/static/course_experience/js/spec/course_outline_factory_spec.js index ccea16b8f2..649de3ccd3 100644 --- a/openedx/features/course_experience/static/course_experience/js/spec/course_outline_factory_spec.js +++ b/openedx/features/course_experience/static/course_experience/js/spec/course_outline_factory_spec.js @@ -1,9 +1,10 @@ define([ 'jquery', + 'logger', 'edx-ui-toolkit/js/utils/constants', 'course_experience/js/course_outline_factory' ], - function($, constants, CourseOutlineFactory) { + function($, Logger, constants, CourseOutlineFactory) { 'use strict'; describe('Course outline factory', function() { @@ -81,6 +82,25 @@ define([ }); }); }); + + describe('eventing', function() { + beforeEach(function() { + loadFixtures('course_experience/fixtures/course-outline-fragment.html'); + CourseOutlineFactory('.block-tree'); + spyOn(Logger, 'log'); + }); + + it('sends an event when an outline section is clicked', function() { + $('a.focusable:contains("Homework - Labs and Demos")').click(); + + expect(Logger.log).toHaveBeenCalledWith('edx.ui.lms.link_clicked', { + target_url: window.location.origin + + '/courses/course-v1:edX+DemoX+Demo_Course/jump_to/block-v1:edX+DemoX+Demo_Course+type' + + '@sequential+block@graded_simulations', + current_url: window.location.toString() + }); + }); + }); }); } );