SmartIT_Extensions/BMC/smart-it-full/test/components/chat/chat-swarm.spec.js

59 lines
2.7 KiB
JavaScript

describe('Chat Swarm', function() {
beforeEach(module('myitsmApp'));
beforeEach(inject(function (chatSwarm, ticketModel,relationModel,searchService)
{
this.chatSwarmMock=chatSwarm;
this.ticketModelMock=ticketModel;
this.relationModelMock=relationModel;
this.searchServiceMock=searchService;
}));
it('linkKnowledge', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.relationModelMock, 'addRelation').and.callThrough();
this.chatSwarmMock.linkKnowledgeArticles("123",'testType',chatWindow);
expect(this.relationModelMock.addRelation).toHaveBeenCalled();
}));
it('unlinkKnowledge', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.relationModelMock, 'removeRelation').and.callThrough();
this.chatSwarmMock.unlinkKnowledgeArticles("123",'testType',chatWindow);
expect(this.relationModelMock.removeRelation).toHaveBeenCalled();
}));
it('processChatMessage for any /details', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.ticketModelMock, 'getTicket').and.callThrough();
this.chatSwarmMock.processChatMessage("/details",chatWindow);
expect(this.ticketModelMock.getTicket).toHaveBeenCalled();
}));
it('processChatMessage for any /knowledge', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.ticketModelMock, 'getTicket').and.callThrough();
this.chatSwarmMock.processChatMessage("/knowledge",chatWindow);
expect(this.ticketModelMock.getTicket).toHaveBeenCalled();
}));
it('processChatMessage for any /similarincidents', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.ticketModelMock, 'getTicket').and.callThrough();
this.chatSwarmMock.processChatMessage("/similarincidents",chatWindow);
expect(this.ticketModelMock.getTicket).toHaveBeenCalled();
}));
it('processChatMessage for any /swarm', inject(function() {
var chatWindow={"parent":{"id":"123"}};
spyOn(this.ticketModelMock, 'getTicket').and.callThrough();
this.chatSwarmMock.processChatMessage("/swarm",chatWindow);
expect(this.ticketModelMock.getTicket).toHaveBeenCalled();
}));
it('processChatMessage for any plain text', inject(function() {
var r={$$state: Object({ status: 1, value: 'hello' }) };
expect(JSON.stringify((this.chatSwarmMock.processChatMessage("hello",null)))).toEqual(JSON.stringify(r));
}));
it('checkIfJson for non json values', inject(function() {
expect(this.chatSwarmMock.checkIfJson("hello")).toEqual(false);
}));
it('checkIfJson for json values', inject(function() {
var json='{"name": "John", "age": 31, "city": "New York"}';
expect(this.chatSwarmMock.checkIfJson(json)).toEqual(true);
}));
});