<commit_before>/**
 * File: constructor.js
 *
 * Purpose: Jasmine tests for LTI module (front-end part).
 *
 *
 * The front-end part of the LTI module is really simple. If an action
 * is set for the hidden LTI form, then it is submited, and the results are
 * redirected to an iframe.
 *
 * We will test that the form is only submited when the action is set (i.e.
 * not empty).
 *
 * Other aspects of LTI module will be covered by Python unit tests and
 * acceptance tests.
 *
 */

/*
 * "Hence that general is skilful in attack whose opponent does not know what
 * to defend; and he is skilful in defense whose opponent does not know what
 * to attack."
 *
 * ~ <NAME>
 */

(function () {
    describe('LTI', function () {
        var element, errorMessage, frame,
            editSettings = false;

        // This function will be executed before each of the it() specs
        // in this suite.
        beforeEach(function () {
            spyOn($.fn, 'submit').andCallThrough();

            loadFixtures('lti.html');

            element = $('#lti_id');
            errorMessage = element.find('.error_message');
            form = element.find('.ltiLaunchForm');
            frame = element.find('.ltiLaunchFrame');

            // First part of the tests will be running without the settings
            // filled in. Once we reach the describe() spec
            //
            //     "After the settings were filled in"
            //
            // the variable `editSettings` will be changed to `true`.
            if (editSettings) {
                form.attr('action', 'http://www.example.com/');
            }

            LTI(element);
        });

        describe('constructor', function () {
            describe('before settings were filled in', function () {
                it(
                    'when URL setting is filled form is not submited',
                    function () {

                    expect($.fn.submit).not.toHaveBeenCalled();
                });
            });

            describe('After the settings were filled in', function () {
                it('editSettings is disabled', function () {
                    expect(editSettings).toBe(false);

                    // Let us toggle edit settings switch. Next beforeEach()
                    // will populate element's attributes with settings.
                    editSettings = true;
                });

                it('when URL setting is filled form is submited', function () {
                    expect($.fn.submit).toHaveBeenCalled();
                });
            });
        });
    });
}());<commit_msg>Addressing comments on PR 804.<commit_after>/**
 * File: constructor.js
 *
 * Purpose: Jasmine tests for LTI module (front-end part).
 *
 *
 * The front-end part of the LTI module is really simple. If an action
 * is set for the hidden LTI form, then it is submited, and the results are
 * redirected to an iframe.
 *
 * We will test that the form is only submited when the action is set (i.e.
 * not empty).
 *
 * Other aspects of LTI module will be covered by Python unit tests and
 * acceptance tests.
 *
 */

/*
 * "Hence that general is skilful in attack whose opponent does not know what
 * to defend; and he is skilful in defense whose opponent does not know what
 * to attack."
 *
 * ~ <NAME>
 */

(function () {
    describe('LTI', function () {
        describe('constructor', function () {
            describe('before settings were filled in', function () {
                var element, errorMessage, frame;

                // This function will be executed before each of the it() specs
                // in this suite.
                beforeEach(function () {
                    loadFixtures('lti.html');

                    element = $('#lti_id');
                    errorMessage = element.find('.error_message');
                    form = element.find('.ltiLaunchForm');
                    frame = element.find('.ltiLaunchFrame');

                    spyOnEvent(form, 'submit');

                    LTI(element);
                });

                it(
                    'when URL setting is filled form is not submited',
                    function () {

                    expect('submit').not.toHaveBeenTriggeredOn(form);
                });
            });

            describe('After the settings were filled in', function () {
                var element, errorMessage, frame;

                // This function will be executed before each of the it() specs
                // in this suite.
                beforeEach(function () {
                    loadFixtures('lti.html');

                    element = $('#lti_id');
                    errorMessage = element.find('.error_message');
                    form = element.find('.ltiLaunchForm');
                    frame = element.find('.ltiLaunchFrame');

                    spyOnEvent(form, 'submit');

                    // The user "fills in" the necessary settings, and the
                    // form will get an action URL.
                    form.attr('action', 'http://www.example.com/');

                    LTI(element);
                });

                it('when URL setting is filled form is submited', function () {
                    expect('submit').toHaveBeenTriggeredOn(form);
                });
            });
        });
    });
}());
{'fraction_non_alphanumeric': 0.10766084046113797, 'fraction_numerical': 0.0005578281889178133, 'mean_word_length': 1.584814992791927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '525984', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1272, 'n_words': 464}