track_events_spec.js 4.58 KB
Newer Older
1
(function(define) {
2 3 4 5 6 7
    'use strict';
    define([
        'jquery',
        'js/dashboard/track_events'
    ],
    function($) {
8
        describe('edx.dashboard.trackEvents', function() {
9 10 11 12 13 14
            beforeEach(function() {
                // Stub the analytics event tracker
                window.analytics = jasmine.createSpyObj('analytics', ['track', 'page', 'trackLink']);
                loadFixtures('js/fixtures/dashboard/dashboard.html');
            });

15
            it('sends an analytics event when the user clicks course title link', function() {
16 17 18 19
                var $courseTitle = $('.course-title > a');
                window.edx.dashboard.trackCourseTitleClicked(
                    $courseTitle,
                    window.edx.dashboard.generateTrackProperties);
20
                // Verify that analytics events fire when the 'course title link' is clicked.
21
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
22
                    $courseTitle,
23
                    'edx.bi.dashboard.course_title.clicked',
24 25 26 27
                     window.edx.dashboard.generateTrackProperties
                );
            });

28
            it('sends an analytics event when the user clicks course image link', function() {
29 30 31 32
                var $courseImage = $('.cover');
                window.edx.dashboard.trackCourseImageLinkClicked(
                    $courseImage,
                    window.edx.dashboard.generateTrackProperties);
33
                // Verify that analytics events fire when the 'course image link' is clicked.
34
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
35
                    $courseImage,
36
                    'edx.bi.dashboard.course_image.clicked',
37 38 39 40 41
                    window.edx.dashboard.generateTrackProperties
                );
            });


42
            it('sends an analytics event when the user clicks enter course link', function() {
43 44 45 46
                var $enterCourse = $('.enter-course');
                window.edx.dashboard.trackEnterCourseLinkClicked(
                    $enterCourse,
                    window.edx.dashboard.generateTrackProperties);
47
                // Verify that analytics events fire when the 'enter course link' is clicked.
48
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
49
                    $enterCourse,
50
                    'edx.bi.dashboard.enter_course.clicked',
51 52 53 54
                    window.edx.dashboard.generateTrackProperties
                );
            });

55
            it('sends an analytics event when the user clicks enter course link', function() {
56 57 58 59
                var $dropDown = $('.wrapper-action-more');
                window.edx.dashboard.trackCourseOptionDropdownClicked(
                    $dropDown,
                    window.edx.dashboard.generateTrackProperties);
60 61
                // Verify that analytics events fire when the options dropdown is engaged.
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
62
                    $dropDown,
63
                    'edx.bi.dashboard.course_options_dropdown.clicked',
64 65 66 67
                    window.edx.dashboard.generateTrackProperties
                );
            });

68
            it('sends an analytics event when the user clicks the learned about verified track link', function() {
69 70 71 72
                var $learnVerified = $('.verified-info');
                window.edx.dashboard.trackLearnVerifiedLinkClicked(
                    $learnVerified,
                    window.edx.dashboard.generateTrackProperties);
73
                // Verify that analytics events fire when the 'Learned about verified track' link is clicked.
74
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
75
                    $learnVerified,
76
                    'edx.bi.dashboard.verified_info_link.clicked',
77 78 79 80
                    window.edx.dashboard.generateTrackProperties
                );
            });

81
            it('sends an analytics event when the user clicks find courses button', function() {
82 83 84 85 86 87
                var $findCourse = $('.btn-find-courses'),
                    property = {
                        category: 'dashboard',
                        label: null
                    };
                window.edx.dashboard.trackFindCourseBtnClicked($findCourse, property);
88
                // Verify that analytics events fire when the 'user clicks find the course' button.
89
                expect(window.analytics.trackLink).toHaveBeenCalledWith(
90
                    $findCourse,
91
                    'edx.bi.dashboard.find_courses_button.clicked',
92
                    property
93 94 95 96 97
                );
            });
        });
    });
}).call(this, window.define);