'use strict';
describe('AppControllerTest', function() {
var MockCall;
var MockRoomSelection;
var roomSelectionBackup_;
var callBackup_;
var loadingParams_;
var mainElem;
MockRoomSelection = function() {};
MockRoomSelection.RecentlyUsedList = function() {
return {
pushRecentRoom: function() {}
};
};
MockRoomSelection.matchRandomRoomPattern = function() {
return false;
};
MockCall = function() {};
MockCall.prototype.start = function() {};
MockCall.prototype.hangup = function() {};
beforeEach(function(done) {
roomSelectionBackup_ = RoomSelection;
RoomSelection = MockRoomSelection;
callBackup_ = Call;
Call = MockCall;
loadingParams_ = {
mediaConstraints: {
audio: true, video: true
}
};
mainElem = document.createElement('div');
document.body.insertBefore(mainElem, document.body.firstChild);
for (var key in UI_CONSTANTS) {
var elem;
if (key.toLowerCase().includes('button')) {
elem = document.createElement('button');
} else {
elem = document.createElement('div');
}
elem.id = UI_CONSTANTS[key].substr(1);
mainElem.appendChild(elem);
}
loadingParams_.roomId = 'myRoom';
new AppController(loadingParams_);
$(UI_CONSTANTS.confirmJoinRoomSpan)
.addEventListener('DOMSubtreeModified', function() {
done();
});
});
afterEach(function() {
RoomSelection = roomSelectionBackup_;
Call = callBackup_;
});
it('Confirm to join', function() {
expect($(UI_CONSTANTS.confirmJoinRoomSpan).textContent)
.toEqual(' "' + loadingParams_.roomId + '"');
expect($(UI_CONSTANTS.confirmJoinDiv).classList.contains('hidden'))
.toBeFalsy();
});
it('Hide UI after clicking the join button', function(done) {
setTimeout(function() {
$(UI_CONSTANTS.confirmJoinButton).addEventListener('click', function() {
expect($(UI_CONSTANTS.confirmJoinDiv).classList.contains('hidden'))
.toBeTruthy();
done();
});
$(UI_CONSTANTS.confirmJoinButton).click();
}, 2000);
});
});