Commit fd224672 by Harry Rein Committed by GitHub

Merge pull request #15637 from edx/HarryRein/LEARNER-1652-cleanup

Updating jasmine tests for course tools.
parents b523ac3f 7efd5f38
...@@ -14,6 +14,13 @@ class CourseBookmarksTool(CourseTool): ...@@ -14,6 +14,13 @@ class CourseBookmarksTool(CourseTool):
The course bookmarks tool. The course bookmarks tool.
""" """
@classmethod @classmethod
def analytics_id(cls):
"""
Returns an id to uniquely identify this tool in analytics events.
"""
return 'edx.bookmarks'
@classmethod
def is_enabled(cls, request, course_key): def is_enabled(cls, request, course_key):
""" """
The bookmarks tool is only enabled for enrolled users or staff. The bookmarks tool is only enabled for enrolled users or staff.
......
...@@ -16,6 +16,14 @@ class CourseTool(object): ...@@ -16,6 +16,14 @@ class CourseTool(object):
not a requirement, and plugin implementations outside of this repo should not a requirement, and plugin implementations outside of this repo should
simply follow the contract defined below. simply follow the contract defined below.
""" """
@classmethod
def analytics_id(cls):
"""
Returns an id to uniquely identify this tool in analytics events.
For example, 'edx.bookmarks'. New tools may warrant doc updates for the new id.
"""
raise NotImplementedError("Must specify an id to enable course tool eventing.")
@classmethod @classmethod
def is_enabled(cls, request, course_key): def is_enabled(cls, request, course_key):
......
...@@ -20,6 +20,13 @@ class CourseUpdatesTool(CourseTool): ...@@ -20,6 +20,13 @@ class CourseUpdatesTool(CourseTool):
The course updates tool. The course updates tool.
""" """
@classmethod @classmethod
def analytics_id(cls):
"""
Returns an analytics id for this tool, used for eventing.
"""
return 'edx.updates'
@classmethod
def title(cls): def title(cls):
""" """
Returns the title of this tool. Returns the title of this tool.
...@@ -58,6 +65,13 @@ class CourseReviewsTool(CourseTool): ...@@ -58,6 +65,13 @@ class CourseReviewsTool(CourseTool):
The course reviews tool. The course reviews tool.
""" """
@classmethod @classmethod
def analytics_id(cls):
"""
Returns an id to uniquely identify this tool in analytics events.
"""
return 'edx.reviews'
@classmethod
def title(cls): def title(cls):
""" """
Returns the title of this tool. Returns the title of this tool.
......
...@@ -67,19 +67,19 @@ ...@@ -67,19 +67,19 @@
<h3 class="hd-6">Course Tools</h3> <h3 class="hd-6">Course Tools</h3>
<ul class="list-unstyled"> <ul class="list-unstyled">
<li> <li>
<a class="course-tool-link" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/bookmarks/"> <a class="course-tool-link" data-analytics-id="edx.bookmarks" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/bookmarks/">
<span class="icon fa fa-bookmark" aria-hidden="true"></span> <span class="icon fa fa-bookmark" aria-hidden="true"></span>
Bookmarks Bookmarks
</a> </a>
</li> </li>
<li> <li>
<a class="course-tool-link" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/course/reviews"> <a class="course-tool-link" data-analytics-id="edx.reviews" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/course/reviews">
<span class="icon fa fa-star" aria-hidden="true"></span> <span class="icon fa fa-star" aria-hidden="true"></span>
Reviews Reviews
</a> </a>
</li> </li>
<li> <li>
<a class="course-tool-link" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/course/updates"> <a class="course-tool-link" data-analytics-id="edx.updates" href="/courses/course-v1:W3Cx+HTML5.0x+1T2017/course/updates">
<span class="icon fa fa-newspaper-o" aria-hidden="true"></span> <span class="icon fa fa-newspaper-o" aria-hidden="true"></span>
Updates Updates
</a> </a>
......
...@@ -4,13 +4,12 @@ export class CourseHome { // eslint-disable-line import/prefer-default-export ...@@ -4,13 +4,12 @@ export class CourseHome { // eslint-disable-line import/prefer-default-export
constructor(options) { constructor(options) {
// Logging for course tool click events // Logging for course tool click events
const $courseToolLink = $(options.courseToolLink); const $courseToolLink = $(options.courseToolLink);
$courseToolLink.on('click', () => { $courseToolLink.on('click', (event) => {
const courseToolName = document.querySelector('.course-tool-link').text.trim().toLowerCase(); const courseToolName = event.srcElement.dataset['analytics-id']; // eslint-disable-line dot-notation
Logger.log( Logger.log(
'edx.course.tool.accessed', 'edx.course.tool.accessed',
{ {
tool_name: courseToolName, tool_name: courseToolName,
page: 'course_home',
}, },
); );
}); });
......
...@@ -15,15 +15,19 @@ describe('Course Home factory', () => { ...@@ -15,15 +15,19 @@ describe('Course Home factory', () => {
}); });
it('sends an event when an course tool is clicked', () => { it('sends an event when an course tool is clicked', () => {
document.querySelector('.course-tool-link').dispatchEvent(new Event('click')); const courseToolNames = document.querySelectorAll('.course-tool-link');
const courseToolName = document.querySelector('.course-tool-link').text.trim().toLowerCase(); for (let i = 0; i < courseToolNames.length; i += 1) {
expect(Logger.log).toHaveBeenCalledWith( const courseToolName = courseToolNames[i].dataset['analytics-id']; // eslint-disable-line dot-notation
'edx.course.tool.accessed', const event = new CustomEvent('click');
{ event.srcElement = { dataset: { 'analytics-id': courseToolName } };
tool_name: courseToolName, courseToolNames[i].dispatchEvent(event);
page: 'course_home', expect(Logger.log).toHaveBeenCalledWith(
}, 'edx.course.tool.accessed',
); {
tool_name: courseToolName,
},
);
}
}); });
}); });
}); });
...@@ -78,7 +78,7 @@ from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, SHOW_REV ...@@ -78,7 +78,7 @@ from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG, SHOW_REV
<ul class="list-unstyled"> <ul class="list-unstyled">
% for course_tool in course_tools: % for course_tool in course_tools:
<li> <li>
<a class="course-tool-link" href="${course_tool.url(course_key)}"> <a class="course-tool-link" data-analytics-id="${course_tool.analytics_id()}" href="${course_tool.url(course_key)}">
<span class="icon ${course_tool.icon_classes()}" aria-hidden="true"></span> <span class="icon ${course_tool.icon_classes()}" aria-hidden="true"></span>
${course_tool.title()} ${course_tool.title()}
</a> </a>
......
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