431 lines
14 KiB
JavaScript
431 lines
14 KiB
JavaScript
describe('Test feed model', function () {
|
|
var $httpBackend, metadataModel, feedService, attachmentService, systemAlertService, feedModel, filterSet, seletedFilter, $q, $scope;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function ($injector, _metadataModel_, _$rootScope_, _$q_, _feedService_, _feedModel_, _attachmentService_, _systemAlertService_) {
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
$httpBackend.whenGET('scripts/app/i18n/resources-locale_en-US.json').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
|
|
metadataModel = _metadataModel_;
|
|
feedService = _feedService_;
|
|
feedModel = _feedModel_;
|
|
attachmentService = _attachmentService_;
|
|
systemAlertService = _systemAlertService_;
|
|
$q = _$q_;
|
|
$scope = _$rootScope_.$new();
|
|
}));
|
|
|
|
beforeEach(function () {
|
|
filterSet = [
|
|
{
|
|
"name": "approval",
|
|
"label": "approvalStatusUpdates",
|
|
"type": "showActivityTypes",
|
|
"criteria": [
|
|
{
|
|
"name": "eventType",
|
|
"value": [
|
|
"approval-accept-event",
|
|
"approval-hold-event",
|
|
"approval-reject-event"
|
|
]
|
|
},
|
|
{
|
|
"name": "filterType",
|
|
"value": [
|
|
"system"
|
|
]
|
|
}
|
|
],
|
|
"display": "hasKnowledgeOrChangePermission",
|
|
"localizedLabel": "Approval Status Updates",
|
|
"selected": false
|
|
},
|
|
{
|
|
"name": "ownershipChanges",
|
|
"label": "ownershipUpdates",
|
|
"type": "showActivityTypes",
|
|
"criteria": [
|
|
{
|
|
"name": "eventType",
|
|
"value": [
|
|
"ownership-change"
|
|
]
|
|
},
|
|
{
|
|
"name": "filterType",
|
|
"value": [
|
|
"system"
|
|
]
|
|
}
|
|
],
|
|
"localizedLabel": "Asset Ownership Updates",
|
|
"selected": false
|
|
}
|
|
];
|
|
|
|
seletedFilter = {
|
|
"filters": {
|
|
"eventType": [
|
|
"approval-accept-event",
|
|
"approval-hold-event",
|
|
"approval-reject-event",
|
|
"ownership-change"
|
|
],
|
|
"filterType": [
|
|
"system"
|
|
]
|
|
},
|
|
"params": {
|
|
"followCount": true,
|
|
"limit": 20,
|
|
"poiId": null
|
|
}
|
|
};
|
|
});
|
|
|
|
it('should be defined', function () {
|
|
expect(feedModel).toBeDefined();
|
|
expect(feedModel.activityFeed.params.limit).toBe(20);
|
|
expect(feedModel.updateFeed.params.limit).toBe(20);
|
|
expect(feedModel.pendingWorkNote).toBe(null);
|
|
});
|
|
|
|
it('should fetch update feeds if user selects some filters and click on apply button', function () {
|
|
var result;
|
|
filterSet[0].selected = true;
|
|
feedModel.buildFeedFilter(seletedFilter, filterSet);
|
|
result = feedModel.getUpdateFeedItems({});
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should fetch all the update feeds if user clicks on Select All button', function () {
|
|
var result;
|
|
filterSet[0].selected = true;
|
|
filterSet[1].selected = true;
|
|
feedModel.buildFeedFilter(seletedFilter, filterSet);
|
|
result = feedModel.getUpdateFeedItems({});
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should fetch all the activity feeds if no activity is selected', function () {
|
|
var result,
|
|
entity = {
|
|
"type": "incident",
|
|
"id": "AGGAA5V0HHE9CAP35YRTP29DTESR49",
|
|
"poiId": null
|
|
},
|
|
criteria = {};
|
|
result = feedModel.getActivityFeedItems(entity, criteria);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should fetch all the activity feeds if some activity is selected', function () {
|
|
var result,
|
|
entity = {
|
|
"type": "asset",
|
|
"id": "REHAA5V0GQBORANBA19A831T72G67V",
|
|
"poiId": 'test'
|
|
},
|
|
criteria = {};
|
|
|
|
feedModel.activityFeed.filters = {
|
|
"eventType": [
|
|
"asset-reboot",
|
|
"asset-wakeup"
|
|
],
|
|
"filterType": [
|
|
"system"
|
|
]
|
|
};
|
|
result = feedModel.getActivityFeedItems(entity, criteria);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should save note successfully if user flag the knowledge article and click on post', function () {
|
|
var entity = {
|
|
"type": "knowledge",
|
|
"id": "AGGAA5V0HHE9CAP3AV84P2EA9P61K5",
|
|
"poiId": null
|
|
},
|
|
note = {
|
|
"noteText": "Notes",
|
|
"addFlagNote": true,
|
|
"flag": true
|
|
};
|
|
|
|
spyOn(feedService, 'addActivityFeedWorknoteWithFlag');
|
|
feedModel.saveNote(entity, note);
|
|
expect(feedService.addActivityFeedWorknoteWithFlag).toHaveBeenCalledWith(entity, { flagNote: 'Notes', flagged: true });
|
|
});
|
|
|
|
it('should save note successfully without attachment', function () {
|
|
var entity = {
|
|
"type": "knowledge",
|
|
"id": "AGGAA5V0HHE9CAP3AV84P2EA9P61K5",
|
|
"poiId": null
|
|
},
|
|
note = {
|
|
"noteText": "Notes"
|
|
},
|
|
res = [
|
|
{
|
|
items: [
|
|
{
|
|
statusInfo: {
|
|
message: 'Records Updated Successfully'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
];
|
|
spyOn(feedService, 'addActivityFeedWorknote').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.resolve(res);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(systemAlertService, 'success');
|
|
feedModel.saveNote(entity, note);
|
|
note.articleId = 'AGGAA5V0HHE9CAP3AV84P2EA9P61K5';
|
|
note.attachmentType = 'pdf';
|
|
$scope.$apply();
|
|
expect(feedService.addActivityFeedWorknote).toHaveBeenCalledWith(entity, { worknote: 'Notes', access: undefined, workInfoType: undefined });
|
|
expect(systemAlertService.success).toHaveBeenCalledWith({
|
|
text: res[0].items[0].statusInfo.message,
|
|
clear: true,
|
|
hide: 10000
|
|
});
|
|
});
|
|
|
|
it('should save note successfully with attachments', function () {
|
|
var result,
|
|
entity = {
|
|
"type": "knowledge",
|
|
"id": "AGGAA5V0HHE9CAP3AV84P2EA9P61K5",
|
|
"poiId": null
|
|
},
|
|
note = {
|
|
"noteText": "Notes",
|
|
"attachments": [
|
|
{
|
|
"name": "user.png",
|
|
"fileExt": "png",
|
|
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eN"
|
|
}
|
|
]
|
|
};
|
|
|
|
spyOn(feedService, 'addActivityFeedWorknote');
|
|
|
|
result = feedModel.saveNote(entity, note);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should alert an error if there is any error while saving note with attachments', function () {
|
|
var entity = {
|
|
"type": "knowledge",
|
|
"id": "AGGAA5V0HHE9CAP3AV84P2EA9P61K5",
|
|
"poiId": null
|
|
},
|
|
note = {
|
|
"noteText": "Notes",
|
|
"attachments": [
|
|
{
|
|
"name": "user.png",
|
|
"fileExt": "png",
|
|
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eN"
|
|
}
|
|
]
|
|
},
|
|
error = {
|
|
data: {
|
|
defaultMessage: 'Not saved'
|
|
}
|
|
};
|
|
|
|
spyOn(attachmentService, 'addWorknoteWithAttachment').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.reject(error);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(systemAlertService, 'error');
|
|
|
|
feedModel.saveNote(entity, note);
|
|
|
|
$scope.$apply();
|
|
|
|
expect(systemAlertService.error).toHaveBeenCalledWith({
|
|
text: error.data.defaultMessage,
|
|
clear: false
|
|
});
|
|
});
|
|
|
|
it('should add activity feed work note in bulk having no attachments', function () {
|
|
var request = {
|
|
"type": "incident",
|
|
"id": "IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C",
|
|
"poiId": null,
|
|
"ticketList": [{
|
|
workNoteType: 'test'
|
|
}]
|
|
}, result;
|
|
|
|
result = feedModel.saveNoteBulk(request);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should add activity feed work note in bulk having attachments', function () {
|
|
var request = {
|
|
"type": "incident",
|
|
"id": "IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C",
|
|
"poiId": null,
|
|
"ticketList": [{
|
|
workNoteType: 'test'
|
|
}],
|
|
"attachments": [
|
|
{
|
|
"name": "user.png",
|
|
"fileExt": "png",
|
|
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eN"
|
|
}
|
|
]
|
|
}, result;
|
|
|
|
result = feedModel.saveNoteBulk(request);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should successfully unpinned feed item', function () {
|
|
var unPinnedFeedObj = {
|
|
"type": "system",
|
|
"id": "000000000000152"
|
|
}, result;
|
|
|
|
result = feedModel.unpinFeedItem(unPinnedFeedObj);
|
|
expect(result.$$state.status).toEqual(0);
|
|
});
|
|
|
|
it('should alert an error if user encounters any error while unpinning feed item', function () {
|
|
var unPinnedFeedObj = {
|
|
"type": "system",
|
|
"id": "000000000000152"
|
|
};
|
|
|
|
spyOn(feedService, 'unpinFeedItem').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.reject();
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(systemAlertService, 'error');
|
|
|
|
feedModel.unpinFeedItem(unPinnedFeedObj);
|
|
|
|
$scope.$apply();
|
|
|
|
expect(systemAlertService.error).toHaveBeenCalledWith({
|
|
text: 'feed.unpin.error',
|
|
clear: false
|
|
});
|
|
});
|
|
|
|
it('should fetch work info type filters and should return the same if the value is available', function () {
|
|
var metadata = {
|
|
"workinfoTypes": [
|
|
{
|
|
"type": "option",
|
|
"index": 1000,
|
|
"name": "Technical Update",
|
|
"label": "Technical Update"
|
|
},
|
|
{
|
|
"type": "option",
|
|
"index": 2000,
|
|
"name": "Enhancement",
|
|
"label": "Enhancement"
|
|
}
|
|
]
|
|
}, result;
|
|
|
|
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
|
|
feedModel.getWorkinfoTypeFilters('knowledge');
|
|
|
|
$scope.$apply();
|
|
|
|
expect(feedModel.workinfoTypeFilters['knowledge'][0].name).toBe('Technical Update');
|
|
|
|
result = feedModel.getWorkinfoTypeFilters('knowledge');
|
|
|
|
expect(result.$$state.status).toEqual(1);
|
|
expect(feedModel.workinfoTypeFilters['knowledge'][0].name).toBe('Technical Update');
|
|
});
|
|
|
|
it('should successfully save pending work note while submitting draft incident', function () {
|
|
var ticket = {
|
|
type: "incident",
|
|
id: "IDGAA5V0HHE9CAP360FCP295G3TCBC",
|
|
pendingWorkNote: {
|
|
"noteText": "Test\n",
|
|
"attachments": [],
|
|
"access": true,
|
|
"workInfoType": 8000
|
|
}
|
|
};
|
|
|
|
feedModel.pendingWorkNote = true;
|
|
|
|
spyOn(feedModel, 'saveNote').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.resolve();
|
|
return deferred.promise;
|
|
});
|
|
|
|
feedModel.processPendingWorkNote(ticket);
|
|
$scope.$apply();
|
|
expect(feedModel.pendingWorkNote).toBe(null);
|
|
});
|
|
|
|
it('should alert an error if there is an error while saving pending work note on submitting draft incident', function () {
|
|
var ticket = {
|
|
type: "incident",
|
|
id: "IDGAA5V0HHE9CAP360FCP295G3TCBC",
|
|
pendingWorkNote: {
|
|
"noteText": "Test\n",
|
|
"attachments": [],
|
|
"access": true,
|
|
"workInfoType": 8000
|
|
}
|
|
}, pendingWorkNoteError = {
|
|
data: {
|
|
error: 'Not Saved'
|
|
}
|
|
};
|
|
|
|
feedModel.pendingWorkNote = true;
|
|
|
|
spyOn(feedModel, 'saveNote').and.callFake(function () {
|
|
var deferred = $q.defer();
|
|
deferred.reject(pendingWorkNoteError);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(systemAlertService, 'error');
|
|
|
|
feedModel.processPendingWorkNote(ticket);
|
|
$scope.$apply();
|
|
|
|
expect(systemAlertService.error).toHaveBeenCalledWith({
|
|
text: pendingWorkNoteError.data.error,
|
|
clear: false
|
|
});
|
|
});
|
|
}); |