1571 lines
60 KiB
JavaScript
1571 lines
60 KiB
JavaScript
describe('Test feed-comment-thread directive', function () {
|
||
var element, scope, compile, rootScope, $httpBackend, elementScope, events, keyCodes, worknoteTypesData, metadataModel, $q, $templateCache, timelineItem,
|
||
smartRecorderModel, assetList, personList, $window, i18nService, feedModel, attachmentService, systemAlertService, configurationModel;
|
||
|
||
beforeEach(module('myitsmApp', 'templates', 'ticketModule'));
|
||
beforeEach(function () {
|
||
inject(function ($compile, $rootScope, $injector, _events_, _metadataModel_, _$q_, _$templateCache_, _smartRecorderModel_, _$window_, _i18nService_,
|
||
_feedModel_, _attachmentService_, _systemAlertService_, _configurationModel_) {
|
||
$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\/v2\/metadata/).respond(new MetadataVO());
|
||
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
||
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
|
||
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
|
||
compile = $compile;
|
||
rootScope = $rootScope;
|
||
scope = $rootScope.$new();
|
||
events = _events_;
|
||
metadataModel = _metadataModel_;
|
||
$q = _$q_;
|
||
$templateCache = _$templateCache_;
|
||
smartRecorderModel = _smartRecorderModel_;
|
||
$window = _$window_;
|
||
i18nService = _i18nService_;
|
||
feedModel = _feedModel_;
|
||
attachmentService = _attachmentService_;
|
||
systemAlertService = _systemAlertService_;
|
||
configurationModel = _configurationModel_;
|
||
});
|
||
});
|
||
|
||
beforeEach(function () {
|
||
navigator.__defineGetter__('userAgent', function(){
|
||
return 'Chrome';// customized user agent
|
||
});
|
||
|
||
keyCodes = {
|
||
enter: 13,
|
||
leftArrow: 37,
|
||
rightArrow: 39,
|
||
upArrow: 38,
|
||
downArrow: 40
|
||
};
|
||
|
||
worknoteTypesData = {
|
||
workinfoTypes: [
|
||
{
|
||
"type": "option",
|
||
"index": 16000,
|
||
"name": "Email System",
|
||
"label": "Email System",
|
||
"expanded": false
|
||
},
|
||
{
|
||
"type": "option",
|
||
"index": 29000,
|
||
"name": "General Information",
|
||
"label": "General Information",
|
||
"expanded": false
|
||
}
|
||
]
|
||
};
|
||
|
||
personList = [
|
||
{
|
||
"firstName": "Allen",
|
||
"lastName": "Allbrook",
|
||
"fullName": "Allen Allbrook"
|
||
},
|
||
{
|
||
"firstName": "Irwin",
|
||
"lastName": "Allen",
|
||
"fullName": "Irwin Allen"
|
||
}
|
||
];
|
||
|
||
assetList = {
|
||
"objects": [
|
||
{
|
||
"name": "7L851BS",
|
||
"desc": "",
|
||
"type": "Hardware",
|
||
"company": {
|
||
"name": "Petramco"
|
||
},
|
||
"product": {
|
||
"name": "OptiPlex",
|
||
"model": "3010"
|
||
}
|
||
},
|
||
{
|
||
"name": "AkhShukl-pun",
|
||
"desc": "",
|
||
"type": "Hardware",
|
||
"company": {
|
||
"name": "Petramco"
|
||
},
|
||
"product": {
|
||
"name": "OptiPlex",
|
||
"model": "7010"
|
||
}
|
||
}
|
||
],
|
||
"totalMatches": 2
|
||
};
|
||
|
||
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve(worknoteTypesData);
|
||
return deferred.promise;
|
||
});
|
||
|
||
spyOn(smartRecorderModel, 'getListOfPersons').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve({exceedsChunkSize: true, list: personList});
|
||
return deferred.promise;
|
||
});
|
||
|
||
spyOn(smartRecorderModel, 'getListOfAssets').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve(assetList);
|
||
return deferred.promise;
|
||
});
|
||
});
|
||
|
||
function getCompiledElement(type) {
|
||
element = angular.element('<div feed-comment-thread="" ' +
|
||
'threads="" ' +
|
||
'nesting-level="0" ' +
|
||
'parent-context="parentContext" ' +
|
||
'type="type" ' +
|
||
'timeline-item="timelineItem"' +
|
||
'is-draft="isDraft" ></div>');
|
||
|
||
switch (type) {
|
||
case EntityVO.TYPE_INCIDENT:
|
||
scope.parentContext = new IncidentVO();
|
||
break;
|
||
case EntityVO.TYPE_CHANGE:
|
||
scope.parentContext = new ChangeVO();
|
||
break;
|
||
}
|
||
|
||
scope.type = type;
|
||
scope.isDraft = false;
|
||
|
||
var directiveElem = compile(element)(scope);
|
||
|
||
scope.$digest();
|
||
$('body').append(element);
|
||
|
||
elementScope = element.isolateScope();
|
||
|
||
return directiveElem;
|
||
}
|
||
|
||
function loadTemplateCache (directiveElem) {
|
||
directiveElem.trigger('click');
|
||
}
|
||
|
||
function mockForIEBrowser() {
|
||
navigator.__defineGetter__('userAgent', function(){
|
||
return 'MSIE';// customized user agent
|
||
});
|
||
}
|
||
|
||
it('should compile', function () {
|
||
var directiveElem = getCompiledElement();
|
||
var divElem = directiveElem[0];
|
||
expect(divElem).toBeDefined();
|
||
});
|
||
|
||
it('add note UI should appear when set to focus', function () {
|
||
getCompiledElement();
|
||
|
||
spyOn(elementScope, 'addNoteForm').and.callThrough();
|
||
|
||
expect(element.find('.timeline-note').length).toEqual(0);
|
||
|
||
rootScope.$broadcast(events.SET_FOCUS_TO_ACTIVITY_INPUT);
|
||
scope.$digest();
|
||
|
||
expect(elementScope.addNoteForm).toHaveBeenCalled();
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').length).toEqual(1);
|
||
});
|
||
|
||
it('should enable "Share with Vendor" checkbox when incident contains brokerVendorName data', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
rootScope.$broadcast(events.SET_FOCUS_TO_ACTIVITY_INPUT);
|
||
scope.$digest();
|
||
|
||
expect(elementScope.state.isVendorEnabled).not.toEqual(true);
|
||
expect(elementScope.commentFormNode.find('input[ng-model="state.shareWithVendor"]').length).toEqual(0);
|
||
|
||
scope.parentContext.brokerVendorName = 'JIRA';
|
||
scope.$digest();
|
||
|
||
expect(elementScope.state.isVendorEnabled).toEqual(true);
|
||
expect(elementScope.commentFormNode.find('input[ng-model="state.shareWithVendor"]').length).toEqual(1);
|
||
});
|
||
|
||
it('should enable "Share with Vendor" checkbox when Change Request contains brokerVendorName data', function () {
|
||
getCompiledElement(EntityVO.TYPE_CHANGE);
|
||
rootScope.$broadcast(events.SET_FOCUS_TO_ACTIVITY_INPUT);
|
||
scope.$digest();
|
||
|
||
expect(elementScope.state.isVendorEnabled).not.toEqual(true);
|
||
expect(elementScope.commentFormNode.find('input[ng-model="state.shareWithVendor"]').length).toEqual(0);
|
||
|
||
scope.parentContext.brokerVendorName = 'AWS';
|
||
scope.$digest();
|
||
|
||
expect(elementScope.state.isVendorEnabled).toEqual(true);
|
||
expect(elementScope.commentFormNode.find('input[ng-model="state.shareWithVendor"]').length).toEqual(1);
|
||
});
|
||
|
||
it('paste data to feed', function () {
|
||
getCompiledElement();
|
||
var event = jasmine.createSpyObj('e', [ 'preventDefault' ]);
|
||
|
||
elementScope.handleSmartInputPaste(event);
|
||
expect(event.preventDefault).toHaveBeenCalled();
|
||
});
|
||
|
||
it('should load work note types on load', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
expect(elementScope.worknoteTypes[0].name).toBe('Email System');
|
||
});
|
||
|
||
it('should prevent the cursor from moving on the text input field if type-ahead popup is active. The up, down and enter keys will be used exclusive for selection purposes', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
var upArrowEvent, downArrowEvent, leftArrowEvent, rightArrowEvent, enterKeyEvent;
|
||
upArrowEvent = downArrowEvent = leftArrowEvent = rightArrowEvent = enterKeyEvent = jasmine.createSpyObj('e', [ 'preventDefault' ]);
|
||
elementScope.showPopup = true;
|
||
|
||
upArrowEvent.keyCode = keyCodes.upArrow;
|
||
elementScope.handleSmartInputKeyDown(upArrowEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(upArrowEvent.preventDefault).toHaveBeenCalled();
|
||
|
||
downArrowEvent.keyCode = keyCodes.downArrow;
|
||
elementScope.handleSmartInputKeyDown(downArrowEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(downArrowEvent.preventDefault).toHaveBeenCalled();
|
||
|
||
leftArrowEvent.keyCode = keyCodes.leftArrow;
|
||
elementScope.handleSmartInputKeyDown(leftArrowEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(leftArrowEvent.preventDefault).toHaveBeenCalled();
|
||
|
||
rightArrowEvent.keyCode = keyCodes.rightArrow;
|
||
elementScope.handleSmartInputKeyDown(rightArrowEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(rightArrowEvent.preventDefault).toHaveBeenCalled();
|
||
|
||
enterKeyEvent.keyCode = keyCodes.enter;
|
||
elementScope.handleSmartInputKeyDown(enterKeyEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(enterKeyEvent.preventDefault).toHaveBeenCalled();
|
||
});
|
||
|
||
it('should forcefully insert <br> tag instead of <div> or <p> tags for all browsers on press of enter key', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
var enterKeyEvent = jasmine.createSpyObj('e', [ 'preventDefault' ]),
|
||
range = {
|
||
deleteContents: jasmine.createSpy('deleteContents'),
|
||
insertNode: jasmine.createSpy('insertNode'),
|
||
setStartAfter: jasmine.createSpy('setStartAfter'),
|
||
setEndAfter: jasmine.createSpy('setEndAfter'),
|
||
collapse: jasmine.createSpy('collapse')
|
||
},
|
||
rangeObject = {
|
||
getRangeAt: function() {
|
||
return range;
|
||
},
|
||
removeAllRanges: jasmine.createSpy('removeAllRanges'),
|
||
addRange: jasmine.createSpy('addRange')
|
||
};
|
||
spyOn(window, 'getSelection').and.returnValue(rangeObject);
|
||
|
||
enterKeyEvent.keyCode = keyCodes.enter;
|
||
elementScope.handleSmartInputKeyDown(enterKeyEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(range.deleteContents).toHaveBeenCalled();
|
||
expect(range.insertNode).toHaveBeenCalled();
|
||
expect(range.setStartAfter).toHaveBeenCalled();
|
||
expect(range.setEndAfter).toHaveBeenCalled();
|
||
expect(range.collapse).toHaveBeenCalled();
|
||
expect(rangeObject.removeAllRanges).toHaveBeenCalled();
|
||
expect(rangeObject.addRange).toHaveBeenCalled();
|
||
expect(enterKeyEvent.preventDefault).toHaveBeenCalled();
|
||
});
|
||
|
||
it('should load fire clickFocusInHandler on click/focus in of activity note text area and load template in cache if it is not already loaded', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
loadTemplateCache(directiveElem);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedWorknoteType.name).toBe('General Information');
|
||
expect(elementScope.state.noteFormIsActive).toBeTruthy();
|
||
expect(elementScope.editMode).toBeTruthy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text-container').length).toBe(1);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__attachments').length).toBe(1);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__message').length).toBe(1);
|
||
expect($templateCache.get('views/feed/feed-add-note-form.html')).toBeDefined();
|
||
});
|
||
|
||
it('should perform check on user input and replace <br> with \n for inputText model', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content<br>Next Line<br><br><br>Three Line Space';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputTextHtml).toBe(testContent);
|
||
expect(elementScope.inputText).toBe('Text Content\nNext Line\n\n\nThree Line Space');
|
||
});
|
||
|
||
it('should not do anything if shift or ctrl key is pressed', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content<br>Next Line<br><br><br>Three Line Space';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
keyUpEvent.ctrlKey = true;
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputTextHtml).toBe(testContent);
|
||
expect(elementScope.inputText).toBe('Text Content\nNext Line\n\n\nThree Line Space');
|
||
});
|
||
|
||
it('should perform check on user input and replace <p> with \n for inputText model in case of IE browser', function () {
|
||
mockForIEBrowser();
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content<p></p>Next Line<p></p><p></p><p></p>Three Line Space';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputTextHtml).toBe(testContent);
|
||
expect(elementScope.inputText).toBe('Text Content\nNext Line\n\n\nThree Line Space');
|
||
});
|
||
|
||
it('should check for @ and should show the person list popup', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.popupType).toBe('profile');
|
||
expect(elementScope.actualTypeAheadText).toBe('Allen');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.showPopup).toBeTruthy();
|
||
expect(elementScope.showPopupHeader).toBeTruthy();
|
||
expect(elementScope.typeAheadText).toBe('Allen');
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.personProfileList[0].firstName).toBe('Allen');
|
||
expect(elementScope.personProfileListFilteredLength).toBe(2);
|
||
});
|
||
|
||
it('should check for @ and should show the asset list popup', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
personList = [];
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Opti';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.assetProfileList[0].product.name).toBe('OptiPlex');
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(2);
|
||
expect(elementScope.typeAheadText).toBe('Opti');
|
||
});
|
||
|
||
it('should highlight the above person item if user press up key to move upward in case of person/asset list popup', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
keyUpEvent.keyCode = keyCodes.upArrow;
|
||
elementScope.showPopup = true;
|
||
elementScope.typeAheadListPos = 2;
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.typeAheadListPos).toBe(1);
|
||
});
|
||
|
||
it('should highlight the below person item if user press down key to move downward in case of person/asset list popup', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
keyUpEvent.keyCode = keyCodes.downArrow;
|
||
elementScope.showPopup = true;
|
||
elementScope.typeAheadListPos = 0;
|
||
elementScope.personProfileListFilteredLength = 2;
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.typeAheadListPos).toBe(1);
|
||
});
|
||
|
||
describe('should select the highlighted person, replace with full person name at right position and close the popup if user hit enter key', function () {
|
||
var directiveElem, keyUpEvent, testContent;
|
||
beforeEach(function () {
|
||
mockForIEBrowser();
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
keyUpEvent = new Event('keyup');
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
keyUpEvent.keyCode = keyCodes.enter;
|
||
});
|
||
|
||
it(' if last node is text then insert nbsp at end', function () {
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedText).toBe('@Allen');
|
||
expect(elementScope.inputText).toBe('Text Content Allen Allbrook');
|
||
expect(elementScope.inputTextHtml).toBe('Text Content <span class="smart-recorder-highlightPerfectMatch ng-scope" contenteditable="true">Allen Allbrook</span>');
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
it(' if last node is <br> then select the previous node', function () {
|
||
testContent = 'Text Content @Allen<br>';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedText).toBe('@Allen');
|
||
expect(elementScope.inputText).toBe('Text Content Allen Allbrook');
|
||
expect(elementScope.inputTextHtml).toBe('Text Content <span class="smart-recorder-highlightPerfectMatch ng-scope" contenteditable="true">Allen Allbrook</span><br>');
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
it(' if last node is <span> then replace with nbsp', function () {
|
||
testContent = 'Text Content @Allen<span></span>';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedText).toBe('@Allen');
|
||
expect(elementScope.inputText).toBe('Text Content Allen Allbrook');
|
||
expect(elementScope.inputTextHtml).toBe('Text Content <span class="smart-recorder-highlightPerfectMatch ng-scope" contenteditable="true">Allen Allbrook</span><span></span>');
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
});
|
||
|
||
it('should select the highlighted asset, replace with full asset name at right position and close the popup if user hit enter key', function () {
|
||
var directiveElem, keyUpEvent, testContent;
|
||
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
keyUpEvent = new Event('keyup');
|
||
|
||
personList = [];
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Text Content @Opti';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
keyUpEvent.keyCode = keyCodes.enter;
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedText).toBe('@Opti');
|
||
expect(elementScope.inputText).toBe('Text Content 7L851BS');
|
||
expect(elementScope.inputTextHtml).toBe('Text Content <span class="smart-recorder-highlightPerfectMatch ng-scope" contenteditable="false">7L851BS</span><br>');
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
it('should close person/asset list popup if user removes all the content', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = '@Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
testContent = '';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
it('should close person/asset list popup if user removes content till @', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'Test Content @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
testContent = 'Test Content';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
it('should highlight potential item in case of person and should show list of potential match and if user hit the enter key then it should replace with name', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent,
|
||
clickEvent = $.Event('click');
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = '@Allen what to ';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
testContent = '@Allen what to d';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Allen what to d');
|
||
|
||
//if popup is already opened then close it and open its own popup
|
||
elementScope.showPopup = true;
|
||
|
||
clickEvent.currentTarget = elementScope.commentFormNode.find('.smart-recorder-highlight')[0];
|
||
|
||
//Should list potential match on click of highlighted item
|
||
elementScope.handleSmartInputHighlightSelected(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.personProfileList[0].firstName).toBe('Allen');
|
||
expect(elementScope.selectedText).toBe('Allen');
|
||
expect(elementScope.showPopup).toBeTruthy();
|
||
|
||
//Replace Potential item with Confirmed people name on press of enter key on person list
|
||
keyUpEvent.keyCode = keyCodes.enter;
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').html()).toBe('<span class="smart-recorder-highlightPerfectMatch" contenteditable="false">Allen Allbrook</span> what to d<br>');
|
||
});
|
||
|
||
it('should highlight potential item in case of asset', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('click'),
|
||
testContent;
|
||
|
||
personList = [];
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = '@Optiplex this is ';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
testContent = '@Optiplex this is i';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Optiplex this is i');
|
||
});
|
||
|
||
it('should reset all the parameters if typeahead text length is less then 3', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyUpEvent = new Event('keyup'),
|
||
testContent;
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
testContent = 'This is @Allen';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.showPopup).toBeTruthy();
|
||
expect(elementScope.personProfileList.length).toBe(2);
|
||
expect(elementScope.typeAheadText).toBe('Allen');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(2);
|
||
expect(elementScope.showPopupHeader).toBeTruthy();
|
||
|
||
testContent = 'This is @A';
|
||
|
||
//enter some text in text area
|
||
elementScope.commentFormNode.find('.timeline-note__text').html(testContent);
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
});
|
||
|
||
describe('should paste the copied content', function () {
|
||
var pasteEvent, directiveElem, pasteContent;
|
||
beforeEach(function () {
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
pasteEvent = jasmine.createSpyObj('e', [ 'preventDefault' ]);
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
personList = [];
|
||
|
||
loadTemplateCache(directiveElem);
|
||
|
||
pasteContent = 'Copied Content';
|
||
});
|
||
|
||
it('if originalEvent is supported by browser', function () {
|
||
pasteEvent.originalEvent = {
|
||
clipboardData: {
|
||
getData: function () {
|
||
return pasteContent;
|
||
}
|
||
}
|
||
};
|
||
|
||
spyOn(document, 'queryCommandSupported').and.callFake(function (command) {
|
||
return command === 'insertText' ? true: false;
|
||
});
|
||
|
||
spyOn(document, 'execCommand');
|
||
|
||
elementScope.handleSmartInputPaste(pasteEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(document.execCommand).toHaveBeenCalledWith('insertText', false, pasteContent);
|
||
});
|
||
|
||
it('if originalEvent is not supported by browser but window clipboard is supported by browser', function () {
|
||
$window.clipboardData = jasmine.createSpyObj('clipboardData', ['test']);
|
||
$window.clipboardData.getData = function () {
|
||
return pasteContent;
|
||
};
|
||
|
||
spyOn(document, 'queryCommandSupported').and.callFake(function (command) {
|
||
return command === 'insertText' ? true: false;
|
||
});
|
||
|
||
spyOn(document, 'execCommand');
|
||
elementScope.handleSmartInputPaste(pasteEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(document.execCommand).toHaveBeenCalledWith('insertText', false, pasteContent);
|
||
});
|
||
|
||
it('if insertText command is not supported by browser but paste query command is supported by browser', function () {
|
||
pasteEvent.originalEvent = {
|
||
clipboardData: {
|
||
getData: function () {
|
||
return pasteContent;
|
||
}
|
||
}
|
||
};
|
||
spyOn(document, 'queryCommandSupported').and.callFake(function (command) {
|
||
return command === 'paste' ? true: false;
|
||
});
|
||
|
||
spyOn(document, 'execCommand');
|
||
elementScope.handleSmartInputPaste(pasteEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(document.execCommand).toHaveBeenCalledWith('paste', false, pasteContent);
|
||
});
|
||
|
||
it('if both insertText and paste command are not supported by browser then it should not do anything', function () {
|
||
pasteEvent.originalEvent = {
|
||
clipboardData: {
|
||
getData: function () {
|
||
return pasteContent;
|
||
}
|
||
}
|
||
};
|
||
spyOn(document, 'queryCommandSupported').and.callFake(function (command) {
|
||
return false;
|
||
});
|
||
|
||
spyOn(document, 'execCommand');
|
||
elementScope.handleSmartInputPaste(pasteEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(document.execCommand).not.toHaveBeenCalledWith('paste', false, pasteContent);
|
||
expect(document.execCommand).not.toHaveBeenCalledWith('insertText', false, pasteContent);
|
||
});
|
||
});
|
||
|
||
describe('should add @ to the activity note text area on click of @', function () {
|
||
var directiveElem, range, rangeObject;
|
||
beforeEach(function () {
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
range = {
|
||
deleteContents: jasmine.createSpy('deleteContents'),
|
||
insertNode: jasmine.createSpy('insertNode'),
|
||
cloneRange: function () {
|
||
return range;
|
||
},
|
||
setStartAfter: jasmine.createSpy('setStartAfter'),
|
||
collapse: jasmine.createSpy('collapse'),
|
||
selectNodeContents: jasmine.createSpy('selectNodeContents'),
|
||
commonAncestorContainer: ''
|
||
};
|
||
rangeObject = {
|
||
getRangeAt: function() {
|
||
return range;
|
||
},
|
||
removeAllRanges: jasmine.createSpy('removeAllRanges'),
|
||
addRange: jasmine.createSpy('addRange'),
|
||
rangeCount: 1
|
||
};
|
||
spyOn(window, 'getSelection').and.callFake(function () {
|
||
return navigator.userAgent === 'MSIE'? false: rangeObject;
|
||
});
|
||
});
|
||
|
||
it('if browser is chrome', function () {
|
||
range.commonAncestorContainer = elementScope.commentFormNode.find('.timeline-note__text')[0];
|
||
|
||
elementScope.toggleMentioning();
|
||
elementScope.$apply();
|
||
|
||
expect(range.deleteContents).toHaveBeenCalled();
|
||
expect(range.insertNode).toHaveBeenCalled();
|
||
expect(range.setStartAfter).toHaveBeenCalled();
|
||
expect(range.collapse).toHaveBeenCalled();
|
||
expect(rangeObject.removeAllRanges).toHaveBeenCalled();
|
||
expect(rangeObject.addRange).toHaveBeenCalled();
|
||
});
|
||
});
|
||
|
||
describe('user click on work note type section ', function () {
|
||
var clickEvent;
|
||
beforeEach(function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
clickEvent = jasmine.createSpyObj('e', ['preventDefault', 'stopPropagation']);
|
||
});
|
||
|
||
it(' and nothing will be happen when user click on expanded work note section', function () {
|
||
elementScope.worknoteTypes[0].expanded = true;
|
||
elementScope.expandWorknoteTypeSection(clickEvent, elementScope.worknoteTypes[0]);
|
||
elementScope.$apply();
|
||
|
||
expect(clickEvent.preventDefault).toHaveBeenCalled();
|
||
expect(clickEvent.stopPropagation).toHaveBeenCalled();
|
||
});
|
||
|
||
it(' and should able to expand work note section', function () {
|
||
elementScope.expandWorknoteTypeSection(clickEvent, elementScope.worknoteTypes[0]);
|
||
elementScope.$apply();
|
||
|
||
expect(clickEvent.preventDefault).toHaveBeenCalled();
|
||
expect(clickEvent.stopPropagation).toHaveBeenCalled();
|
||
expect(elementScope.worknoteTypes[0].expanded).toBeTruthy();
|
||
});
|
||
});
|
||
|
||
it('should work note type if user click on it', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
elementScope.selectWorknoteType(elementScope.worknoteTypes[0]);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedWorknoteType.name).toBe(elementScope.worknoteTypes[0].name);
|
||
});
|
||
|
||
it('should select work note if user press space key', function () {
|
||
var keyupEvent = jasmine.createSpyObj('e', ['preventDefault', 'stopPropagation']);
|
||
keyupEvent.keyCode = 32;
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
elementScope.handleKeydown(keyupEvent, elementScope.worknoteTypes[0]);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedWorknoteType.name).toBe(elementScope.worknoteTypes[0].name);
|
||
expect(keyupEvent.preventDefault).toHaveBeenCalled();
|
||
expect(keyupEvent.stopPropagation).toHaveBeenCalled();
|
||
});
|
||
|
||
it('should unbind all the events if scope is getting destroyed', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
elementScope.$destroy();
|
||
elementScope.$apply();
|
||
});
|
||
|
||
it('should unbind all the events if scope is getting destroyed', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
||
keyPressEvent = $.Event('keydown');
|
||
|
||
keyPressEvent.which = 13; //enter key down
|
||
directiveElem.trigger(keyPressEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedWorknoteType.name).toBe(elementScope.worknoteTypes[1].name);
|
||
});
|
||
|
||
it('should dismiss note form on click of set preview item or cancel button', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
rootScope.$broadcast(events.DISMISS_NOTE_FORM, {});
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.showPopup).toBeFalsy();
|
||
expect(elementScope.personProfileList.length).toBe(0);
|
||
expect(elementScope.assetProfileList.length).toBe(0);
|
||
expect(elementScope.typeAheadText).toBe('');
|
||
expect(elementScope.typeAheadListPos).toBe(0);
|
||
expect(elementScope.personProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.assetProfileListFilteredLength).toBe(0);
|
||
expect(elementScope.showPopupHeader).toBeFalsy();
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
expect(elementScope.state.shareWithVendor).toBeFalsy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.addFlagNote).toBeFalsy();
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
});
|
||
|
||
it('should add note on click of flag icon of knowledge ticket', function () {
|
||
getCompiledElement(EntityVO.TYPE_KNOWLEDGE);
|
||
|
||
rootScope.$broadcast(events.ADD_FLAG_NOTE, { flag: true });
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.selectedWorknoteType.name).toBe(elementScope.worknoteTypes[1].name);
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(elementScope.addFlagNote).toBeTruthy();
|
||
expect(elementScope.flag).toBeTruthy();
|
||
});
|
||
|
||
it('should focus the textAreaElement if textAreaElement is already initialized', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_KNOWLEDGE);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
spyOn(elementScope.commentFormNode, 'show');
|
||
|
||
rootScope.$broadcast(events.ADD_FLAG_NOTE, { flag: true });
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.show).toHaveBeenCalled();
|
||
});
|
||
|
||
describe('should load timeline activity notes in case of knowledge article', function () {
|
||
beforeEach(function () {
|
||
timelineItem = {
|
||
"type": "comment",
|
||
"note": {
|
||
"message": "Add Flag\n",
|
||
"workNoteTypeId": "FLAG0001",
|
||
"workNoteGuid": "IDGAA5V0HHE9CAP36DW5P29IXQSWTK",
|
||
},
|
||
"replies": [
|
||
{
|
||
"type": "comment"
|
||
}
|
||
]
|
||
};
|
||
|
||
scope.timelineItem = new FeedItemVO().build(timelineItem);
|
||
getCompiledElement(EntityVO.TYPE_KNOWLEDGE);
|
||
});
|
||
|
||
it('should set isThreadUnflagged and isFlagThread if there is any timeline activity notes', function () {
|
||
expect(elementScope.state.isThreadUnflagged).toBeFalsy();
|
||
expect(elementScope.isFlagThread).toBeFalsy();
|
||
});
|
||
});
|
||
|
||
it('should handle event SET_TICKET_DRAFT_MENTIONED if user mentioned any other customer in smart recorder and create ticket', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
smartRecorderModel.smartRecorderData = {
|
||
confirmedItems: [
|
||
{
|
||
"displayName": "Allen Allbrook",
|
||
"id": "Allen",
|
||
"type": "person",
|
||
"relationship": "",
|
||
"originalName": "Allen Allbrook"
|
||
},
|
||
{
|
||
"displayName": "Bob Baxter",
|
||
"id": "Bob",
|
||
"type": "person",
|
||
"relationship": "mentioned",
|
||
"originalName": "Bob Baxter"
|
||
},
|
||
{
|
||
"displayName": "Ivan",
|
||
"id": "Ivan",
|
||
"type": "person",
|
||
"relationship": "mentioned",
|
||
"originalName": "Ivan"
|
||
}
|
||
]
|
||
};
|
||
|
||
spyOn(i18nService, 'getLocalizedString').and.callFake(function (val) {
|
||
return val === 'createNew.ticket.mentionedPersons'? 'were mentioned when this ticket was logged': val;
|
||
});
|
||
rootScope.$broadcast(events.SET_TICKET_DRAFT_MENTIONED);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Bob Baxter, Ivan were mentioned when this ticket was logged');
|
||
});
|
||
|
||
it('should handle event SAVE_TICKET_DRAFT when user save draft ticket', function () {
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content');
|
||
|
||
rootScope.$broadcast(events.SAVE_TICKET_DRAFT);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Test Content');
|
||
expect(feedModel.pendingWorkNote.noteText).toBe('Test Content');
|
||
expect(elementScope.state.savingNote).toBeTruthy();
|
||
});
|
||
|
||
|
||
it('should not do anything if noteData does not have any value while saving draft ticket', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
rootScope.$broadcast(events.SAVE_TICKET_DRAFT);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('');
|
||
});
|
||
|
||
it('should upload the attachment and show it near text area', function () {
|
||
var attachment = {
|
||
"pendingSave": true,
|
||
"name": "user.png",
|
||
"size": 27117,
|
||
"file": {},
|
||
"fileExt": "png"
|
||
};
|
||
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
spyOn(attachmentService, 'prepareFileToUpload').and.returnValue(attachment);
|
||
|
||
elementScope.handleFileChange();
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.attachments[0].name).toBe('user.png');
|
||
});
|
||
|
||
it('should alert a warning if attachment file is empty', function () {
|
||
var attachment = {
|
||
size: 0
|
||
};
|
||
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
spyOn(attachmentService, 'prepareFileToUpload').and.returnValue(attachment);
|
||
spyOn(systemAlertService, 'warning');
|
||
|
||
elementScope.handleFileChange();
|
||
elementScope.$apply();
|
||
|
||
expect(systemAlertService.warning).toHaveBeenCalled();
|
||
});
|
||
|
||
it('should remove the attachment when user deletes the attachment', function () {
|
||
var attachment = {
|
||
"pendingSave": true,
|
||
"name": "user.png",
|
||
"size": 27117,
|
||
"file": {},
|
||
"fileExt": "png"
|
||
},
|
||
clickEvent = jasmine.createSpyObj('e', ['stopImmediatePropagation']);
|
||
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
elementScope.attachments[0] = attachment;
|
||
|
||
elementScope.dismissAttachment(clickEvent, attachment);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(clickEvent.stopImmediatePropagation).toHaveBeenCalled();
|
||
});
|
||
|
||
describe(' user clicks on post button ', function () {
|
||
var directiveElem, clickEvent, runSaveNoteSuccess, keyUpEvent;
|
||
beforeEach(function () {
|
||
var error = {
|
||
data: {
|
||
detailMessage: 'Error'
|
||
}
|
||
};
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_KNOWLEDGE);
|
||
loadTemplateCache(directiveElem);
|
||
elementScope.attachments[0] = {
|
||
"pendingSave": true,
|
||
"name": "user.png",
|
||
"size": 27117,
|
||
"file": {},
|
||
"fileExt": "png"
|
||
};
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
keyUpEvent = new Event('keyup');
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content @Allen');
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
keyUpEvent.keyCode = keyCodes.enter;
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Test Content Allen Allbrook');
|
||
|
||
clickEvent = $.Event('click');
|
||
clickEvent.target = elementScope.commentFormNode.find('[type=submit]')[0];
|
||
|
||
runSaveNoteSuccess = true;
|
||
|
||
spyOn(elementScope, 'runSaveNoteHandler').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
runSaveNoteSuccess ? deferred.resolve() : deferred.reject(error);
|
||
return deferred.promise;
|
||
});
|
||
});
|
||
|
||
it('but should not do anything if it does not have any attachment or text', function () {
|
||
var result;
|
||
elementScope.attachments = [];
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('');
|
||
|
||
result = elementScope.submitNote();
|
||
elementScope.$apply();
|
||
|
||
expect(result).toBeFalsy();
|
||
});
|
||
|
||
it('and it should post the activity if it has any attachment or text and empty the textarea', function () {
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputText).toBe('');
|
||
expect(elementScope.state.noteFormIsActive).toBeFalsy();
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
expect(elementScope.state.shareWithVendor).toBeFalsy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.addFlagNote).toBeFalsy();
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('');
|
||
});
|
||
|
||
it('and it should post the activity if user replies to a flagged comment', function () {
|
||
//Article is flagged
|
||
elementScope.isFlagThread = true;
|
||
elementScope.state.isThreadUnflagged = false;
|
||
elementScope.timelineItem = {
|
||
note: {
|
||
workNoteGuid: 'IDGAA5V0HHE9CAP3YKXTP3BPZE46IM'
|
||
}
|
||
};
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputText).toBe('');
|
||
expect(elementScope.state.noteFormIsActive).toBeFalsy();
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
expect(elementScope.state.shareWithVendor).toBeFalsy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.addFlagNote).toBeFalsy();
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('');
|
||
});
|
||
|
||
it('and it should post the activity if user replies to a unflagged comment', function () {
|
||
//Article is unflagged
|
||
elementScope.isFlagThread = true;
|
||
elementScope.state.isThreadUnflagged = true;
|
||
elementScope.timelineItem = {
|
||
note: {
|
||
workNoteGuid: 'IDGAA5V0HHE9CAP3YKXTP3BPZE46IM'
|
||
}
|
||
};
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputText).toBe('');
|
||
expect(elementScope.state.noteFormIsActive).toBeFalsy();
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
expect(elementScope.state.shareWithVendor).toBeFalsy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.addFlagNote).toBeFalsy();
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('');
|
||
});
|
||
|
||
it('and it should clean up text before posting', function () {
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test<br><br><br><br>Content 1 2');
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
//Remove more than 2 line break with only 2. Replace special characters line breaks with normal \n.
|
||
expect(elementScope.noteData.noteText).toBe('Test\n\nContent 1\n2');
|
||
});
|
||
|
||
it('and it should alert an error if there is any error while posting note', function () {
|
||
spyOn(systemAlertService, 'error');
|
||
|
||
runSaveNoteSuccess = false;
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(systemAlertService.error).toHaveBeenCalled();
|
||
});
|
||
});
|
||
|
||
it('and it should post the activity if it has any attachment or text and empty the textarea and browser is IE', function () {
|
||
mockForIEBrowser();
|
||
|
||
var directiveElem = getCompiledElement(EntityVO.TYPE_KNOWLEDGE),
|
||
keyUpEvent,
|
||
clickEvent;
|
||
loadTemplateCache(directiveElem);
|
||
|
||
assetList = {
|
||
"objects": [],
|
||
"totalMatches": 0
|
||
};
|
||
|
||
keyUpEvent = new Event('keyup');
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content @Allen');
|
||
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
keyUpEvent.keyCode = keyCodes.enter;
|
||
elementScope.handleSmartInputChange(keyUpEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('Test Content Allen Allbrook ');
|
||
|
||
clickEvent = $.Event('click');
|
||
clickEvent.target = elementScope.commentFormNode.find('[type=submit]')[0];
|
||
|
||
spyOn(elementScope, 'runSaveNoteHandler').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve();
|
||
return deferred.promise;
|
||
});
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.inputText).toBe('');
|
||
expect(elementScope.state.noteFormIsActive).toBeFalsy();
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
expect(elementScope.state.shareWithVendor).toBeFalsy();
|
||
expect(elementScope.state.unflagging).toBeFalsy();
|
||
expect(elementScope.addFlagNote).toBeFalsy();
|
||
expect(elementScope.attachments.length).toBe(0);
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').text()).toBe('');
|
||
});
|
||
|
||
it('should hide draft loader if there is any error in saving draft ticket', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
elementScope.state.savingNote = true;
|
||
rootScope.$broadcast(events.HIDE_TICKET_DRAFT_LOADER);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.state.savingNote).toBeFalsy();
|
||
});
|
||
|
||
it('should watch vendor name and info model successfully and enable vendor list in ui', function () {
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
elementScope.parentContext.brokerVendorName = 'Calbro Services';
|
||
|
||
elementScope.parentContext.vendorInfo = [
|
||
{name: 'Calbro Services', selected: true},
|
||
{name: 'Petramco', selected: false}
|
||
];
|
||
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.state.isMultipleVendorTickets).toBeTruthy();
|
||
expect(elementScope.state.isVendorEnabled).toBeTruthy();
|
||
expect(elementScope.state.shareWithVendor).toBeTruthy();
|
||
});
|
||
|
||
it('should check/uncheck vendor on press of space bar', function () {
|
||
var spaceEvent = new Event('keyup');
|
||
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
|
||
elementScope.parentContext.brokerVendorName = 'Calbro Services';
|
||
|
||
elementScope.parentContext.vendorInfo = [
|
||
{name: 'Calbro Services', selected: true},
|
||
{name: 'Petramco', selected: false}
|
||
];
|
||
|
||
elementScope.$apply();
|
||
|
||
spaceEvent.keyCode = 32;
|
||
elementScope.handleKeydownOnUpdate(spaceEvent, elementScope.parentContext.vendorInfo[1]);
|
||
|
||
expect(elementScope.parentContext.vendorInfo[1]).toBeTruthy();
|
||
});
|
||
|
||
it('should post note if any vendor is selected in case of Incident', function () {
|
||
var clickEvent = $.Event('click'),
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
clickEvent.target = elementScope.commentFormNode.find('[type=submit]')[0];
|
||
|
||
elementScope.parentContext.brokerVendorName = 'Calbro Services';
|
||
|
||
elementScope.parentContext.vendorInfo = [
|
||
{name: 'Calbro Services', selected: true},
|
||
{name: 'Petramco', selected: false}
|
||
];
|
||
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content');
|
||
|
||
elementScope.$apply();
|
||
|
||
spyOn(elementScope, 'runSaveNoteHandler').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve();
|
||
return deferred.promise;
|
||
});
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').html()).toBe('');
|
||
});
|
||
|
||
it('should post note if any vendor is selected in case of change and multiple vendor', function () {
|
||
var clickEvent = $.Event('click'),
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_CHANGE);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
clickEvent.target = elementScope.commentFormNode.find('[type=submit]')[0];
|
||
|
||
elementScope.parentContext.brokerVendorName = 'Calbro Services';
|
||
|
||
elementScope.parentContext.vendorInfo = [
|
||
{name: 'Calbro Services', selected: true},
|
||
{name: 'Petramco', selected: false}
|
||
];
|
||
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content');
|
||
|
||
elementScope.$apply();
|
||
|
||
spyOn(elementScope, 'runSaveNoteHandler').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve();
|
||
return deferred.promise;
|
||
});
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').html()).toBe('');
|
||
});
|
||
|
||
it('should post note if any vendor is selected in case of change and only one vendor', function () {
|
||
var clickEvent = $.Event('click'),
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_CHANGE);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
clickEvent.target = elementScope.commentFormNode.find('[type=submit]')[0];
|
||
|
||
elementScope.parentContext.brokerVendorName = 'Calbro Services';
|
||
|
||
elementScope.parentContext.vendorInfo = [
|
||
{name: 'Calbro Services', selected: true}
|
||
];
|
||
|
||
elementScope.commentFormNode.find('.timeline-note__text').html('Test Content');
|
||
|
||
elementScope.$apply();
|
||
|
||
spyOn(elementScope, 'runSaveNoteHandler').and.callFake(function () {
|
||
let deferred = $q.defer();
|
||
deferred.resolve();
|
||
return deferred.promise;
|
||
});
|
||
|
||
elementScope.submitNote(clickEvent);
|
||
elementScope.$apply();
|
||
|
||
expect(elementScope.commentFormNode.find('.timeline-note__text').html()).toBe('');
|
||
});
|
||
|
||
it('should by default check the public checkbox in case of Service Request, it is not dependant on socialWorklogAccessSetting configuration parameter', function () {
|
||
var directiveElem;
|
||
configurationModel.socialWorklogAccessSetting = false;
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_SERVICEREQUEST);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
expect(elementScope.state.access).toBeTruthy();
|
||
});
|
||
|
||
it('should by default uncheck the public checkbox in case of knowledge, it is not dependant on socialWorklogAccessSetting configuration parameter', function () {
|
||
var directiveElem;
|
||
configurationModel.socialWorklogAccessSetting = true;
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_KNOWLEDGE);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
});
|
||
|
||
it('should by default check the public checkbox in case of Incident or ticket type other than knowledge and service request if socialWorklogAccessSetting configuration parameter is true', function () {
|
||
var directiveElem;
|
||
configurationModel.socialWorklogAccessSetting = true;
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
expect(elementScope.state.access).toBeTruthy();
|
||
});
|
||
|
||
it('should by default uncheck the public checkbox in case of Incident or ticket type other than knowledge and service request if socialWorklogAccessSetting configuration parameter is false', function () {
|
||
var directiveElem;
|
||
configurationModel.socialWorklogAccessSetting = false;
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
});
|
||
|
||
it('should by default uncheck the public checkbox in case of Incident or ticket type other than knowledge and service request if socialWorklogAccessSetting configuration parameter is not defined', function () {
|
||
var directiveElem;
|
||
configurationModel.socialWorklogAccessSetting = undefined;
|
||
directiveElem = getCompiledElement(EntityVO.TYPE_WORKORDER);
|
||
loadTemplateCache(directiveElem);
|
||
|
||
expect(elementScope.state.access).toBeFalsy();
|
||
});
|
||
});
|