2012-11-22 17:21:50 +00:00
|
|
|
(function(context,$) {
|
|
|
|
|
|
|
|
|
|
describe("CreateSession", function() {
|
|
|
|
|
|
|
|
|
|
var css;
|
|
|
|
|
var ajaxSpy;
|
|
|
|
|
|
|
|
|
|
var appFake = {
|
|
|
|
|
clientId: '12345',
|
|
|
|
|
notify: function(){},
|
|
|
|
|
ajaxError: function() { console.debug("ajaxError"); }
|
|
|
|
|
};
|
|
|
|
|
|
2012-11-23 17:20:13 +00:00
|
|
|
var selectors = {
|
2012-11-23 19:09:01 +00:00
|
|
|
form: '#create-session-form',
|
2013-02-05 07:58:19 +00:00
|
|
|
genres: '#genre-list',
|
2013-01-14 01:43:48 +00:00
|
|
|
description: '#description'
|
2012-11-23 17:20:13 +00:00
|
|
|
};
|
|
|
|
|
|
2012-11-23 19:09:01 +00:00
|
|
|
function makeValid() {
|
2013-02-05 07:58:19 +00:00
|
|
|
//var genre = '<div class="list-item-text"><input type="checkbox" checked="checked" value="1">1</div>';
|
|
|
|
|
$(selectors.genres).val('african');
|
|
|
|
|
//$(selectors.genres, $(selectors.form)).append(genre);
|
2012-11-23 19:09:01 +00:00
|
|
|
$(selectors.description).val('XYZ');
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 17:21:50 +00:00
|
|
|
beforeEach(function() {
|
2012-11-23 17:20:13 +00:00
|
|
|
// Use the actual screen markup
|
|
|
|
|
jasmine.getFixtures().fixturesPath = '/app/views/clients';
|
|
|
|
|
loadFixtures('_createSession.html.erb');
|
2012-11-22 17:21:50 +00:00
|
|
|
spyOn(appFake, 'notify');
|
|
|
|
|
css = new context.JK.CreateSessionScreen(appFake);
|
2013-01-30 00:36:54 +00:00
|
|
|
css.getGenreSelector().initialize('Choose up to 3 genres', 3, $(selectors.form));
|
2012-11-22 17:21:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("resetForm", function() {
|
|
|
|
|
it("description should be empty", function() {
|
2012-11-23 17:20:13 +00:00
|
|
|
$(selectors.description).val('XYZ');
|
2012-11-22 17:21:50 +00:00
|
|
|
css.resetForm();
|
2012-11-23 17:20:13 +00:00
|
|
|
expect($(selectors.description).val()).toEqual('');
|
2012-11-22 17:21:50 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe("loadGenres", function() {
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
spyOn($, "ajax").andCallFake(function(opts) {
|
|
|
|
|
opts.success(TestResponses.loadGenres);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it("should populate genres select", function() {
|
|
|
|
|
css.loadGenres();
|
2013-02-26 03:54:09 +00:00
|
|
|
$genres = $(selectors.genres);
|
|
|
|
|
alert($genres.html());
|
|
|
|
|
expect($genres.length).toEqual(2);
|
2012-11-22 17:21:50 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2012-11-23 19:09:01 +00:00
|
|
|
describe("submitForm", function() {
|
|
|
|
|
|
2012-12-07 00:28:48 +00:00
|
|
|
var fakeEvt;
|
2012-11-23 19:09:01 +00:00
|
|
|
var passedData = {};
|
|
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
makeValid();
|
2012-12-07 00:28:48 +00:00
|
|
|
fakeEvt = {
|
|
|
|
|
preventDefault: $.noop,
|
|
|
|
|
currentTarget: $(selectors.form)
|
|
|
|
|
};
|
2012-11-23 19:09:01 +00:00
|
|
|
spyOn($, "ajax").andCallFake(function(opts) {
|
|
|
|
|
opts.success(TestResponses.sessionPost);
|
|
|
|
|
});
|
2012-12-07 00:28:48 +00:00
|
|
|
css.submitForm(fakeEvt);
|
2012-11-23 19:09:01 +00:00
|
|
|
passedData = JSON.parse($.ajax.mostRecentCall.args[0].data);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass client_id", function() {
|
|
|
|
|
expect(passedData.client_id).toEqual("12345");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass genres as non-empty list", function() {
|
|
|
|
|
expect("genres" in passedData).toBeTruthy();
|
|
|
|
|
var isArray = $.isArray(passedData.genres);
|
|
|
|
|
expect(isArray).toBeTruthy();
|
|
|
|
|
expect(passedData.genres.length).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass tracks as non-empty list", function() {
|
|
|
|
|
expect("tracks" in passedData).toBeTruthy();
|
|
|
|
|
var isArray = $.isArray(passedData.tracks);
|
|
|
|
|
expect(isArray).toBeTruthy();
|
|
|
|
|
expect(passedData.tracks.length).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass musician_access as boolean", function() {
|
|
|
|
|
expect("musician_access" in passedData).toBeTruthy();
|
|
|
|
|
expect(typeof(passedData.musician_access)).toEqual("boolean");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass approval_required as boolean", function() {
|
|
|
|
|
expect("approval_required" in passedData).toBeTruthy();
|
|
|
|
|
expect(typeof(passedData.approval_required)).toEqual("boolean");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass fan_access as boolean", function() {
|
|
|
|
|
expect("fan_access" in passedData).toBeTruthy();
|
|
|
|
|
expect(typeof(passedData.fan_access)).toEqual("boolean");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass fan_chat as boolean", function() {
|
|
|
|
|
expect("fan_chat" in passedData).toBeTruthy();
|
|
|
|
|
expect(typeof(passedData.fan_chat)).toEqual("boolean");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2012-11-22 17:21:50 +00:00
|
|
|
describe("validateForm", function() {
|
2012-11-23 17:20:13 +00:00
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
|
makeValid();
|
|
|
|
|
});
|
|
|
|
|
|
2012-11-22 17:21:50 +00:00
|
|
|
it("valid form", function() {
|
|
|
|
|
var errs = css.validateForm();
|
|
|
|
|
expect(errs).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2013-02-05 07:58:19 +00:00
|
|
|
// it("should fail with > 3 genres", function() {
|
|
|
|
|
// var htm = '<div class="list-item-text"><input type="checkbox" checked="checked" value="2">2</div>' +
|
|
|
|
|
// '<div class="list-item-text"><input type="checkbox" checked="checked" value="3">3</div>' +
|
2013-02-26 03:54:09 +00:00
|
|
|
// '<div class="list-item-text"><input type="checkbox" checked="checked" value="4">4</div>' +
|
2013-02-05 07:58:19 +00:00
|
|
|
// '<div class="list-item-text"><input type="checkbox" checked="checked" value="5">5</div>';
|
|
|
|
|
// $(selectors.genres, $(selectors.form)).append(htm);
|
|
|
|
|
// var errs = css.validateForm();
|
|
|
|
|
// // Verify that we have an error.
|
|
|
|
|
// expect(errs).toBeTruthy();
|
|
|
|
|
// // Verify that the error is a two-part list
|
|
|
|
|
// expect(errs[0].length).toEqual(2);
|
|
|
|
|
// // Verify that the first part is a selector for the problem.
|
|
|
|
|
// expect(errs[0][0]).toEqual('#genre-list-items');
|
|
|
|
|
// });
|
2012-11-22 17:21:50 +00:00
|
|
|
|
|
|
|
|
it("should fail with 0 genres", function() {
|
2013-01-30 00:36:54 +00:00
|
|
|
$(selectors.genres, $(selectors.form)).html('');
|
2012-11-22 17:21:50 +00:00
|
|
|
var errs = css.validateForm();
|
|
|
|
|
// Verify that we have an error.
|
|
|
|
|
expect(errs).toBeTruthy();
|
|
|
|
|
// Verify that the first part is a selector for the problem.
|
2013-02-05 07:58:19 +00:00
|
|
|
expect(errs[0][0]).toEqual('#genre-list');
|
2012-11-22 17:21:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should fail with empty description", function() {
|
2012-11-23 17:20:13 +00:00
|
|
|
$(selectors.description).val('');
|
2012-11-22 17:21:50 +00:00
|
|
|
var errs = css.validateForm();
|
|
|
|
|
// Verify that we have an error.
|
|
|
|
|
expect(errs).toBeTruthy();
|
|
|
|
|
// Verify that the first part is a selector for the problem.
|
2013-01-14 01:43:48 +00:00
|
|
|
expect(errs[0][0]).toEqual('#description');
|
2012-11-22 17:21:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2013-02-26 03:54:09 +00:00
|
|
|
}) // Intentionally not running tests as they're failing. (window, jQuery);
|