233 lines
6.7 KiB
JavaScript
233 lines
6.7 KiB
JavaScript
/**
|
|
* Created by ohnatkov on 10-23-2017.
|
|
*/
|
|
describe('Chat window directive', function () {
|
|
var scope,
|
|
compile,
|
|
chatModel,
|
|
$httpBackend,
|
|
systemAlertService,
|
|
participant1 = {
|
|
firstName: 'Test',
|
|
lastName: 'Person',
|
|
fullName: 'Test Person',
|
|
loginId: 'test',
|
|
jid: 'test@server',
|
|
thumbnail: 'thumbnail'
|
|
},
|
|
participant2 = {
|
|
firstName: 'Test2',
|
|
lastName: 'Person2',
|
|
fullName: 'Test2 Person2',
|
|
loginId: 'test2',
|
|
jid: 'test2@server',
|
|
thumbnail: 'thumbnail2'
|
|
},
|
|
room = {
|
|
id: 'room@test',
|
|
nick: '',
|
|
roster: {
|
|
test: participant1,
|
|
test2: participant2
|
|
}
|
|
},
|
|
chatRoom = new ChatWindowVO().build({room: room, isOpened: true});
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
module(function ($provide) {
|
|
$provide.value('chatModel', {
|
|
cachedProfiles: {},
|
|
getUserProfileByJID: function (jids) {
|
|
this.cachedProfiles[Strophe.getNodeFromJid(participant1.jid)] = participant1;
|
|
this.cachedProfiles[Strophe.getNodeFromJid(participant2.jid)] = participant2;
|
|
|
|
return Promise.resolve([participant1, participant2])
|
|
},
|
|
Client: {conn: {authcid: 'currentUser'}},
|
|
leaveConversation: function () {
|
|
|
|
},
|
|
leaveRoomAndDestroyChatWindow: function () {
|
|
|
|
},
|
|
saveChatLogToTicketWorknote: function () {
|
|
|
|
}
|
|
});
|
|
|
|
$provide.provider('systemAlertService', function () {
|
|
var self = {};
|
|
|
|
this.$get = function () {
|
|
return {
|
|
modal: jasmine.createSpy('systemAlertService.modal').and.callFake(function () {
|
|
return {
|
|
result: {
|
|
then: jasmine.createSpy('systemAlertService.modal').and.callFake(function (callback) {
|
|
self.callBack = callback || self.callBack;
|
|
})
|
|
}
|
|
}
|
|
}),
|
|
close: function (data) {
|
|
if (self.callBack && angular.isFunction(self.callBack)) {
|
|
self.callBack(data);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
beforeEach(inject(function ($rootScope, $compile, _$httpBackend_, _chatModel_, _systemAlertService_) {
|
|
$httpBackend = _$httpBackend_;
|
|
chatModel = _chatModel_;
|
|
systemAlertService = _systemAlertService_;
|
|
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(200, readJSON('scripts/app/i18n/resources-locale_en.json'));
|
|
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200, readJSON('mocks/metadata-global.json'));
|
|
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200, [{items: [{id: 'currentUser'}]}]);
|
|
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200, {});
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200, {});
|
|
|
|
scope = $rootScope.$new();
|
|
compile = $compile;
|
|
chatModel.cachedProfiles = {};
|
|
chatRoom = new ChatWindowVO().build({room: room, isOpened: true, isLoading: false});
|
|
}));
|
|
|
|
it('should compile', function () {
|
|
var elem = angular.element('<chat-window chat-room="chatRoom"></chat-window>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.chatRoom = chatRoom;
|
|
scope.isPopupWindow = false;
|
|
|
|
$httpBackend.flush();
|
|
|
|
expect(compiledElement).toBeDefined();
|
|
expect(compiledElement.find('.chat__message-editor').length).toEqual(1);
|
|
});
|
|
|
|
it('should generate chat window header text', function () {
|
|
var elem = angular.element('<chat-window chat-room="chatRoom"></chat-window>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.chatRoom = chatRoom;
|
|
scope.isPopupWindow = false;
|
|
|
|
$httpBackend.flush();
|
|
|
|
var elemScope = compiledElement.isolateScope();
|
|
|
|
spyOn(elemScope.chatRoom, 'generateRosterSummary').and.callThrough();
|
|
|
|
var chatHeaderText = elemScope.generateChatHeaderCaption();
|
|
|
|
expect(chatHeaderText).toEqual('test, test2');
|
|
expect(elemScope.chatRoom.generateRosterSummary).toHaveBeenCalled();
|
|
|
|
|
|
scope.chatRoom.generateRosterSummary = null;
|
|
scope.chatRoom.roster = {
|
|
test: participant1,
|
|
test2: participant2,
|
|
};
|
|
|
|
chatHeaderText = elemScope.generateChatHeaderCaption();
|
|
|
|
expect(chatHeaderText).toEqual('Test Person, Test2 Person2');
|
|
|
|
scope.chatRoom.roster = {};
|
|
chatHeaderText = elemScope.generateChatHeaderCaption();
|
|
|
|
expect(chatHeaderText).toEqual('No participants');
|
|
|
|
});
|
|
|
|
it('should handle invite user action click', function () {
|
|
var elem = angular.element('<chat-window chat-room="chatRoom"></chat-window>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.chatRoom = chatRoom;
|
|
scope.isPopupWindow = false;
|
|
|
|
$httpBackend.flush();
|
|
|
|
var elemScope = compiledElement.isolateScope();
|
|
var inviteButton = elem.find('.chat__controls_item.icon-user_plus');
|
|
|
|
expect(inviteButton.length).toEqual(1);
|
|
|
|
spyOn(elemScope.chatActions, 'showSearchForm').and.callThrough();
|
|
|
|
inviteButton.trigger('click');
|
|
|
|
expect(elemScope.chatActions.showSearchForm).toHaveBeenCalled();
|
|
expect(elem.find('.chat__search-bar').length).toEqual(1);
|
|
expect(elemScope.searchBar.searchParam).toEqual('');
|
|
expect(elemScope.state.searchUserFormActive).toEqual(true);
|
|
expect(elemScope.state.searchTicketProfileActive).toEqual(false);
|
|
|
|
elemScope.chatActions.showSearchForm('invite');
|
|
elemScope.$digest();
|
|
|
|
expect(elem.find('.chat__search-bar').length).toEqual(0);
|
|
expect(elemScope.state.searchUserFormActive).toEqual(false);
|
|
});
|
|
|
|
it('should handle minimize chat action', function () {
|
|
var elem = angular.element('<chat-window chat-room="chatRoom"></chat-window>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.chatRoom = chatRoom;
|
|
scope.isPopupWindow = false;
|
|
|
|
$httpBackend.flush();
|
|
|
|
var elemScope = compiledElement.isolateScope();
|
|
var minimizeButton = elem.find('.chat__controls_item.glyphicon-minus');
|
|
|
|
expect(minimizeButton.length).toEqual(1);
|
|
|
|
spyOn(elemScope.chatActions, 'minimize').and.callThrough();
|
|
|
|
minimizeButton.trigger('click');
|
|
|
|
expect(elemScope.chatActions.minimize).toHaveBeenCalled();
|
|
expect(elemScope.chatRoom.isOpened).toEqual(false);
|
|
|
|
});
|
|
|
|
it('should handle leave chat action', function () {
|
|
var elem = angular.element('<chat-window chat-room="chatRoom"></chat-window>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.chatRoom = chatRoom;
|
|
scope.isPopupWindow = false;
|
|
scope.$digest();
|
|
|
|
$httpBackend.flush();
|
|
|
|
var elemScope = compiledElement.isolateScope();
|
|
var leaveChatButton = elem.find('.chat__controls_item.icon-exit');
|
|
|
|
expect(leaveChatButton.length).toEqual(1);
|
|
|
|
spyOn(elemScope.chatActions, 'leaveChat').and.callThrough();
|
|
spyOn(chatModel, 'leaveRoomAndDestroyChatWindow').and.callThrough();
|
|
|
|
elemScope.chatRoom.room.nick = 'test';
|
|
leaveChatButton.trigger('click');
|
|
|
|
expect(elemScope.chatActions.leaveChat).toHaveBeenCalled();
|
|
expect(systemAlertService.modal).toHaveBeenCalled();
|
|
|
|
systemAlertService.close({leave: true});
|
|
|
|
expect(elemScope.chatRoom.isOpened).toEqual(false);
|
|
expect(chatModel.leaveRoomAndDestroyChatWindow).toHaveBeenCalled();
|
|
});
|
|
}); |