144 lines
5.2 KiB
JavaScript
144 lines
5.2 KiB
JavaScript
(function(context,$) {
|
|
|
|
describe("FindSession", function() {
|
|
|
|
var fss;
|
|
|
|
var appFake = {
|
|
clientId: '12345',
|
|
bindScreen: function(){},
|
|
notify: function(){},
|
|
ajaxError: function() { console.debug("ajaxError"); }
|
|
};
|
|
|
|
var jamClientFake = {
|
|
TestLatency: function(client, fnName) {
|
|
var js = fnName + '(' + JSON.stringify({id: client.id, latency: 50}) + ');';
|
|
eval(js);
|
|
}
|
|
};
|
|
|
|
beforeEach(function() {
|
|
fss = null;
|
|
// Use the actual screen markup
|
|
jasmine.getFixtures().fixturesPath = '/app/views/clients';
|
|
loadFixtures('_findSession.html.erb');
|
|
spyOn(appFake, 'notify');
|
|
});
|
|
|
|
var sessionLatencyReal;
|
|
|
|
describe("RealSessionLatency", function() {
|
|
beforeEach(function() {
|
|
sessionLatencyReal = new JK.SessionLatency(jamClientFake);
|
|
spyOn(sessionLatencyReal, 'sessionPings').andCallThrough();
|
|
fss = new context.JK.FindSessionScreen(appFake);
|
|
fss.initialize(sessionLatencyReal);
|
|
$(fss.selectors.TABLE_BODY).empty();
|
|
});
|
|
|
|
describe("loadSessions", function() {
|
|
beforeEach(function() {
|
|
spyOn($, "ajax");
|
|
});
|
|
it("should query ajax for sessions", function() {
|
|
fss.afterShow({});
|
|
expect($.ajax).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("afterShow flow", function() {
|
|
beforeEach(function() {
|
|
spyOn($, "ajax").andCallFake(function(opts) {
|
|
opts.success(TestGetSessionResponses.oneOfEach);
|
|
});
|
|
});
|
|
|
|
it("should output table rows for sessions", function() {
|
|
fss.afterShow({});
|
|
expect($(fss.selectors.TABLE_BODY + ' tr').length).toEqual(5);
|
|
});
|
|
|
|
it("should call sessionPings", function() {
|
|
fss.afterShow({});
|
|
expect(sessionLatencyReal.sessionPings).toHaveBeenCalled();
|
|
});
|
|
|
|
});
|
|
});
|
|
|
|
describe("FakeSessionLatency", function() {
|
|
|
|
beforeEach(function() {
|
|
sessionInfoResponses = {
|
|
"1": {id:"1", sortScore: 3},
|
|
"2": {id:"2", sortScore: 2}
|
|
};
|
|
sessionLatencyFake = {
|
|
sessionInfo: null
|
|
};
|
|
spyOn(sessionLatencyFake, 'sessionInfo').andCallFake(function(id) {
|
|
return sessionInfoResponses[id];
|
|
});
|
|
fss = new context.JK.FindSessionScreen(appFake);
|
|
fss.initialize(sessionLatencyFake);
|
|
$(fss.selectors.TABLE_BODY).empty();
|
|
});
|
|
|
|
describe("renderSession", function() {
|
|
|
|
describe("layout", function() {
|
|
var tbody;
|
|
|
|
beforeEach(function() {
|
|
var session = TestGetSessionResponses.oneOfEach[0];
|
|
fss.setSession(session);
|
|
fss.renderSession(session.id);
|
|
tbody = $(fss.selectors.TABLE_BODY);
|
|
});
|
|
|
|
it("single session should render", function() {
|
|
expect($('tr', tbody).length).toEqual(1);
|
|
});
|
|
|
|
it("Should render genre", function() {
|
|
expect($('tr td', tbody).first().text()).toEqual('classical');
|
|
});
|
|
|
|
it("Should render description", function() {
|
|
expect($('tr td', tbody).first().next().text()).toEqual('Invited');
|
|
});
|
|
|
|
it("Should render musician count", function() {
|
|
expect($('tr td', tbody).first().next().next().text()).toEqual('1');
|
|
});
|
|
|
|
// TODO - test audience
|
|
// TODO - test latency
|
|
// TODO - test Listen
|
|
|
|
it("Should render join link", function() {
|
|
expect($('tr td', tbody).last().text()).toEqual('Join');
|
|
});
|
|
|
|
});
|
|
|
|
it("higher sortScore inserted before lower sortScore", function() {
|
|
var sessionLow = TestGetSessionResponses.oneOfEach[1];
|
|
var sessionHigh = TestGetSessionResponses.oneOfEach[0];
|
|
fss.setSession(sessionLow);
|
|
fss.setSession(sessionHigh);
|
|
fss.renderSession(sessionLow.id);
|
|
fss.renderSession(sessionHigh.id);
|
|
|
|
var tbody = $(fss.selectors.TABLE_BODY);
|
|
expect($('tr', tbody).length).toEqual(2);
|
|
expect($('tr', tbody).first().attr('data-sortScore')).toEqual('3');
|
|
expect($('tr', tbody).first().next().attr('data-sortScore')).toEqual('2');
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
})(window,jQuery); |