443 lines
16 KiB
JavaScript
443 lines
16 KiB
JavaScript
/**
|
|
* Created by mkumar1 on 28-03-2018.
|
|
*/
|
|
|
|
describe('test UpdateFeedController', function () {
|
|
|
|
'use strict';
|
|
|
|
var $httpBackend, deferred;
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(function () {
|
|
var metadataMockModel = {
|
|
cache: {
|
|
global: {
|
|
configurationParameters: {
|
|
feedRefreshInterval: 6
|
|
}
|
|
}
|
|
}
|
|
};
|
|
module(function ($provide) {
|
|
$provide.value('metadataModel', metadataMockModel);
|
|
});
|
|
});
|
|
|
|
beforeEach(inject(function ($injector, $rootScope, $controller, $q, i18nService, $timeout, feedModel, $filter, authService, roles, attachmentService, configurationModel, events) {
|
|
this.scope = $rootScope.$new();
|
|
this.controller = $controller;
|
|
this.$q = $q;
|
|
this.i18nService = i18nService;
|
|
this.$timeout = $timeout;
|
|
this.feedModel = feedModel;
|
|
this.$filter = $filter;
|
|
this.authService = authService;
|
|
this.roles = roles;
|
|
this.attachmentService = attachmentService;
|
|
this.configurationModel = configurationModel;
|
|
this.events = events;
|
|
deferred = $q.defer();
|
|
|
|
this.controllerInstance = this.controller('UpdateFeedController', {
|
|
$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/v2/following/stream?followCount=true&limit=20').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/v2/following/stream?criteria=gt,&followCount=true&limit=20').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/v2/following/stream?eventType=approval-accept-event,approval-hold-event,approval-reject-event&filterType=system&followCount=true&limit=20').respond(200);
|
|
$httpBackend.whenPOST('/smartit/rest/subscription/unpin/system').respond([]);
|
|
}));
|
|
|
|
beforeEach(function () {
|
|
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('follow count setup', function () {
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve('success');
|
|
return deferred.promise;
|
|
});
|
|
expect(this.scope.followCount).toBeNull();
|
|
this.feedModel.getUpdateFeedItems();
|
|
expect(this.scope.state.loadingFeeds).toBeTruthy();
|
|
});
|
|
|
|
it('should refresh the knowledge title multiline ellipsis if there is new updates found', function () {
|
|
var data = {
|
|
items: [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "knowledge",
|
|
"title": "Title",
|
|
"id": "AGGAA5V0HG8PDAP1NE0NP0Q0TURAD1"
|
|
},
|
|
"id": "000000000000039"
|
|
}
|
|
]
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve('success');
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, '$broadcast').and.callThrough();
|
|
spyOn(this.attachmentService, 'getAttachmentFile').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.handleAttachmentClick();
|
|
this.scope.$apply();
|
|
this.scope.getNewUpdateFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.$broadcast).toHaveBeenCalledWith(this.events.ELLIPSIS_EVENT);
|
|
});
|
|
|
|
it('should update the filters and revert all the filter selection changes while closing dropdown', function () {
|
|
expect(this.scope.filters[0].selected).toBeFalsy();
|
|
expect(this.scope.pendingFilterUpdate).toBeFalsy();
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
expect(this.scope.filters[0].selected).toBeTruthy();
|
|
expect(this.scope.pendingFilterUpdate).toBeTruthy();
|
|
|
|
this.scope.applyFilter();
|
|
expect(this.scope.pendingFilterUpdate).toBeFalsy();
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
expect(this.scope.filters[0].selected).toBeFalsy();
|
|
expect(this.scope.pendingFilterUpdate).toBeTruthy();
|
|
this.scope.filterMenuToggled(false);
|
|
this.scope.$apply();
|
|
expect(this.scope.pendingFilterUpdate).toBeFalsy();
|
|
expect(this.scope.filters[0].selected).toBeTruthy();
|
|
});
|
|
|
|
it('should fetch records as per selected filters on click of apply filters', function () {
|
|
var feedItems = {
|
|
"items": [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "change",
|
|
"title": "Title Updated"
|
|
}
|
|
}
|
|
],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.configurationModel, 'isServerApplicationEnabled').and.returnValue(true);
|
|
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
this.scope.applyFilter();
|
|
this.scope.$apply();
|
|
|
|
expect(this.scope.followCount).toBe(7);
|
|
expect(this.scope.feed[0].relatedObject.title).toBe('Title Updated');
|
|
});
|
|
|
|
it('should fetch person records on click of apply filters', function () {
|
|
var feedItems = {
|
|
"items": [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title Updated"
|
|
}
|
|
}
|
|
],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
this.scope.applyFilter();
|
|
this.scope.$apply();
|
|
|
|
expect(this.scope.followCount).toBe(7);
|
|
expect(this.scope.feed[0].relatedObject.title).toBe('Title Updated');
|
|
});
|
|
|
|
it('should set allFeedsLoaded to true if feedItems is empty on click of apply filters', function () {
|
|
var feedItems = {
|
|
"items": [],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
this.scope.applyFilter();
|
|
this.scope.$apply();
|
|
|
|
expect(this.scope.state.allFeedsLoaded).toBeTruthy();
|
|
});
|
|
|
|
it('should update list with new records if there is new updates found', function () {
|
|
var data = {
|
|
items: [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title",
|
|
"id": "AGGAA5V0HG8PDAP1NE0NP0Q0TURAD1"
|
|
},
|
|
"id": "000000000000039"
|
|
}
|
|
]
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve('success');
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, '$broadcast');
|
|
spyOn(this.attachmentService, 'getAttachmentFile').and.callFake(function () {
|
|
deferred.resolve(data);
|
|
return deferred.promise;
|
|
});
|
|
this.scope.handleAttachmentClick();
|
|
this.scope.$apply();
|
|
this.scope.getNewUpdateFeedItems();
|
|
this.scope.$apply();
|
|
expect(this.scope.$broadcast).toHaveBeenCalledWith(this.events.ELLIPSIS_EVENT);
|
|
expect(this.scope.feed.length).toBe(1);
|
|
});
|
|
|
|
it('should load more feeds on lazy loading', function () {
|
|
var feedItems = {
|
|
"items": [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title Updated"
|
|
}
|
|
}
|
|
],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, '$broadcast');
|
|
this.scope.state.loadingFeeds = false;
|
|
this.scope.state.loadingMoreFeeds = false;
|
|
this.scope.state.allFeedsLoaded = false;
|
|
this.scope.loadMoreFeeds();
|
|
expect(this.scope.state.loadingMoreFeeds).toBeTruthy();
|
|
this.scope.$apply();
|
|
expect(this.scope.$broadcast).toHaveBeenCalledWith(this.events.ELLIPSIS_EVENT);
|
|
expect(this.scope.feed.length).toBe(1);
|
|
expect(this.scope.state.loadingMoreFeeds).toBeFalsy();
|
|
});
|
|
|
|
it('should toggle the state of filter on enter key press of that filter item', function () {
|
|
expect(this.scope.filters[0].selected).toBeFalsy();
|
|
var keyPressEvent = new Event('keypress');
|
|
keyPressEvent.keyCode = 32;
|
|
this.scope.keyPressOnFilterItem(keyPressEvent, this.scope.filters[0]);
|
|
this.scope.$apply();
|
|
expect(this.scope.filters[0].selected).toBeTruthy();
|
|
});
|
|
|
|
it('should successfully watch searchQuery model if there is any value', function () {
|
|
spyOn(this.feedModel, 'getUpdateFeedItems');
|
|
this.feedModel.updateFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.$timeout(function() {
|
|
expect(this.feedModel.getUpdateFeedItems).toHaveBeenCalled();
|
|
}, 1500);
|
|
});
|
|
|
|
it('should successfully watch searchQuery model if there is no value and fetch records accordingly', function () {
|
|
var feedItems = {
|
|
"items": [
|
|
{
|
|
"type": "system",
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title Updated"
|
|
}
|
|
}
|
|
],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.scope, '$broadcast');
|
|
this.feedModel.updateFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.feedModel.updateFeed.params.searchQuery = '';
|
|
this.scope.$apply();
|
|
expect(this.scope.$broadcast).toHaveBeenCalledWith(this.events.ELLIPSIS_EVENT);
|
|
expect(this.scope.feed.length).toBe(1);
|
|
});
|
|
|
|
it('should clear the search value on click of cross button', function () {
|
|
this.feedModel.updateFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.scope.clearSearchText();
|
|
expect(this.feedModel.updateFeed.params.searchQuery).toBe('');
|
|
this.scope.$apply();
|
|
expect(this.feedModel.updateFeed.params.searchQuery).toBeUndefined();
|
|
});
|
|
|
|
it('should successfully call $destroy if scope is getting destroyed', function () {
|
|
this.feedModel.updateFeed.params.searchQuery = 'test';
|
|
this.scope.$apply();
|
|
this.scope.$destroy();
|
|
this.scope.$apply();
|
|
expect(this.feedModel.updateFeed.params.searchQuery).toBe('');
|
|
});
|
|
|
|
it('should successfully unpinned item and update the order on click of pin icon', function () {
|
|
var feedItems = {
|
|
"items": [
|
|
{
|
|
"type": "system",
|
|
"priority": 2,
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title Updated"
|
|
},
|
|
"createDate": 1533632191000,
|
|
"id": "000000000000152"
|
|
},
|
|
{
|
|
"type": "system",
|
|
"priority": 0,
|
|
"relatedObject": {
|
|
"type": "change",
|
|
"title": "Change"
|
|
},
|
|
"createDate": 1533632291001,
|
|
"id": "000000000000153"
|
|
},
|
|
{
|
|
"type": "system",
|
|
"priority": 0,
|
|
"relatedObject": {
|
|
"type": "change",
|
|
"title": "Change"
|
|
},
|
|
"createDate": 1033632190001,
|
|
"id": "000000000000154"
|
|
}
|
|
],
|
|
"followCount": 7,
|
|
"syncTime": 0
|
|
}, unPinnedFeedObj = {
|
|
"type": "system",
|
|
"priority": 2,
|
|
"relatedObject": {
|
|
"type": "person",
|
|
"title": "Title Updated"
|
|
},
|
|
"createDate": 1533632191002,
|
|
"id": "000000000000152"
|
|
};
|
|
spyOn(this.feedModel, 'getUpdateFeedItems').and.callFake(function () {
|
|
deferred.resolve(feedItems);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.feedModel, 'unpinFeedItem').and.callFake(function () {
|
|
deferred.resolve([]);
|
|
return deferred.promise;
|
|
});
|
|
|
|
this.scope.updateFilters(new Event('click'), this.scope.filters[0]);
|
|
this.scope.applyFilter();
|
|
this.scope.$apply();
|
|
|
|
this.scope.handleUnpinClick(unPinnedFeedObj);
|
|
this.scope.$apply();
|
|
expect(unPinnedFeedObj.priority).toBe(0);
|
|
expect(this.feedModel.unpinFeedItem).toHaveBeenCalled();
|
|
expect(this.scope.feed[0].priority).toBe(0);
|
|
expect(this.scope.feed[0].id).toBe('000000000000153');
|
|
});
|
|
}); |