updates_visibility_spec.js 2.38 KB
Newer Older
1 2
define(['jquery', 'logger', 'js/courseware/toggle_element_visibility', 'moment'],
    function ($, Logger, ToggleElementVisibility, moment) {
3 4 5 6 7 8 9 10 11
        'use strict';

        describe('show/hide with mouse click', function () {

            beforeEach(function() {
                loadFixtures('js/fixtures/courseware/course_updates.html');
                /*jshint newcap: false */
                ToggleElementVisibility();
                /*jshint newcap: true */
12
                spyOn(Logger, 'log');
13 14 15
            });

            it('ensures update will hide on hide button click', function () {
16 17 18
                var $shownUpdate = $('.toggle-visibility-element:not(.hidden)').first(),
                    $updateButton = $shownUpdate.siblings('.toggle-visibility-button');
                $updateButton.trigger('click');
19
                expect($shownUpdate).toHaveClass('hidden');
20
                expect($updateButton.text()).toEqual('Show');
21 22 23
            });

            it('ensures update will show on show button click', function () {
24 25 26
                var $hiddenUpdate = $('.toggle-visibility-element.hidden').first(),
                    $updateButton = $hiddenUpdate.siblings('.toggle-visibility-button');
                $updateButton.trigger('click');
27
                expect($hiddenUpdate).not.toHaveClass('hidden');
28
                expect($updateButton.text()).toEqual('Hide');
29 30 31 32 33 34 35 36 37 38 39
            });

            it('ensures old updates will show on button click', function () {
                // on page load old updates will be hidden
                var $oldUpdates = $('.toggle-visibility-element.old-updates');
                expect($oldUpdates).toHaveClass('hidden');

                // on click on show earlier update button old updates will be shown
                $('.toggle-visibility-button.show-older-updates').trigger('click');
                expect($oldUpdates).not.toHaveClass('hidden');
            });
40 41 42 43 44 45

            it('sends a tracking event on hide and show', function () {
                var $update = $('.toggle-visibility-element:not(.hidden)').first();
                $update.siblings('.toggle-visibility-button').trigger('click');
                expect(Logger.log).toHaveBeenCalledWith('edx.course.home.course_update.toggled', {
                    action: 'hide',
46
                    publish_date: moment('December 1, 2015', 'MMM DD, YYYY').format()
47 48
                });
            });
49 50
        });
    });