112 lines
3.5 KiB
JavaScript
112 lines
3.5 KiB
JavaScript
describe('Chat message directive', function () {
|
|
var scope,
|
|
$compile,
|
|
$httpBackend,
|
|
$state,
|
|
chatModel;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
module(function ($provide) {
|
|
$provide.value('chatModel', {
|
|
currentUser: {
|
|
jid: 'test@domain'
|
|
}
|
|
});
|
|
$provide.value('$state', {
|
|
go: jasmine.createSpy('$state.go').and.returnValue(true)
|
|
});
|
|
})
|
|
});
|
|
|
|
beforeEach(inject(function (_$rootScope_, _$compile_, _$state_, _$httpBackend_, _chatModel_) {
|
|
$compile = _$compile_;
|
|
$state = _$state_;
|
|
$httpBackend = _$httpBackend_;
|
|
chatModel = _chatModel_;
|
|
|
|
$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();
|
|
chatModel.cachedProfiles = {};
|
|
}));
|
|
|
|
function getMessageDetails(overrideProps) {
|
|
return _.assign({
|
|
author: {
|
|
firstName: 'Test',
|
|
lastName: 'Person',
|
|
fullName: 'Test Person',
|
|
loginId: 'test',
|
|
jid: 'test@domain',
|
|
thumbnail: 'thumbnail1',
|
|
nick: 'Test_Person',
|
|
},
|
|
message: 'Hello there. I am test message!',
|
|
type: 'chat',
|
|
eventType: '',
|
|
parent: {}
|
|
}, overrideProps);
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var regularMessage = getMessageDetails();
|
|
var elem = angular.element('<chat-message context="message"></chat-message>');
|
|
var compiledElement = $compile(elem)(scope);
|
|
|
|
scope.message = new ChatMessageVO().build(regularMessage);
|
|
scope.$digest();
|
|
$httpBackend.flush();
|
|
|
|
var elemScope = elem.isolateScope();
|
|
|
|
expect(compiledElement).toBeDefined();
|
|
expect(compiledElement.find('.chat-message__body').length).toEqual(1);
|
|
expect(elemScope.selfMessage).toEqual(true);
|
|
|
|
});
|
|
|
|
it('should redirect to system message related item', function () {
|
|
var connectTicketMessage = getMessageDetails({
|
|
eventType: 'connected',
|
|
type: 'system',
|
|
parent: {id: 1, displayId: '0001', summary: 'Test Ticket', type: EntityVO.TYPE_WORKORDER}
|
|
});
|
|
|
|
var elem = angular.element('<chat-message context="message"></chat-message>');
|
|
var compiledElement = $compile(elem)(scope);
|
|
|
|
scope.message = new ChatMessageVO().build(connectTicketMessage);
|
|
scope.$digest();
|
|
|
|
var userProfileLink = compiledElement.find('.chat-history__link:contains(\'Test Person\')');
|
|
var ticketProfileLink = compiledElement.find('.chat-history__link:contains(\'0001: Test Ticket\')');
|
|
|
|
expect(userProfileLink.length).toEqual(1);
|
|
expect(ticketProfileLink.length).toEqual(1);
|
|
|
|
userProfileLink.trigger('click');
|
|
|
|
expect($state.go).toHaveBeenCalledWith('person', {id: 'test'});
|
|
|
|
ticketProfileLink.trigger('click');
|
|
|
|
expect($state.go).toHaveBeenCalledWith(EntityVO.TYPE_WORKORDER, {id: 1});
|
|
|
|
scope.message.parent = {reconciliationId: 1, classId: 'Printer', ticketType: EntityVO.TYPE_ASSET, name: 'Wireless Printer'};
|
|
scope.$digest();
|
|
|
|
var assetProfileLink = compiledElement.find('.chat-history__link:contains(\'Wireless Printer\')');
|
|
|
|
expect(assetProfileLink.length).toEqual(1);
|
|
|
|
assetProfileLink.trigger('click');
|
|
|
|
expect($state.go).toHaveBeenCalledWith('asset', {assetId: 1, assetClassId: 'Printer'});
|
|
});
|
|
});
|