136 lines
4.3 KiB
JavaScript
136 lines
4.3 KiB
JavaScript
describe('Test ChatWindowVO', function () {
|
|
var participant1 = {
|
|
firstName: 'Test',
|
|
lastName: 'Person',
|
|
fullName: 'Test Person',
|
|
loginId: 'test',
|
|
jid: 'test@domain',
|
|
thumbnail: 'thumbnail1',
|
|
nick: 'Test_Person',
|
|
affiliation: 'owner',
|
|
},
|
|
participant2 = {
|
|
firstName: 'Test2',
|
|
lastName: 'Person2',
|
|
fullName: 'Test2 Person2',
|
|
loginId: 'test2',
|
|
jid: 'test2@domain',
|
|
thumbnail: 'thumbnail2',
|
|
nick: 'Test2_Person2'
|
|
},
|
|
participant3 = {
|
|
firstName: 'Test3',
|
|
lastName: 'Person3',
|
|
fullName: 'Test3 Person3',
|
|
loginId: 'test3',
|
|
jid: 'test3@domain',
|
|
thumbnail: 'thumbnail3',
|
|
nick: 'Test3_Person3'
|
|
},
|
|
room = {
|
|
name: 'testRoom@domain',
|
|
roster: {
|
|
Test_Person: participant1,
|
|
Test2_Person2: participant2
|
|
},
|
|
client: {
|
|
_connection: {
|
|
authcid: 'test2' // current user id
|
|
}
|
|
},
|
|
nick: 'Test_Person'
|
|
},
|
|
chatWindow;
|
|
|
|
beforeEach(function () {
|
|
chatWindow = new ChatWindowVO().build({room: angular.copy(room), isOpened: true});
|
|
chatWindow.roster = [participant1, participant2].reduce(function (roster, user) {
|
|
roster[user.loginId] = user;
|
|
return roster;
|
|
}, {});
|
|
});
|
|
|
|
it('should build ChatWindow instance with all properties', function () {
|
|
expect(chatWindow).toBeDefined();
|
|
expect(chatWindow.id).toEqual(room.name);
|
|
expect(chatWindow.isOpened).toEqual(true);
|
|
expect(chatWindow.participants).toEqual(jasmine.objectContaining(room.roster));
|
|
expect(chatWindow.roomOwner).toEqual(jasmine.objectContaining(participant1));
|
|
});
|
|
|
|
it('should generate user thumbnail', function () {
|
|
var thumbnail = chatWindow.getUserThumbnailForChatList();
|
|
var systemMessage = new ChatMessageVO().build({type: 'system', author: participant1, created: new Date('2017-01-01').getTime()});
|
|
var textMessage = new ChatMessageVO().build({type: 'chat', author: participant2, text: 'Hello', created: new Date('2017-01-02').getTime()});
|
|
var connectionMessage = new ChatMessageVO().build({type: 'connection', author: participant1, text: 'System message', created: Date.now()});
|
|
|
|
expect(thumbnail).toEqual(participant1.thumbnail);
|
|
|
|
chatWindow.messages.push(systemMessage, textMessage, connectionMessage);
|
|
thumbnail = chatWindow.getUserThumbnailForChatList();
|
|
|
|
expect(thumbnail).toEqual(participant2.thumbnail);
|
|
});
|
|
|
|
it('should toggle chat window', function () {
|
|
chatWindow.toggleChatWindow();
|
|
|
|
expect(chatWindow.isOpened).toEqual(false);
|
|
|
|
chatWindow.toggleChatWindow();
|
|
|
|
expect(chatWindow.isOpened).toEqual(true);
|
|
});
|
|
|
|
it('should generate conversation summary', function () {
|
|
var summary = chatWindow.generateConversationSummary();
|
|
|
|
expect(summary).toEqual(participant2.firstName);
|
|
|
|
chatWindow.participants[participant3.fullName.replace(' ', '_')] = participant3;
|
|
chatWindow.room.roster[participant3.fullName.replace(' ', '_')] = participant3;
|
|
chatWindow.roster[participant3.userId] = participant3;
|
|
|
|
summary = chatWindow.generateConversationSummary();
|
|
|
|
expect(summary).toEqual('Test2, Test3');
|
|
|
|
chatWindow.parent = {ticketType: EntityVO.TYPE_ASSET, name: 'Printer'};
|
|
summary = chatWindow.generateConversationSummary();
|
|
|
|
expect(summary).toEqual('Test2, Test3 (Printer)');
|
|
|
|
chatWindow.parent = {ticketType: EntityVO.TYPE_INCIDENT, displayId: '00001'};
|
|
summary = chatWindow.generateConversationSummary();
|
|
|
|
expect(summary).toEqual('Test2, Test3 (00001)');
|
|
});
|
|
|
|
it('should get last message text', function () {
|
|
var textMessage1 = new ChatMessageVO().build({type: 'chat', author: participant2, text: 'Hello'});
|
|
var textMessage2 = new ChatMessageVO().build({type: 'chat', author: participant1, text: 'Hi'});
|
|
|
|
chatWindow.messages.push(textMessage1, textMessage2);
|
|
|
|
expect(chatWindow.getLastMessageText()).toEqual(textMessage2.text);
|
|
});
|
|
|
|
it('should generate chat topic', function () {
|
|
expect(chatWindow.generateChatTopic()).toBeUndefined();
|
|
|
|
chatWindow.parent = {ticketType: EntityVO.TYPE_ASSET, name: 'Printer'};
|
|
|
|
expect(chatWindow.generateChatTopic()).toEqual(EntityVO.TYPE_ASSET.toUpperCase() + ': Printer');
|
|
|
|
chatWindow.parent = {ticketType: EntityVO.TYPE_INCIDENT, displayId: '00001', summary: 'Account got blocked'};
|
|
|
|
expect(chatWindow.generateChatTopic()).toEqual('00001: Account got blocked');
|
|
});
|
|
|
|
it('should populate array of participant JIDs', function () {
|
|
var JIDs = chatWindow.getParticipantJIDsArray();
|
|
|
|
expect(JIDs).toEqual(jasmine.arrayContaining(['test', 'test2']));
|
|
});
|
|
|
|
}); |