cms.runtime.v1_spec.js 2.88 KB
Newer Older
1
define(["js/spec_helpers/edit_helpers", "js/views/modals/base_modal", "xblock/cms.runtime.v1"],
2
    function (EditHelpers, BaseModal) {
3 4 5 6 7

        describe("Studio Runtime v1", function() {
            var runtime;

            beforeEach(function () {
8
                EditHelpers.installEditTemplates();
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
                runtime = new window.StudioRuntime.v1();
            });

            it('allows events to be listened to', function() {
                var canceled = false;
                runtime.listenTo('cancel', function() {
                    canceled = true;
                });
                expect(canceled).toBeFalsy();
                runtime.notify('cancel', {});
                expect(canceled).toBeTruthy();
            });

            it('shows save notifications', function() {
                var title = "Mock saving...",
24
                    notificationSpy = EditHelpers.createNotificationSpy();
25 26 27 28
                runtime.notify('save', {
                    state: 'start',
                    message: title
                });
29
                EditHelpers.verifyNotificationShowing(notificationSpy, title);
30 31 32
                runtime.notify('save', {
                    state: 'end'
                });
33
                EditHelpers.verifyNotificationHidden(notificationSpy);
34 35 36 37 38
            });

            it('shows error messages', function() {
                var title = "Mock Error",
                    message = "This is a mock error.",
39
                    notificationSpy = EditHelpers.createNotificationSpy("Error");
40 41 42 43
                runtime.notify('error', {
                    title: title,
                    message: message
                });
44
                EditHelpers.verifyNotificationShowing(notificationSpy, title);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
            });

            describe("Modal Dialogs", function() {
                var MockModal, modal, showMockModal;

                MockModal = BaseModal.extend({
                    getContentHtml: function() {
                        return readFixtures('mock/mock-modal.underscore');
                    }
                });

                showMockModal = function() {
                    modal = new MockModal({
                        title: "Mock Modal"
                    });
                    modal.show();
                };

                beforeEach(function () {
64
                    EditHelpers.installEditTemplates();
65 66 67
                });

                afterEach(function() {
68
                    EditHelpers.hideModalIfShowing(modal);
69 70 71 72 73
                });

                it('cancels a modal dialog', function () {
                    showMockModal();
                    runtime.notify('modal-shown', modal);
74
                    expect(EditHelpers.isShowingModal(modal)).toBeTruthy();
75
                    runtime.notify('cancel');
76
                    expect(EditHelpers.isShowingModal(modal)).toBeFalsy();
77 78 79 80
                });
            });
        });
    });