186 lines
9.7 KiB
JavaScript
186 lines
9.7 KiB
JavaScript
/**
|
|
* Created by Srini
|
|
*/
|
|
//This is test suite for Expression Event Manager
|
|
|
|
describe("Test Expression event manager", function() {
|
|
'use strict';
|
|
|
|
var expressionEventManager, objectValueMapperService, expressionEvaluatorService, getExpMapStub,
|
|
evalExpStub, setPropStub, getProviderActionExpMapStub, getAllFieldsStub, getAllProviderActionsFieldsStub,
|
|
setProviderActionPropStub, clearProviderActionPropStub, $timeout, setProviderActionFieldNameStub, clearProviderActionFieldNameStub;
|
|
|
|
beforeEach(module('myitsmApp'));
|
|
beforeEach(inject(function (_expressionEventManager_, _objectValueMapperService_, _expressionEvaluatorService_, _$timeout_, $httpBackend) {
|
|
let getLocale = function () {
|
|
return readJSON('scripts/app/i18n/resources-locale_en.json');
|
|
};
|
|
objectValueMapperService = _objectValueMapperService_;
|
|
expressionEvaluatorService = _expressionEvaluatorService_;
|
|
expressionEventManager = _expressionEventManager_;
|
|
$timeout = _$timeout_;
|
|
|
|
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(200, getLocale());
|
|
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200);
|
|
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').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);
|
|
|
|
getExpMapStub = sinon.stub(objectValueMapperService,'getExpreesionMapByFieldName');
|
|
getExpMapStub.withArgs('field1').returns([{ expression: '$desc != ""', field: 'test2', property: 'readOnly', isWidget: false }]);
|
|
getExpMapStub.returns([]);
|
|
evalExpStub = sinon.stub(expressionEvaluatorService,'evaluate');
|
|
evalExpStub.withArgs('ONCHANGE($status)').returns(false);
|
|
evalExpStub.returns(true);
|
|
setPropStub = sinon.stub(objectValueMapperService,'setByProperty').returns();
|
|
getAllFieldsStub = sinon.stub(objectValueMapperService,'getAllExpressionFields').returns(['field1']);
|
|
getAllProviderActionsFieldsStub = sinon.stub(objectValueMapperService,'getAllProviderActionExpressionFields').returns(['field5']);
|
|
getProviderActionExpMapStub = sinon.stub(objectValueMapperService,'getProviderActionExpressionMapByFieldName');
|
|
setProviderActionFieldNameStub = sinon.stub(objectValueMapperService,'setProviderActionFieldName');
|
|
clearProviderActionFieldNameStub = sinon.stub(objectValueMapperService,'clearProviderActionFieldName');
|
|
let expressionData1 = [
|
|
{
|
|
expression: '$status == "Assigned"',
|
|
actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T',
|
|
action: {
|
|
actionName: "PA1",
|
|
actionType: 'provider'
|
|
}
|
|
}
|
|
], expressionData2 = [
|
|
{
|
|
expression: 'ONCHANGE($status)',
|
|
actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T',
|
|
action: {
|
|
actionName: "PA1",
|
|
actionType: 'provider'
|
|
}
|
|
}
|
|
];
|
|
getProviderActionExpMapStub.withArgs('field5').returns(expressionData1);
|
|
getProviderActionExpMapStub.withArgs('field9').returns(expressionData2);
|
|
getProviderActionExpMapStub.withArgs('field8').returns([
|
|
{
|
|
expression: '$status == "Assigned"',
|
|
actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T',
|
|
action: {
|
|
actionName: "PA1",
|
|
actionType: 'provider',
|
|
sequenceNo: 2
|
|
}
|
|
},
|
|
{
|
|
expression: '$status == "Assigned"',
|
|
actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4W',
|
|
action: {
|
|
actionName: "PA2",
|
|
actionType: 'provider',
|
|
sequenceNo: 1
|
|
}
|
|
}
|
|
]);
|
|
|
|
getProviderActionExpMapStub.returns([]);
|
|
setProviderActionPropStub = sinon.stub(objectValueMapperService,'setProviderActionToExecute').returns();
|
|
clearProviderActionPropStub = sinon.stub(objectValueMapperService,'clearProviderActionFromList').returns();
|
|
}));
|
|
afterEach(function () {
|
|
getExpMapStub.restore();
|
|
evalExpStub.restore();
|
|
setPropStub.restore();
|
|
});
|
|
|
|
it('Should init expression event manager', function () {
|
|
expect(expressionEventManager).toBeDefined();
|
|
expect(expressionEventManager.handleFieldChange).toBeDefined();
|
|
expect(expressionEventManager.handleOOTBFieldValueChange).toBeDefined();
|
|
expect(expressionEventManager.handleTicketLoad).toBeDefined();
|
|
expect(expressionEventManager.handleTicketLoadForActions).toBeDefined();
|
|
expect(expressionEventManager._evaluateFieldExpression).toBeUndefined();
|
|
expect(expressionEventManager._evaluateProviderActionExpression).toBeUndefined();
|
|
});
|
|
it('On field change should get expression map, evaluate and set the value', function () {
|
|
expressionEventManager.handleFieldChange('field1');
|
|
expect(getExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setPropStub.called).toBe(true);
|
|
expect(setPropStub.calledWith('test2', 'readOnly', true, false)).toBe(true);
|
|
});
|
|
it('On field change should get expression map, and if empty should not evaluate or set value', function () {
|
|
expressionEventManager.handleFieldChange('field2');
|
|
expect(getExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(false);
|
|
expect(setPropStub.called).toBe(false);
|
|
});
|
|
it('On Ticket load should get all expression fields and evaluate each field related expression', function () {
|
|
expressionEventManager.handleTicketLoad();
|
|
expect(getAllFieldsStub.called).toBe(true);
|
|
expect(getExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setPropStub.called).toBe(true);
|
|
expect(setPropStub.calledWith('test2', 'readOnly', true, false)).toBe(true);
|
|
});
|
|
it('On Ticket load should get all provider action expression fields and evaluate each field related expression', function () {
|
|
expressionEventManager.handleTicketLoadForActions();
|
|
$timeout.flush();
|
|
expect(getAllProviderActionsFieldsStub.called).toBe(true);
|
|
expect(getProviderActionExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setProviderActionPropStub.called).toBe(true);
|
|
expect(setProviderActionPropStub.calledWith(
|
|
{
|
|
expression: '$status == "Assigned"', actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T',
|
|
action: {
|
|
actionFieldName: "field5", actionId: "AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T", actionName: "PA1", actionType: 'provider'
|
|
}
|
|
})).toBe(true);
|
|
});
|
|
it('On field change should get provider action expression map, and if empty should not evaluate or set value', function () {
|
|
expressionEventManager.handleFieldChangeForActions('field5');
|
|
$timeout.flush();
|
|
expect(getProviderActionExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setProviderActionPropStub.called).toBe(true);
|
|
expect(clearProviderActionPropStub.called).toBe(false);
|
|
});
|
|
|
|
it('On field change should clear Provider Action from list if expression is not matched', function () {
|
|
getProviderActionExpMapStub.withArgs('field6').returns([
|
|
{
|
|
expression: '$status == "Pending"',
|
|
actionId: 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T',
|
|
action: {
|
|
actionName: "PA1",
|
|
actionType: 'provider'
|
|
}
|
|
}
|
|
]);
|
|
evalExpStub.withArgs('$status == "Pending"').returns(false);
|
|
expressionEventManager.handleFieldChangeForActions('field6');
|
|
$timeout.flush();
|
|
expect(getProviderActionExpMapStub.called).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setProviderActionPropStub.called).toBe(false);
|
|
expect(clearProviderActionPropStub.called).toBe(true);
|
|
});
|
|
|
|
it('On field change should get provider action expression map, and should sort it by sequence no and set provider action by fieldName', function () {
|
|
expressionEventManager.handleFieldChangeForActions('field8');
|
|
$timeout.flush();
|
|
expect(getProviderActionExpMapStub.called).toBe(true);
|
|
expect(setProviderActionFieldNameStub.calledWith('field8', 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T')).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
expect(setProviderActionPropStub.called).toBe(true);
|
|
expect(clearProviderActionPropStub.called).toBe(false);
|
|
});
|
|
|
|
it('On field change should get provider action expression map, and should sort it by sequence no and clear provider action by fieldName', function () {
|
|
expressionEventManager.handleFieldChangeForActions('field9');
|
|
$timeout.flush();
|
|
expect(getProviderActionExpMapStub.called).toBe(true);
|
|
expect(setProviderActionFieldNameStub.calledWith('field9', 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T')).toBe(true);
|
|
expect(clearProviderActionFieldNameStub.calledWith('field9', 'AGGAA5V0FKZ9XAPC5WPJPB95F5WX4T')).toBe(true);
|
|
expect(evalExpStub.called).toBe(true);
|
|
});
|
|
}); |