Commit 86dbb1fe by Valera Rozuvan Committed by Alexander Kryklia

Addressing comments on PR 804.

Rewriting expect() calls to use Jasmine jQuery event spies. Making individual
it() tests independent.
parent c63170ae
...@@ -26,55 +26,57 @@ ...@@ -26,55 +26,57 @@
(function () { (function () {
describe('LTI', function () { describe('LTI', function () {
var element, errorMessage, frame, describe('constructor', function () {
editSettings = false; 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 () {
spyOn($.fn, 'submit').andCallThrough();
loadFixtures('lti.html'); // This function will be executed before each of the it() specs
// in this suite.
beforeEach(function () {
loadFixtures('lti.html');
element = $('#lti_id'); element = $('#lti_id');
errorMessage = element.find('.error_message'); errorMessage = element.find('.error_message');
form = element.find('.ltiLaunchForm'); form = element.find('.ltiLaunchForm');
frame = element.find('.ltiLaunchFrame'); frame = element.find('.ltiLaunchFrame');
// First part of the tests will be running without the settings spyOnEvent(form, 'submit');
// 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); LTI(element);
}); });
describe('constructor', function () {
describe('before settings were filled in', function () {
it( it(
'when URL setting is filled form is not submited', 'when URL setting is filled form is not submited',
function () { function () {
expect($.fn.submit).not.toHaveBeenCalled(); expect('submit').not.toHaveBeenTriggeredOn(form);
}); });
}); });
describe('After the settings were filled in', function () { describe('After the settings were filled in', function () {
it('editSettings is disabled', function () { var element, errorMessage, frame;
expect(editSettings).toBe(false);
// 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/');
// Let us toggle edit settings switch. Next beforeEach() LTI(element);
// will populate element's attributes with settings.
editSettings = true;
}); });
it('when URL setting is filled form is submited', function () { it('when URL setting is filled form is submited', function () {
expect($.fn.submit).toHaveBeenCalled(); expect('submit').toHaveBeenTriggeredOn(form);
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment