describe('Test feed event message renderer', function () {
var scope, compile, $httpBackend, relatedObject, event, metadataModel, $q, approvalModel, approvalService, i18nService;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(function () {
inject(function ($compile, $rootScope, $injector, _metadataModel_, _$q_, _approvalModel_, _approvalService_, _i18nService_) {
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond('');
$httpBackend.whenGET('/smartit/rest/serverstates').respond('');
compile = $compile;
scope = $rootScope.$new();
metadataModel = _metadataModel_;
$q = _$q_;
approvalModel = _approvalModel_;
approvalService = _approvalService_;
i18nService = _i18nService_;
});
});
beforeEach(function () {
event = {
"messageId": "48930",
"eventType": "assignment-change",
"labelTemplate": "Assigned To: {0} by {1}",
"entities": [
{
"entityId": "Allen",
"type": "person",
"displayValue": "Francie Stafford",
"entityLink": "#/person/Francie"
},
{
"entityId": "",
"type": "text",
"displayValue": "System Generated",
"entityLink": "#/text/"
}
],
"recipients": [],
"createDate": "2018-08-16T11:53:14.000Z"
};
relatedObject = {
"type": "change",
"title": "Change Request",
"id": "IDGAA5V0HGR55AP39QTSP2MUW8NEX0"
};
scope.relatedObject = new RelatedObjectVO().build(relatedObject);
scope.event = new EventVO().build(event);
scope.isUpdateFeed = true;
});
function getCompiledElement() {
var element = angular.element(' '),
compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
var directiveElem = getCompiledElement(),
divElem = directiveElem[0];
expect(divElem).toBeDefined();
});
it('should display assignment change event to UI in case of assignment-change event type', function () {
var directiveElem = getCompiledElement();
expect(directiveElem[0].innerText.trim()).toBe('Assigned To: Francie Stafford by System Generated');
});
it('should display email work note to UI in case of email-worknote event type', function () {
var directiveElem,
isolatedScope;
event = {
"messageId": "49001",
"eventType": "email-worknote",
"labelTemplate": "{0} sent an email to {1} recipients",
"entities": [
{
"entityId": "Allen",
"type": "person",
"displayValue": "Allen Allbrook",
"entityLink": "#/person/Allen"
},
{
"entityId": "",
"type": "integer",
"displayValue": "2",
"entityLink": "javascript:void(0)"
}
],
"recipients": [
{
"entityId": "Bob",
"type": "person",
"displayValue": "Bob Baxter",
"entityLink": "#/person/Bob"
},
{
"entityId": "Allen",
"type": "person",
"displayValue": "Allen Allbrook",
"entityLink": "#/person/Allen"
}
],
"createDate": "2018-08-16T12:34:44.976Z"
};
scope.event = new EventVO().build(event);
directiveElem = getCompiledElement();
isolatedScope = directiveElem.isolateScope();
expect(directiveElem[0].innerText.trim()).toBe('Allen Allbrook sent an email to 2 recipients');
expect(isolatedScope.tooltipHtml).toBe('
email.tooltip.headerText:
');
});
it('should log message if event does not have any data', function () {
var directiveElem;
scope.event = null;
spyOn(console, 'log');
directiveElem = getCompiledElement();
expect(console.log).toHaveBeenCalledWith('No information about system event.');
expect(directiveElem[0].innerText.trim()).toBe('');
});
it('should fetch metadata response if entity type is status or priority', function () {
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
var deferred = $q.defer();
deferred.resolve(true);
return deferred.promise;
});
event = {
"messageId": "48928",
"eventType": "status-change",
"labelTemplate": "Status Marked: {0} by {1}",
"entities": [
{
"entityId": "",
"type": "status",
"displayValue": "Closed",
"entityLink": "#/status/"
},
{
"entityId": "Allen",
"type": "person",
"displayValue": "Allen Allbrook",
"entityLink": "#/person/Allen"
}
],
"recipients": [],
"createDate": "2018-08-17T22:11:25.000Z"
};
scope.event = new EventVO().build(event);
getCompiledElement();
expect(metadataModel.getMetadataByType).toHaveBeenCalledWith('change');
});
it('should specific styles to colorize "SLA Alert:" in case of sla-change event', function () {
var directiveElem;
event = {
"messageId": "48919",
"eventType": "sla-change",
"labelTemplate": "SLA Alert: Due in {0} for {1}",
"entities": [
{
"entityId": "",
"type": "time",
"displayValue": 1534853828,
"entityLink": "#/time/"
},
{
"entityId": "GGP000000000021",
"type": "group",
"displayValue": "US Support 1",
"entityLink": "#/group/GGP000000000021"
}
],
"recipients": [],
"createDate": new Date("2018-08-20T06:17:37.000Z")
};
scope.event = new EventVO().build(event);
directiveElem = getCompiledElement();
expect(directiveElem[0].innerText.trim()).toBe('SLA Alert: Due in a day for US Support 1');
expect(directiveElem.find('.system-event-message__sla-change').length).toBe(1);
});
it('should add a link of show approvers in case of approval accept event and should show dialog on click of it', function () {
var directiveElem,
isolateScope,
data = {
"approvalList": {
"closed": [
{
"type": "person",
"status": {
"value": "Approved",
"name": "approved"
},
"approver": {
"type": "person",
"fullName": "Mary Mann"
}
}
],
"open": [],
"rejected": []
}
};
event = {
"messageId": "65002",
"eventType": "approval-accept-event",
"labelTemplate": "{0} approved the change request with rationale: {1}",
"entities": [
{
"entityId": "Mary",
"type": "person",
"displayValue": "Mary Mann",
"entityLink": "#/person/Mary"
},
{
"entityId": "",
"type": "text",
"displayValue": "",
"entityLink": "#/text/"
}
],
"recipients": [],
"createDate": "2018-08-20T09:53:09.000Z"
};
scope.event = new EventVO().build(event);
scope.isUpdateFeed = false;
spyOn(approvalModel, 'getListOfApprovers').and.callFake(function () {
var deferred = $q.defer();
deferred.resolve(data);
return deferred.promise;
});
spyOn(approvalService, 'showApproversDialog');
spyOn(i18nService, 'getLocalizedString').and.callFake(function (input) {
if(input == 'approval.approversList.labels.showList') {
return 'Show approvers';
} else {
return input;
}
});
directiveElem = getCompiledElement();
isolateScope = directiveElem.isolateScope();
expect(directiveElem[0].innerText.trim()).toBe('Mary Mann approved the change request with rationale: Show approvers');
isolateScope.showApprovers(true);
isolateScope.$apply();
expect(approvalModel.getListOfApprovers).toHaveBeenCalledWith(isolateScope.relatedObject);
expect(approvalService.showApproversDialog).toHaveBeenCalledWith(data.approvalList, isolateScope.parentContext, true);
});
it('should add a link of show approvers in case of approval accept event', function () {
var directiveElem;
event = {
"messageId": "65003",
"eventType": "approval-accept-event",
"labelTemplate": "{0} approved the change request with rationale: {1}",
"entities": [
{
"entityId": "Mary",
"type": "person",
"displayValue": "Mary Mann",
"entityLink": "#/person/Mary"
},
{
"entityId": "",
"type": "text",
"displayValue": "",
"entityLink": "#/text/"
}
],
"recipients": [],
"createDate": "2018-08-20T09:53:09.000Z"
};
scope.event = new EventVO().build(event);
scope.isUpdateFeed = false;
spyOn(i18nService, 'getLocalizedString').and.callFake(function (input) {
if(input == 'approval.approversList.labels.showList') {
return 'Show approvers';
} else {
return input;
}
});
directiveElem = getCompiledElement();
expect(directiveElem[0].innerText.trim()).toBe('Mary Mann approved the change request with rationale: Show approvers');
});
it('should display asset in update feed', function () {
var directiveElem;
event = {
"messageId": "10183",
"eventType": "related-change",
"labelTemplate": "Related to {0} by {1}",
"entities": [
{
"entityId": "REHAA5V0GQBORANAMVY0WE3E1KVMX7",
"type": "asset",
"displayValue": "Sales Tracking",
"entityLink": "#/asset/REHAA5V0GQBORANAMVY0WE3E1KVMX7/BMC_BUSINESSSERVICE"
},
{
"entityId": "Allen",
"type": "person",
"displayValue": "Allen Allbrook",
"entityLink": "#/person/Allen"
}
],
"recipients": [],
"createDate": "2018-08-20T08:17:24.000Z"
};
scope.event = new EventVO().build(event);
directiveElem = getCompiledElement();
expect(directiveElem[0].innerText.trim()).toBe('Related to Sales Tracking by Allen Allbrook');
});
});