100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
/**
|
|
* Created by ohnatkov on 10-23-2017.
|
|
*/
|
|
describe('Chat assign suggestion directive', function () {
|
|
var scope,
|
|
compile,
|
|
chatModelMock,
|
|
person = {
|
|
firstName: 'Test',
|
|
lastName: 'Person',
|
|
loginId: 'id',
|
|
jid: 'test@server'
|
|
},
|
|
asset = {
|
|
category: 'asset',
|
|
additionalInformation: {status: {value: 'Online'}}
|
|
};
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
module(function ($provide) {
|
|
$provide.value('chatModel', {
|
|
cachedProfiles: [person],
|
|
generateUserJID: function (id) {
|
|
return 'j' + id + '@server'
|
|
},
|
|
checkUserAvailability: function (jid) {
|
|
this.cachedProfiles[jid] = person;
|
|
this.cachedProfiles[jid].available = true;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
beforeEach(inject(function ($rootScope, $compile, $httpBackend, chatModel) {
|
|
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(readJSON('scripts/app/i18n/resources-locale_en.json'));
|
|
scope = $rootScope.$new();
|
|
compile = $compile;
|
|
chatModelMock = chatModel;
|
|
chatModelMock.cachedProfiles = {};
|
|
}));
|
|
|
|
it('should compile', function () {
|
|
var elem = angular.element('<chat-assign-suggestion></chat-assign-suggestion>');
|
|
var compiledElement = compile(elem)(scope);
|
|
|
|
scope.item = person;
|
|
scope.searchBar = {};
|
|
chatModelMock.cachedProfiles[person.jid] = person;
|
|
scope.$digest();
|
|
|
|
expect(compiledElement).toBeDefined();
|
|
});
|
|
|
|
it('should generate user jid and check availability', function () {
|
|
var elem = angular.element('<chat-assign-suggestion></chat-assign-suggestion>');
|
|
compile(elem)(scope);
|
|
|
|
var personCopy = angular.copy(person);
|
|
personCopy.available = true;
|
|
delete personCopy.jid;
|
|
|
|
spyOn(chatModelMock, 'generateUserJID').and.callThrough();
|
|
spyOn(chatModelMock, 'checkUserAvailability').and.callThrough();
|
|
|
|
|
|
scope.item = person;
|
|
scope.searchBar = {selectedSuggestionIndex: 1};
|
|
chatModelMock.cachedProfiles = {'jid': personCopy};
|
|
scope.$digest();
|
|
|
|
expect(chatModelMock.generateUserJID).toHaveBeenCalled();
|
|
expect(chatModelMock.checkUserAvailability).toHaveBeenCalled();
|
|
expect(scope.item.available).toBe(true);
|
|
});
|
|
|
|
it('should generate additional properties when asset or template is an item', function () {
|
|
var elem = angular.element('<chat-assign-suggestion></chat-assign-suggestion>');
|
|
compile(elem)(scope);
|
|
|
|
scope.item = asset;
|
|
scope.searchBar = {selectedSuggestionIndex: 1};
|
|
scope.$digest();
|
|
|
|
expect(scope.item.isPerson).toBe(false);
|
|
expect(scope.item.itemStatus).toEqual('Online');
|
|
});
|
|
|
|
it('should generate selected class', function () {
|
|
var elem = angular.element('<chat-assign-suggestion></chat-assign-suggestion>');
|
|
compile(elem)(scope);
|
|
|
|
scope.item = person;
|
|
scope.searchBar = {selectedSuggestionIndex: 1};
|
|
chatModelMock.cachedProfiles[person.jid] = person;
|
|
scope.$digest();
|
|
|
|
expect(scope.generateSelectedClass(1)).toBe('chat__search-result_selected-item');
|
|
});
|
|
}); |