443 lines
17 KiB
JavaScript
443 lines
17 KiB
JavaScript
describe('test ActivityFeedController', function () {
|
|
|
|
'use strict';
|
|
|
|
var $httpBackend, feedItems;
|
|
beforeEach(module('myitsmApp'));
|
|
|
|
beforeEach(inject(function ($injector, $rootScope, $controller, $q, i18nService, $timeout, feedModel, $filter, metadataModel, authService, roles, events, attachmentService) {
|
|
this.rootScope = $rootScope;
|
|
this.scope = $rootScope.$new();
|
|
this.controller = $controller;
|
|
this.$q = $q;
|
|
this.i18nService = i18nService;
|
|
this.$timeout = $timeout;
|
|
this.feedModel = feedModel;
|
|
this.$filter = $filter;
|
|
this.metadataModel = metadataModel;
|
|
this.authService = authService;
|
|
this.roles = roles;
|
|
this.events = events;
|
|
this.attachmentService = attachmentService;
|
|
this.scope.type = 'person';
|
|
this.controllerInstance = this.controller('ActivityFeedController', {
|
|
$scope: this.scope
|
|
});
|
|
}));
|
|
|
|
beforeEach(inject(function ($injector) {
|
|
$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?type=global').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);
|
|
$httpBackend.whenGET('/smartit/rest/timeline/person/IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C?limit=20').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=asset').respond(200);
|
|
}));
|
|
|
|
beforeEach(function () {
|
|
feedItems = [
|
|
{
|
|
"type": "system",
|
|
"priority": 2,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "",
|
|
"id": ""
|
|
},
|
|
"id": "000000000000152",
|
|
"createDate": 1533632191000
|
|
},
|
|
{
|
|
"type": "system",
|
|
"priority": 0,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "INC1004",
|
|
"id": "IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C"
|
|
},
|
|
"id": "AGGAA5V0HG8PDAP3DCH7P2GGXVCIZX",
|
|
"createDate": 1533632236000
|
|
},
|
|
{
|
|
"type": "system",
|
|
"priority": 0,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "INC1004",
|
|
"id": "IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C"
|
|
},
|
|
"id": "AGGAA5V0HG8PDAP3DCCRP2GGTECIPQ",
|
|
"createDate": 1533632066000
|
|
},
|
|
{
|
|
"type": "system",
|
|
"priority": 0,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "",
|
|
"id": ""
|
|
},
|
|
"id": "000000000000149",
|
|
"createDate": 1533632044000
|
|
}
|
|
];
|
|
this.scope.parentContext = {
|
|
type: 'incident'
|
|
};
|
|
|
|
this.scope.filters = [
|
|
{
|
|
"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",
|
|
"$$hashKey": "object:21",
|
|
"selected": false
|
|
},
|
|
{
|
|
"name": "ownershipChanges",
|
|
"label": "ownershipUpdates",
|
|
"type": "showActivityTypes",
|
|
"criteria": [
|
|
{
|
|
"name": "eventType",
|
|
"value": [
|
|
"ownership-change"
|
|
]
|
|
},
|
|
{
|
|
"name": "filterType",
|
|
"value": [
|
|
"system"
|
|
]
|
|
}
|
|
],
|
|
"localizedLabel": "Asset Ownership Updates",
|
|
"$$hashKey": "object:22",
|
|
"selected": false
|
|
}
|
|
];
|
|
});
|
|
|
|
it('should be defined', function () {
|
|
expect(this.controllerInstance).toBeDefined();
|
|
this.scope.$apply();
|
|
});
|
|
|
|
it('should cancel the earlier call to getActivityFeedItems', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function(){
|
|
deferred.resolve({ isNotAuthorized: true });
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope.getActivityFeedItemsDebounced, 'cancel');
|
|
this.scope.getActivityFeedItems();
|
|
expect(this.scope.getActivityFeedItemsDebounced.cancel).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fetch all activity feeds on refresh', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
expect(this.scope.feed.length).toBe(0);
|
|
expect(this.scope.parentContext.feed).toBeUndefined();
|
|
this.rootScope.$broadcast(this.events.REFRESH_ACTIVITY_FEED);
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(4);
|
|
expect(this.scope.parentContext.feed.length).toBe(4);
|
|
});
|
|
|
|
it('should set allFeedsLoaded to true if there is no records', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve([]);
|
|
return deferred.promise;
|
|
});
|
|
expect(this.scope.state.allFeedsLoaded).toBeFalsy();
|
|
this.rootScope.$broadcast(this.events.REFRESH_ACTIVITY_FEED);
|
|
this.scope.$apply();
|
|
expect(this.scope.state.allFeedsLoaded).toBeTruthy();
|
|
});
|
|
|
|
it('should show Not Authorized error if isNotAuthorized is true', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve({ isNotAuthorized: true });
|
|
return deferred.promise;
|
|
});
|
|
this.scope.getActivityFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.state.isNotAuthorized).toBeTruthy();
|
|
});
|
|
|
|
it('should show Not Authorized error if isNotAuthorized is true', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve({ isNotAuthorized: true });
|
|
return deferred.promise;
|
|
});
|
|
this.scope.getActivityFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.state.isNotAuthorized).toBeTruthy();
|
|
});
|
|
|
|
it('should load new activity feed and insert at the starting of the feeds', function () {
|
|
var _this = this,
|
|
isNewActivityFeed = false,
|
|
newFeeds = [
|
|
{
|
|
"type": "system",
|
|
"priority": 3,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "New Feeds",
|
|
"id": ""
|
|
},
|
|
"id": "000000000000150",
|
|
"createDate": 1533632191444
|
|
}
|
|
];
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
var deferred = _this.$q.defer(),
|
|
feeds = isNewActivityFeed ? newFeeds : feedItems;
|
|
deferred.resolve(feeds);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.getActivityFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(4);
|
|
isNewActivityFeed = true;
|
|
this.scope.getNewActivityFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(5);
|
|
expect(this.scope.feed[0].relatedObject.title).toBe('New Feeds');
|
|
});
|
|
|
|
it('should load more feeds when user scroll down to the end of the feeds', function () {
|
|
var _this = this,
|
|
loadMoreActivityFeed = false,
|
|
newFeeds = [
|
|
{
|
|
"type": "system",
|
|
"priority": 3,
|
|
"relatedObject": {
|
|
"type": "incident",
|
|
"title": "New Feeds",
|
|
"id": ""
|
|
},
|
|
"id": "000000000000150",
|
|
"createDate": 1533632191444
|
|
}
|
|
];
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
var deferred = _this.$q.defer(),
|
|
feeds = loadMoreActivityFeed ? newFeeds : feedItems;
|
|
deferred.resolve(feeds);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.getActivityFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(4);
|
|
loadMoreActivityFeed = true;
|
|
this.scope.loadMoreFeeds();
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(5);
|
|
expect(this.scope.feed[4].relatedObject.title).toBe('New Feeds');
|
|
});
|
|
|
|
it('should download the attachment on click of attachment icon', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.attachmentService, 'getAttachmentFile').and.callFake(function () {
|
|
deferred.resolve([]);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.handleAttachmentClick('incident', {name: 'test.png'}, false, false);
|
|
this.scope.$apply();
|
|
expect(this.scope.state.loadingFeeds).toBeFalsy();
|
|
expect(this.attachmentService.getAttachmentFile).toHaveBeenCalledWith('incident', {name: 'test.png'}, false, false);
|
|
});
|
|
|
|
it('should toggle and apply filter on enter key press of that filter item', function () {
|
|
var keyPressEvent = new Event('keypress'),
|
|
deferred = this.$q.defer();
|
|
expect(this.scope.filters[0].selected).toBeFalsy();
|
|
keyPressEvent.keyCode = 32;
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.keyPressOnFilterItem(keyPressEvent, this.scope.filters[0]);
|
|
this.scope.$apply();
|
|
expect(this.scope.filters[0].selected).toBeTruthy();
|
|
expect(this.scope.filters.length).toBe(2);
|
|
});
|
|
|
|
it('should toggle and apply filter on click of filter item', function () {
|
|
var deferred = this.$q.defer();
|
|
expect(this.scope.filters[0].selected).toBeFalsy();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.applyFilter(this.scope.filters[0]);
|
|
this.scope.$apply();
|
|
expect(this.scope.filters[0].selected).toBeTruthy();
|
|
expect(this.scope.filters.length).toBe(2);
|
|
});
|
|
|
|
it('should successfully watch searchQuery model if there is any value', function () {
|
|
spyOn(this.scope, 'getActivityFeedItemsDebounced');
|
|
this.feedModel.activityFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
expect(this.scope.getActivityFeedItemsDebounced).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should successfully watch searchQuery model if there is no value and fetch records accordingly', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, 'getActivityFeedItemsDebounced');
|
|
this.feedModel.activityFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.feedModel.activityFeed.params.searchQuery = '';
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(4);
|
|
});
|
|
|
|
it('should clear the search value on click of cross button', function () {
|
|
var deferred = this.$q.defer();
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, 'getActivityFeedItemsDebounced');
|
|
this.feedModel.activityFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.scope.clearSearchText();
|
|
this.scope.$apply();
|
|
expect(this.feedModel.activityFeed.params.searchQuery).toBe('');
|
|
});
|
|
|
|
it('should successfully call $destroy if scope is getting destroyed', function () {
|
|
spyOn(this.scope, 'getActivityFeedItemsDebounced');
|
|
this.feedModel.activityFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.scope.$destroy();
|
|
this.scope.$apply();
|
|
expect(this.feedModel.activityFeed.params.searchQuery).toBe('');
|
|
});
|
|
|
|
it('should save note on click of Post button and refresh ticket in case of flag note', function () {
|
|
var noteData = {
|
|
"noteText": "test",
|
|
"attachments": [],
|
|
"access": true,
|
|
"workInfoType": 8000,
|
|
"addFlagNote": true
|
|
}, _this = this;
|
|
|
|
spyOn(this.feedModel, 'saveNote').and.callFake(function () {
|
|
var deferred = _this.$q.defer();
|
|
deferred.resolve(true);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
var deferred = _this.$q.defer();
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, '$emit');
|
|
|
|
this.scope.saveNote(noteData);
|
|
expect(this.scope.state.savingNote).toBeTruthy();
|
|
this.scope.$apply();
|
|
expect(this.scope.feed.length).toBe(4);
|
|
expect(this.scope.state.savingNote).toBeFalsy();
|
|
expect(this.scope.$emit).toHaveBeenCalledWith(this.events.TICKET_PROFILE_RESEND_EVENT, { eventName: this.events.REFRESH_KNOWLEDGE_ARTICLE });
|
|
});
|
|
|
|
it('should return true if context info needs to be shown', function () {
|
|
this.scope.itemId = 'IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C';
|
|
var result = this.scope.showContext(feedItems[0]);
|
|
this.scope.$apply();
|
|
expect(result).toBeTruthy();
|
|
});
|
|
|
|
it('should successfully watch itemId and update the workinfoTypefilter accordingly and apply filter in case of POI assetClassId', function () {
|
|
var _this = this;
|
|
spyOn(this.feedModel, 'getWorkinfoTypeFilters').and.callFake(function () {
|
|
var deferred = _this.$q.defer();
|
|
deferred.resolve(_this.scope.filters);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
var deferred = _this.$q.defer();
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
expect(this.scope.state.filterReady).toBeFalsy();
|
|
this.scope.itemId = 'IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C';
|
|
this.scope.assetClassId = 'POI';
|
|
this.scope.$apply();
|
|
expect(this.scope.workinfoTypeFilters.length).toBe(this.scope.filters.length);
|
|
expect(this.scope.state.filterReady).toBeTruthy();
|
|
expect(this.feedModel.getActivityFeedItems).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should successfully watch assetObject and apply filter in case of assets', function () {
|
|
var _this = this;
|
|
spyOn(this.feedModel, 'getActivityFeedItems').and.callFake(function () {
|
|
var deferred = _this.$q.defer();
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.itemId = 'IDGAA5V0HG8PDAP3DCBOP2GGSCCI8C';
|
|
this.scope.type = 'asset';
|
|
this.scope.$apply();
|
|
|
|
this.scope.assetObject = {
|
|
ticketType: 'asset',
|
|
type: 'Computer System'
|
|
};
|
|
|
|
this.scope.$apply();
|
|
|
|
expect(this.feedModel.getActivityFeedItems).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should successfully watch personDetails and update the parentContext in case of type person', function () {
|
|
this.scope.personModel.personDetails = {
|
|
firstName: 'Allen'
|
|
};
|
|
this.scope.$apply();
|
|
expect(this.scope.parentContext.firstName).toBe('Allen');
|
|
});
|
|
}); |