previous_video_upload_spec.js 4.28 KB
Newer Older
1
define(
2
    ['jquery', 'underscore', 'backbone', 'js/views/previous_video_upload', 'common/js/spec_helpers/template_helpers',
Eric Fischer committed
3
        'common/js/spec_helpers/view_helpers'],
4
    function($, _, Backbone, PreviousVideoUploadView, TemplateHelpers, ViewHelpers) {
5 6
        'use strict';
        describe('PreviousVideoUploadView', function() {
7 8
            var render = function(modelData) {
                var defaultData = {
9 10 11 12 13 14 15 16
                        client_video_id: 'foo.mp4',
                        duration: 42,
                        created: '2014-11-25T23:13:05',
                        edx_video_id: 'dummy_id',
                        status: 'uploading'
                    },
                    view = new PreviousVideoUploadView({
                        model: new Backbone.Model($.extend({}, defaultData, modelData)),
17 18
                        videoHandlerUrl: '/videos/course-v1:org.0+course_0+Run_0',
                        videoImageSettings: {}
19
                    });
20 21 22
                return view.render().$el;
            };

23 24 25 26 27
            beforeEach(function() {
                setFixtures('<div id="page-prompt"></div><div id="page-notification"></div>');
                TemplateHelpers.installTemplate('previous-video-upload', false);
            });

28 29
            it('should render video name correctly', function() {
                var testName = 'test name';
30
                var $el = render({client_video_id: testName});
31
                expect($el.find('.name-col').text()).toEqual(testName);
32 33
            });

34 35 36
            it('should render created timestamp correctly', function() {
                var fakeDate = 'fake formatted date';
                spyOn(Date.prototype, 'toLocaleString').and.callFake(
37 38
                    function(locales, options) {
                        expect(locales).toEqual([]);
39 40
                        expect(options.timeZone).toEqual('UTC');
                        expect(options.timeZoneName).toEqual('short');
41 42 43 44
                        return fakeDate;
                    }
                );
                var $el = render({});
45
                expect($el.find('.date-col').text()).toEqual(fakeDate);
46 47
            });

48 49
            it('should render video id correctly', function() {
                var testId = 'test_id';
50
                var $el = render({edx_video_id: testId});
51
                expect($el.find('.video-id-col').text()).toEqual(testId);
52 53
            });

54 55
            it('should render status correctly', function() {
                var testStatus = 'Test Status';
56
                var $el = render({status: testStatus});
57
                expect($el.find('.status-col').text()).toEqual(testStatus);
58
            });
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

            it('should render remove button correctly', function() {
                var $el = render(),
                    removeButton = $el.find('.actions-list .action-remove a.remove-video-button');

                expect(removeButton.data('tooltip')).toEqual('Remove this video');
                expect(removeButton.find('.sr').text()).toEqual('Remove foo.mp4 video');
            });

            it('shows a confirmation popup when the remove button is clicked', function() {
                var $el = render();
                $el.find('a.remove-video-button').click();
                expect($('.prompt.warning .title').text()).toEqual('Are you sure you want to remove this video from the list?');  // eslint-disable-line max-len
                expect(
                    $('.prompt.warning .message').text()
                ).toEqual(
                    'Removing a video from this list does not affect course content. Any content that uses a previously uploaded video ID continues to display in the course.'  // eslint-disable-line max-len
                );
                expect($('.prompt.warning .action-primary').text()).toEqual('Remove');
                expect($('.prompt.warning .action-secondary').text()).toEqual('Cancel');
            });

            it('shows a notification when the remove button is clicked', function() {
                var notificationSpy = ViewHelpers.createNotificationSpy(),
                    $el = render();
                $el.find('a.remove-video-button').click();
                $('.action-primary').click();
                ViewHelpers.verifyNotificationShowing(notificationSpy, /Removing/);
            });
88 89 90
        });
    }
);