SmartIT_Extensions/BMC/smart-it-full/test/app/common/assignee-chooser-directive....

2190 lines
86 KiB
JavaScript

describe('Test assignee chooser directive', function () {
var scope, compile, $httpBackend, $q, groupList, personList, organizationList, companyList, deferred;
beforeEach(module('myitsmApp', 'templates'));
beforeEach(function () {
var userModelMock = {
userFullData: {
loginId: 'Allen',
fullName: 'Allen Allbrook',
availableForAssignment: true
}
};
module('myitsmApp', function ($provide) {
$provide.value('userModel', userModelMock);
});
inject(function ($compile, $rootScope, $injector, _$q_, searchModel, ticketService, objectValueMapperService, i18nService, $timeout, events) {
$q = _$q_;
$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/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
$httpBackend.when('POST', "/smartit/rest/foundation/assignment/items?chunkInfo=%7B%22startIndex%22:0,%22chunkSize%22:80%7D&type=assigneeSupportCompany")
.respond(200, {
status: "success"
});
$httpBackend.when('POST', "/smartit/rest/foundation/assignment/items?type=assigneeSupportCompany")
.respond(200, {
status: "success"
});
deferred = $q.defer();
compile = $compile;
scope = $rootScope.$new();
this.searchModel = searchModel;
this.ticketService = ticketService;
this.objectValueMapperService = objectValueMapperService;
this.i18nService = i18nService;
this.$timeout = $timeout;
this.events = events;
});
});
beforeEach(function () {
companyList = {
objects: [
{
"name": "Calbro Services",
"attributeMap": {}
},
{
"name": "Petramco",
"attributeMap": {}
},
{
"name": "BMC Software",
"attributeMap": {}
},
{
"name": "Remedy",
"attributeMap": {}
}
],
exceedsChunkSize: false
};
groupList = {
supportGroups: [
{
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services"
},
{
"name": "Change Management",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000013",
"companyName": "Calbro Services"
},
{
"name": "Frontoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000010",
"companyName": "Calbro Services"
},
{
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP0000000000011",
"companyName": "Calbro Services"
},
],
exceedsChunkSize: true
};
personList = {
results: [
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"loginId": "Allen",
"id": "Allen",
"supportGroup": "Backoffice Support",
"supportGroupId": "SGP000000000009",
"supportOrganization": "IT Support"
},
{
"type": "person",
"firstName": "Mary",
"lastName": "Mann",
"fullName": "Mary Mann",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"loginId": "Mary",
"id": "Mary",
"supportGroup": "Service Desk",
"supportGroupId": "SGP000000000011",
"supportOrganization": "IT Support"
},
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"loginId": "Bob",
"id": "Bob",
"supportGroup": "Backoffice Support",
"supportGroupId": "SGP000000000009",
"supportOrganization": "IT Support"
},
{
"type": "person",
"firstName": "Francie",
"lastName": "Stafford",
"fullName": "Francie Stafford",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"loginId": "Francie",
"id": "Francie",
"supportGroup": "Service Desk",
"supportGroupId": "SGP000000000011",
"supportOrganization": "IT Support"
}
],
"totalMatches": 4,
"exceedsChunkSize": false
};
organizationList = {
organizations: [
{
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
},
{
"name": "IT Support",
"attributeMap": {
"companyName": "Petramco"
},
"companyName": "Petramco"
},
{
"name": "Unterstützungsorganisation2",
"attributeMap": {
"companyName": "Löwe"
},
"companyName": "Löwe"
}
],
exceedsChunkSize: true
};
spyOn(this.i18nService, 'getLocalizedString').and.callFake(function (input) {
return input === 'assignBlade.company.all'
|| input === 'assignBlade.organization.all'
|| input === 'assignBlade.supportGroup.all' ? 'All': input;
});
});
function spyAssigneeSupportDropdown(self) {
spyOn(self.searchModel, 'getAssigneeSupportOrgByCompany').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(organizationList);
return deferred.promise;
});
spyOn(self.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrg').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(groupList);
return deferred.promise;
});
spyOn(self.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
}
function spyAllInitService(self) {
spyOn(self.searchModel, 'getAssigneeSupportCompanies').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(companyList);
return deferred.promise;
});
spyOn(self.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
if (arguments[0] === 'customerCompany' || arguments[0] === 'locationCompany') {
return 'Calbro Services';
}
return '';
});
spyOn(self.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve({ results: [personList.results[0]], exceedsChunkSize: true });
return deferred.promise;
});
spyAssigneeSupportDropdown(self);
}
function loadTicketData(type) {
var data;
if (type === EntityVO.TYPE_INCIDENT) {
data = {
"type": "incident",
"status": {
"value": "In Progress"
},
"assignee": {
"fullName": "Allen Allbrook",
"loginId": "Allen",
"id": "Allen"
},
"supportGroup": {
"name": "Backoffice Support",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"id": "SGP000000000009"
},
"serviceTargets": [
{
"startTime": 1535115593000,
"endTime": 1535115593000,
"slaType": "createdate"
}
],
"customer": {
"firstName": "Allen",
"lastName": "Allbrook",
"company": {
"name": "Calbro Services"
}
},
"accessMappings": {
"assigneeSelfAssignmentAllowed": true
},
"locationCompany": {
"name": "Calbro Services"
},
"company": {
"name": "Calbro Services"
},
"ticketType": "incident"
}
} else if (type === EntityVO.TYPE_KNOWLEDGE) {
data = {
"ghostEntity": true,
"title": "",
"isDraft": true,
"type": "knowledge",
"status": {
"value": "Work In Progress"
},
"assignee": {
"customFields": {}
},
"author": {
"company": {
"name": "Calbro Services"
}
},
"owner": {
"company": {
"name": "Calbro Services"
}
},
"company": {
"name": "All"
},
"accessMappings": {
"assignee-self-assignmentEditAllowed": true
},
"allCompanies": [
{
"primary": true,
"name": "All",
}
],
"customer": {
"company": {
"name": "Calbro Services"
}
}
}
} else if (type === EntityVO.TYPE_TASK || type === EntityVO.TYPE_CHANGE) {
data = {
"name": "text",
"id": "123",
"type": type === EntityVO.TYPE_CHANGE ? "change" : "task",
"status": {
"value": "Assigned"
},
"customer": {
"company": {
"name": "Calbro Services",
}
},
"supportGroup": {
"name": "Service Desk",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"id": "SGP000000000011"
},
"accessMappings": {
"assigneeSelfAssignmentAllowed": true,
"managerSelfAssignmentAllowed": true,
"coordinatorSelfAssignmentAllowed": true
},
"company": {
"name": "Calbro Services"
}
}
} else if(type === EntityVO.TYPE_KNOWNERROR || type === EntityVO.TYPE_WORKORDER || type === EntityVO.TYPE_RELEASE) {
data = {
"type": type === EntityVO.TYPE_KNOWNERROR ? "knownerror" : (type === EntityVO.TYPE_RELEASE) ? 'release' : 'workorder',
"status": {
"value": "Assigned"
},
"assignee": {
"fullName": "Allen Allbrook",
"loginId": "Allen",
"customFields": {},
"id": "Allen"
},
"supportGroup": {
"name": "Service Desk",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"id": "SGP000000000011"
},
"accessMappings": {
"coordinatorSelfAssignmentAllowed": true,
"assigneeSelfAssignmentAllowed": true,
"managerSelfAssignmentAllowed": true
},
"company": {
"name": "Calbro Services"
},
"coordinatorGroup": {
"name": "Service Desk",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"id": "SGP000000000011"
},
"ticketType": type === EntityVO.TYPE_KNOWNERROR ? "knownerror" : type === EntityVO.TYPE_RELEASE ? 'release' : 'workorder'
}
}
return data;
}
function getCompiledElement(ticket, isDraft, assignee, role) {
scope.ticket = ticket;
scope.assignee = assignee;
role = role ? 'role="' + role + '"' : '';
var element = angular.element('<assignee-chooser ticket="ticket" assignee="assignee" ' +
'assign-to-me="assignticketassignee" is-draft="isDraft" ' + role + '"></assignee-chooser>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile and set showAssignToMe', function () {
var ticket = new KnowledgeArticleVO(),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {}
};
ticket.accessMappings = {
'assignee-self-assignmentEditAllowed': true
};
ticket.allCompanies = null;
ticket.company = {
name: 'Calbro'
};
var directiveElem = getCompiledElement(ticket, false, assignee),
divElem = directiveElem[0],
isolatedScope = directiveElem.isolateScope();
expect(divElem).toBeDefined();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
});
it('should send customer company and location company in calls for companies, support group, organisation for Incident', function () {
var ticket = new IncidentVO(),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'SP123'
}
},
testCompany = { name: 'Calbro' },
testOrganisation = { name: 'HR Support' },
testSupportGroup = { name: 'IT Support' };
ticket.accessMappings = {};
ticket.allCompanies = null;
ticket.company = {
name: 'Calbro'
};
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
if (arguments[0] === 'customerCompany' || arguments[0] === 'locationCompany') {
return 'Calbro';
}
return '';
});
spyOn(this.searchModel, 'getAssigneeSupportCompanies').and.callFake(function () {
let deferred = $q.defer();
expect(arguments[0].customerCompany).toEqual('Calbro');
expect(arguments[0].locationCompany).toEqual('Calbro');
deferred.resolve(companyList);
return deferred.promise;
});
spyOn(this.searchModel, 'getAssigneeSupportOrgByCompany').and.callFake(function () {
let deferred = $q.defer();
expect(arguments[3]).toEqual('Calbro');
expect(arguments[4]).toEqual('Calbro');
deferred.resolve(organizationList);
return deferred.promise;
});
spyOn(this.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrg').and.callFake(function () {
let deferred = $q.defer();
expect(arguments[4]).toEqual('Calbro');
expect(arguments[5]).toEqual('Calbro');
deferred.resolve(groupList);
return deferred.promise;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
expect(arguments[6]).toEqual('Calbro');
expect(arguments[7]).toEqual('Calbro');
deferred.resolve(personList);
return deferred.promise;
});
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
var directiveElem = getCompiledElement(ticket, false, assignee),
divElem = directiveElem[0],
isolatedScope = directiveElem.isolateScope();
expect(divElem).toBeDefined();
isolatedScope.selectCompany(testCompany);
isolatedScope.selectOrganization(testOrganisation);
isolatedScope.selectGroup(testSupportGroup);
isolatedScope.$apply();
});
it('should check Assign to Me checkbox and Logged in user should be searched by name if ticket is Incident', function () {
var ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT)),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'SP123'
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
return input === 'locationCompany' ? 'Calbro Services': input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = true;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.id).toBe('All');
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('Allen Allbrook');
expect(isolatedScope.assigneeLoginId).toBe('Allen');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
});
it('should uncheck Assign to Me checkbox and Logged in user should be cleared from search box if ticket is Incident', function () {
var ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT)),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = false;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.assigneeLoginId).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons.length).toBe(3);
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Bob Baxter');
});
it('should check Assign to Me checkbox and Logged in user should be searched by name if ticket is Knowledge article', function () {
var ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'SP123'
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"exceedsChunkSize": true,
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
return input === 'locationCompany' ? 'Calbro Services': input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = true;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.id).toBe('All');
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('Allen Allbrook');
expect(isolatedScope.assigneeLoginId).toBe('Allen');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
});
it('should uncheck Assign to Me checkbox and Logged in user should be cleared from search box if ticket is Knowledge article', function () {
var ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"exceedsChunkSize": true,
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = false;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.assigneeLoginId).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons.length).toBe(3);
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Bob Baxter');
});
it('should check Assign to Me checkbox and Logged in user should be searched by name if ticket is task article', function () {
var ticket = loadTicketData(EntityVO.TYPE_TASK),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'SP123'
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Allen",
"lastName": "Allbrook",
"fullName": "Allen Allbrook",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
return input === 'locationCompany' ? 'Calbro Services': input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = true;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.id).toBe('All');
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('Allen Allbrook');
expect(isolatedScope.assigneeLoginId).toBe('Allen');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
});
it('should uncheck Assign to Me checkbox and Logged in user should be cleared from search box if ticket is task', function () {
var ticket = loadTicketData(EntityVO.TYPE_TASK),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
},
assignToMeSearchResult = {
"results": [
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"supportGroupId": "SGP000000000009",
},
{
"type": "person",
"firstName": "Bob",
"lastName": "Baxter",
"fullName": "Bob Baxter",
"loginId": "Allen",
"id": "Allen",
"supportGroupId": "SGP000000000010"
}
],
"totalMatches": 2
}, directiveElem, isolatedScope;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(assignToMeSearchResult);
return deferred.promise;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.assignToMe = false;
isolatedScope.selectAssignToMe();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.assigneeLoginId).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.assignee.group.persons.length).toBe(3);
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Bob Baxter');
});
describe('if ticket is Incident, it', function() {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT));
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('should select Support Company item and update the data of other dropdowns when user selects any value from Support Company', function () {
var company = {
"name": "Calbro Services",
"attributeMap": {}
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectCompany(company);
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.name).toBe(company.name);
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Organization item and update the data of Support Group dropdown when user selects any value from Support Organization', function () {
var organization = {
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectOrganization(organization);
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('IT Support');
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Group item when user selects any value from Support Group', function () {
var group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function (input) {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
});
describe('if ticket is Knowledge Article, it', function() {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('should select Support Company item and update the data of other dropdowns when user selects any value from Support Company', function () {
var company = {
"name": "Calbro Services",
"attributeMap": {}
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectCompany(company);
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.name).toBe(company.name);
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Organization item and update the data of Support Group dropdown when user selects any value from Support Organization', function () {
var organization = {
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectOrganization(organization);
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('IT Support');
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Group item when user selects any value from Support Group', function () {
var group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function (input) {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
});
describe('if ticket is Task, it', function() {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = loadTicketData(EntityVO.TYPE_TASK);
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function (input) {
if (input === 'customerCompany') {
input = '';
} else if (input === 'locationCompany') {
input = 'Calbro Services';
}
return input;
});
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('should select Support Company item and update the data of other dropdowns when user selects any value from Support Company', function () {
var company = {
"name": "Calbro Services",
"attributeMap": {}
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectCompany(company);
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.name).toBe(company.name);
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Organization item and update the data of Support Group dropdown when user selects any value from Support Organization', function () {
var organization = {
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
};
spyAssigneeSupportDropdown(this);
isolatedScope.selectOrganization(organization);
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('IT Support');
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Group item when user selects any value from Support Group', function () {
var group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function (input) {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Company item and update the data of other dropdowns when user selects any value from Support Company if location company is null', function () {
var company = {
"name": "Calbro Services",
"attributeMap": {}
};
spyAssigneeSupportDropdown(this);
isolatedScope.ticket.company = null;
isolatedScope.selectCompany(company);
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.name).toBe(company.name);
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Organization item and update the data of Support Group dropdown when user selects any value from Support Organization if location company is null', function () {
var organization = {
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
};
spyAssigneeSupportDropdown(this);
isolatedScope.ticket.company = null;
isolatedScope.selectOrganization(organization);
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('IT Support');
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select Support Group item when user selects any value from Support Group if location company is null', function () {
var group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function (input) {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
isolatedScope.ticket.company = null;
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
});
it('should select the assignee group and make the form dirty', function () {
var ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT)),
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
}, directiveElem, isolatedScope;
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
isolatedScope.assignee.isGroup = false;
isolatedScope.assignToGroup();
isolatedScope.$apply();
expect(isolatedScope.assignee.isGroup).toBeTruthy();
expect(isolatedScope.$emit).toHaveBeenCalledWith(this.events.MODAL_FORM_IS_DIRTY);
});
describe('should select assignee person', function () {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT));
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
});
it('and select its parent in case of person type parent', function () {
var selectedPerson = {
type: 'parent',
fullName: 'Allen Allbrook',
id: 'Allen'
};
isolatedScope.selectedParent = {};
isolatedScope.assignToPerson(selectedPerson);
isolatedScope.$apply();
expect(isolatedScope.selectedParent.fullName).toBe(selectedPerson.fullName);
});
it('and make the form dirty in case of person type child', function () {
var selectedPerson = {
type: 'child',
fullName: 'Allen Allbrook',
id: 'Allen'
};
isolatedScope.assignee.isGroup = true;
isolatedScope.assignToPerson(selectedPerson);
isolatedScope.$apply();
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.person.fullName).toBe(selectedPerson.fullName);
expect(isolatedScope.$emit).toHaveBeenCalledWith(this.events.MODAL_FORM_IS_DIRTY);
});
});
it('should click on search text box cross icon to delete search text and populate all records if assign to me checkbox is not checked', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT));
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.search.text = 'Allen';
isolatedScope.search.filterText = 'Allen';
isolatedScope.clearSearchText();
isolatedScope.$apply();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.assigneeLoginId).toBe('');
expect(isolatedScope.search.filterText).toBe('');
});
it('should set Support Group to All if user clicks on expanding your search to all groups', function () {
var ticket, assignee, directiveElem, isolatedScope, group, list;
ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT));
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
list = {
"results": [
{
"type": "person",
"firstName": "App",
"lastName": "Admin",
"fullName": "App Admin",
"company": {
"name": "Calbro Services"
},
"organization": "IT Support",
"loginId": "App",
"id": "App",
"supportGroup": "Frontoffice Support",
"supportGroupId": "SGP000000000010",
"supportOrganization": "IT Support 1"
}
],
"totalMatches": 1
};
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function (input) {
let deferred = $q.defer();
deferred.resolve(personList);
return deferred.promise;
});
spyOn(this.ticketService, 'getAssigneeSupportGroupPersons').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(list);
return deferred.promise;
});
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(0);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
isolatedScope.setGroupToAll();
isolatedScope.$apply();
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('App Admin');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
describe('if ticket type is incident and records is greater than chunk size then', function () {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = new IncidentVO(loadTicketData(EntityVO.TYPE_INCIDENT));
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
this.searchModel.supportGroupChunkSize = 3;
this.searchModel.organizationChunkSize = 3;
this.searchModel.companyChunkSize = 3;
this.searchModel.supportPersonChunkSize = 3;
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('user can search for support group', function () {
spyOn(this.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrgByName').and.callFake(function () {
deferred.resolve(groupList);
return deferred.promise;
});
isolatedScope.getSupportGroupsForCompanyAndOrgByName('%%%');
isolatedScope.$apply();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName).toHaveBeenCalled();
});
it('user can search for organizations', function () {
spyOn(this.searchModel, 'getSupportOrganizationsByTextAndCompany').and.callFake(function () {
deferred.resolve(organizationList);
return deferred.promise;
});
isolatedScope.getSupportOrganizationsByTextAndCompany('%%%');
isolatedScope.$apply();
expect(this.searchModel.getSupportOrganizationsByTextAndCompany).toHaveBeenCalled();
});
it('user can search for company', function () {
spyOn(this.searchModel, 'getAssigneeSupportCompaniesByText').and.callFake(function () {
deferred.resolve(companyList);
return deferred.promise;
});
isolatedScope.getCompaniesByName('%%%');
isolatedScope.$apply();
expect(this.searchModel.getAssigneeSupportCompaniesByText).toHaveBeenCalled();
});
it('user can select any value from Support Company and data of other dropdowns will be updated accordingly', function () {
var company = {
"name": "Calbro Services",
"attributeMap": {}
};
isolatedScope.selectCompany(company);
isolatedScope.$apply();
expect(isolatedScope.assigneeCompany.name).toBe(company.name);
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons.length).toBe(4);
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('user can select any value from Support Organization and data of other dropdowns will be updated accordingly', function () {
var organization = {
"name": "IT Support",
"attributeMap": {
"companyName": "Calbro Services"
},
"companyName": "Calbro Services"
};
isolatedScope.selectOrganization(organization);
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('IT Support');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons.length).toBe(4);
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('user can select any value from Support Group', function () {
var group = {
"name": "Backoffice Support",
"organization": "IT Support",
"company": {
"name": "Calbro Services"
},
"id": "SGP000000000009",
"companyName": "Calbro Services",
"persons": []
};
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignee.group.name).toBe('Backoffice Support');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons.length).toBe(1);
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('user can select any value from Support Group if selected group is All', function () {
var group = {
"name": "All",
"id": "All",
"companyName": "Calbro Services",
"persons": []
};
isolatedScope.selectGroup(group);
isolatedScope.$apply();
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons.length).toBe(4);
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
});
describe('if ticket type is Knowledge Article and records is greater than chunk size then', function () {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
this.searchModel.supportGroupChunkSize = 3;
this.searchModel.organizationChunkSize = 3;
this.searchModel.companyChunkSize = 3;
this.searchModel.supportPersonChunkSize = 3;
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('user can search for support group', function () {
spyOn(this.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrgByName').and.callFake(function () {
deferred.resolve(groupList);
return deferred.promise;
});
isolatedScope.getSupportGroupsForCompanyAndOrgByName('%%%');
isolatedScope.$apply();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName).toHaveBeenCalled();
});
it('user can search for organizations', function () {
spyOn(this.searchModel, 'getSupportOrganizationsByTextAndCompany').and.callFake(function () {
deferred.resolve(groupList);
return deferred.promise;
});
isolatedScope.getSupportOrganizationsByTextAndCompany('%%%');
isolatedScope.$apply();
expect(this.searchModel.getSupportOrganizationsByTextAndCompany).toHaveBeenCalled();
});
});
describe('if ticket type is task and records is greater than chunk size then', function () {
var ticket, assignee, directiveElem, isolatedScope;
beforeEach(function () {
ticket = loadTicketData(EntityVO.TYPE_TASK);
assignee = {
isGroup: false,
autoAssign: false,
person: new PersonVO(),
group: {
id: 'All',
person: [new PersonVO()]
}
};
this.searchModel.supportGroupChunkSize = 3;
this.searchModel.organizationChunkSize = 3;
this.searchModel.companyChunkSize = 3;
this.searchModel.supportPersonChunkSize = 3;
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
});
it('user can search for support group', function () {
spyOn(this.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrgByName').and.callFake(function () {
deferred.resolve(groupList);
return deferred.promise;
});
isolatedScope.getSupportGroupsForCompanyAndOrgByName('%%%');
isolatedScope.$apply();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName).toHaveBeenCalled();
});
it('user can search for organizations', function () {
spyOn(this.searchModel, 'getSupportOrganizationsByTextAndCompany').and.callFake(function () {
deferred.resolve(organizationList);
return deferred.promise;
});
isolatedScope.getSupportOrganizationsByTextAndCompany('%%%');
isolatedScope.$apply();
expect(this.searchModel.getSupportOrganizationsByTextAndCompany).toHaveBeenCalled();
});
it('user can search for support group if location company is null', function () {
spyOn(this.searchModel, 'getAssigneeSupportGroupsForCompanyAndOrgByName').and.callFake(function () {
deferred.resolve(groupList);
return deferred.promise;
});
isolatedScope.ticket.company = null;
isolatedScope.getSupportGroupsForCompanyAndOrgByName('%%%');
isolatedScope.$apply();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrgByName).toHaveBeenCalled();
});
it('user can search for organizations if location company is null', function () {
spyOn(this.searchModel, 'getSupportOrganizationsByTextAndCompany').and.callFake(function () {
deferred.resolve(organizationList);
return deferred.promise;
});
isolatedScope.ticket.company = null;
isolatedScope.getSupportOrganizationsByTextAndCompany('%%%');
isolatedScope.$apply();
expect(this.searchModel.getSupportOrganizationsByTextAndCompany).toHaveBeenCalled();
});
});
it('should load blade in case of problem coordinator role and it is assigned to logged in user and ticket type is Known Error', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWNERROR);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: 'Allen'
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee, 'problemcoordinator');
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assignToMe).toBeTruthy();
expect(isolatedScope.assignee.person.supportGroupId).toBe(ticket.coordinatorGroup.id);
expect(isolatedScope.assignee.person.supportGroup).toBe(ticket.coordinatorGroup.name);
expect(isolatedScope.assigneeCompany.id).toBe('All');
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('Allen Allbrook');
expect(isolatedScope.assigneeLoginId).toBe('Allen');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith('', '', 'problemcoordinator', null, 'Calbro Services', null, null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith('', null, 'problemcoordinator', 'Calbro Services', null, null, null, null);
});
it('should load blade in case of work order manager role and ticket type is work order', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_WORKORDER);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee, 'workordermanager');
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'workordermanager', null, 'Calbro Services', 'Calbro Services', null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'workordermanager', 'Calbro Services', 'Calbro Services', null, null, null);
});
it('should load blade if role is not defined(so it would be workorderassignee) and ticket type is work order', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_WORKORDER);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'workorderassignee', null, 'Calbro Services', 'Calbro Services', null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'workorderassignee', 'Calbro Services', 'Calbro Services', null, null, null);
});
it('should load blade if role is not defined(so it would be releasecoordinator) and ticket type is release', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_RELEASE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'releasecoordinator', null, 'Calbro Services', null, null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'releasecoordinator', 'Calbro Services', null, null, null, null);
});
it('should load blade if role is changecoordinator and ticket type is Change request', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_CHANGE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee, 'changecoordinator');
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(isolatedScope.assignee.person.supportGroupId).toBe(ticket.supportGroup.id);
expect(isolatedScope.assignee.person.supportGroup).toBe(ticket.supportGroup.name);
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'changecoordinator', null, 'Calbro Services', 'Calbro Services', null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'changecoordinator', 'Calbro Services', 'Calbro Services', null, null, null);
});
it('should load blade if role is changemanager and ticket type is Change request', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_CHANGE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee, 'changemanager');
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeTruthy();
expect(isolatedScope.assignee.person.supportGroupId).toBe(ticket.supportGroup.id);
expect(isolatedScope.assignee.person.supportGroup).toBe(ticket.supportGroup.name);
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'changemanager', null, 'Calbro Services', 'Calbro Services', null, null, null);
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'changemanager', 'Calbro Services', 'Calbro Services', null, null, null);
});
it('should load blade if role is not defined(so it would be knowledgeassignee) and ticket type is knowledge', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {
id: 'All',
person: [new PersonVO()]
}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.conditions.showAssignToMe).toBeTruthy();
expect(isolatedScope.assigneeOrganization.id).toBe('All');
expect(isolatedScope.assignee.group.id).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.search.text).toBe('');
expect(isolatedScope.conditions.showAssignToGroup).toBeFalsy();
expect(this.searchModel.getAssigneeSupportGroupsForCompanyAndOrg).toHaveBeenCalledWith(undefined, '', 'knowledgeassignee', null, null, null, 'Calbro Services', null, 'Calbro Services');
expect(this.searchModel.getAssigneeSupportOrgByCompany).toHaveBeenCalledWith(undefined, null, 'knowledgeassignee', null, null, 'Calbro Services', null, 'Calbro Services');
});
it('should select company on init if assignee is not assigned in case of Knowledge ticket', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.assigneeCompany.name).toBe('Calbro Services');
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select company on init if problem coordinator is not assigned in case of Known Error', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWNERROR);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.assigneeCompany.name).toBe('Calbro Services');
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select company on init if assignment is not done and company is selected while creating Incident', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_INCIDENT);
ticket.selectedCompany = 'Calbro Services';
delete ticket.customer;
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.assigneeCompany.name).toBe('Calbro Services');
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should select company on init if assignment is not done and company is selected while creating Knowledge', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
ticket.author = {
company: {
name: 'Calbro Services'
}
};
delete ticket.customer;
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {}
};
spyAllInitService(this);
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
expect(isolatedScope.assigneeCompany.name).toBe('Calbro Services');
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.group.name).toBe('All');
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('');
});
it('should successfully watch data.setValueFlag', function () {
var ticket, assignee, directiveElem, isolatedScope;
ticket = loadTicketData(EntityVO.TYPE_KNOWLEDGE);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: ''
},
group: {}
};
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
isolatedScope.data = {
setValueFlag: 'test',
name: 'test'
};
isolatedScope.$apply();
expect(isolatedScope.data.setValueFlag).toBe('#$#');
expect(isolatedScope.$emit).toHaveBeenCalledWith(this.events.WIDGET_VALUE_CHANGE, {fieldName: isolatedScope.data.name});
});
it('should intellisense person list while typing person name in search box if tooManySupportPeople is true ', function () {
var ticket, assignee, directiveElem, isolatedScope;
spyAllInitService(this);
ticket = loadTicketData(EntityVO.TYPE_KNOWNERROR);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: 'Bob'
},
group: {
id: 'Backoffice Support'
}
};
this.searchModel.supportPersonChunkSize = 2;
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.search.text = 'Alle';
isolatedScope.onSearchTextChanged();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('');
expect(isolatedScope.search.text).toBe('Alle');
});
it('should intellisense person list while typing person name in search box if tooManySupportPeople is false ', function () {
var ticket, assignee, directiveElem, isolatedScope;
spyOn(this.searchModel, 'getAssigneeSupportCompanies').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve(companyList);
return deferred.promise;
});
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
if (arguments[0] === 'customerCompany' || arguments[0] === 'locationCompany') {
return 'Calbro Services';
}
return '';
});
spyOn(this.ticketService, 'getAssigneeBySupportGroupId').and.callFake(function () {
let deferred = $q.defer();
deferred.resolve({ results: [personList.results[0]], exceedsChunkSize: false });
return deferred.promise;
});
spyAssigneeSupportDropdown(this);
ticket = loadTicketData(EntityVO.TYPE_KNOWNERROR);
assignee = {
isGroup: false,
autoAssign: false,
person: {
loginId: 'Bob'
},
group: {
id: 'SGP000000000009'
}
};
directiveElem = getCompiledElement(ticket, false, assignee);
isolatedScope = directiveElem.isolateScope();
isolatedScope.search.text = 'Alle';
isolatedScope.onSearchTextChanged();
this.$timeout.flush();
isolatedScope.$apply();
expect(isolatedScope.assigneeOrganization.name).toBe('All');
expect(isolatedScope.assignment.organizations.length).toBe(4);
expect(isolatedScope.assignment.groups.length).toBe(5);
expect(isolatedScope.assignee.isGroup).toBeFalsy();
expect(isolatedScope.assignee.group.persons[0].fullName).toBe('Allen Allbrook');
expect(isolatedScope.search.filterText).toBe('Alle');
expect(isolatedScope.search.text).toBe('Alle');
});
});