SmartIT_Extensions/BMC/smart-it-full/test/app/admin/screen-configuration/screen-configuration-contro...

186 lines
6.7 KiB
JavaScript

var systemRequiredField = {
'id': '1',
'name': 'test',
'itsmFieldId': 9999999,
'type': 'characterField',
'dataType': 'text',
'displayOrder': 0,
'label': 'Test Field',
'groupMember': false,
'widgetMember': false,
'ootb': true,
'itsmRequired': true,
'arFieldName': 'Workorder Number',
'hide': false,
'required': false,
'editable': true,
'hideLabel': true,
'rowCount': 1,
'maxLength': 15,
'accessible': true
};
describe('ScreenConfigurationController ', function () {
var $controller, $rootScope, $scope, $httpBackend, $q, $modal, events, screenConfigurationModel,
layoutConfigurationModel, configurationModel;
beforeEach(module('myitsmApp', 'adminModule'));
beforeEach(inject(function (_$q_, _$controller_, _$rootScope_, _$httpBackend_, _$modal_, _configurationModel_,
_screenConfigurationModel_, _layoutConfigurationModel_, _events_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
screenConfigurationModel = _screenConfigurationModel_;
layoutConfigurationModel = _layoutConfigurationModel_;
configurationModel = _configurationModel_;
$q = _$q_;
events = _events_;
$modal = _$modal_;
$scope = $rootScope.$new();
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(200, getLocale());
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200, 1);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200, {});
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200, readJSON('mocks/metadata-global.json'));
$httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&fromConfig=true')
.respond(200, readJSON('mocks/workOrderViewScreen.json'));
$httpBackend.whenGET('/smartit/rest/v2/customization/screenlayout')
.respond(200, readJSON('mocks/workOrder-screenlayout.json'));
$httpBackend.whenGET(/smartit\/rest\/v2\/customization\/field\/available\/search/).respond(200, []);
spyOn(configurationModel, 'isServerApplicationEnabled').and.returnValue(true);
}));
it('should exist', function () {
var ScreenConfigurationController = $controller('ScreenConfigurationController', { $scope: $scope });
expect(ScreenConfigurationController).toBeDefined();
});
it('should initialize', function () {
spyOn(screenConfigurationModel, 'loadConfiguration').and.callThrough();
spyOn(layoutConfigurationModel, 'loadLayout').and.callThrough();
spyOn(screenConfigurationModel, 'loadAvailableFieldListForAllNewScreens').and.callFake(function () {
screenConfigurationModel.availableFieldsCache[ScreenConfigurationVO.prototype.WORK_ORDER_VIEW_SCREEN] = [new FieldVO().build(systemRequiredField)];
return $q.when([]);
});
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
expect(screenConfigurationModel.loadConfiguration).toHaveBeenCalled();
expect(layoutConfigurationModel.loadLayout).toHaveBeenCalled();
expect(screenConfigurationModel.loadAvailableFieldListForAllNewScreens).toHaveBeenCalled();
expect($scope.screens.length).toEqual(1);
expect($scope.screens[0].layout).toEqual(jasmine.objectContaining(layoutConfigurationModel.getLayoutFromCacheByScreenName($scope.screens[0].name)));
expect($scope.screens[0].invalidCustomizations).toEqual(jasmine.objectContaining({ missingSystemFields: true }));
});
it('should show screen panel editor modal dialog', function () {
spyOn($modal, 'open').and.callThrough();
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
var panel = $scope.screens[0].panels[0];
$scope.showEditor(panel, []);
expect($modal.open).toHaveBeenCalledWith(jasmine.objectContaining({
windowClass: 'action-blade',
controller: 'CustomAreaEditorController',
resolve: {
customArea: jasmine.any(Function),
allPanels: jasmine.any(Function)
}
}))
});
it('should show screen action editor modal dialog', function () {
spyOn($modal, 'open').and.callThrough();
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
$scope.showActionEditor($scope.screens[0]);
expect($modal.open).toHaveBeenCalledWith(jasmine.objectContaining({
windowClass: 'action-blade',
controller: 'CustomActionEditorController',
resolve: {
screenObj: jasmine.any(Function)
}
}))
});
it('should set hover panel id on mouse in/out events', function () {
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
var screen = $scope.screens[0],
panel = screen.panels[0];
$scope.onPanelMouseOver(screen, panel);
expect(screen.hoveredPanelId).toEqual(panel.shortId);
$scope.onPanelMouseLeave(screen);
expect(screen.hoveredPanelId).toBe('');
});
it('should generate proper tooltip for invalid screen', inject(function ($filter) {
spyOn(screenConfigurationModel, 'loadAvailableFieldListForAllNewScreens').and.callFake(function () {
screenConfigurationModel.availableFieldsCache[ScreenConfigurationVO.prototype.WORK_ORDER_VIEW_SCREEN] = [new FieldVO().build(systemRequiredField)];
return $q.when([]);
});
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
var expectedTooltipText = $filter('i18n')('customization.screen.invalidCustomization.tooltip',
$filter('i18n')('customization.screen.invalidCustomization.tooltips.missingSystemFields')); // This screen has invalid customizations: Missing System required fields.
expect($scope.getScreenInvalidationTooltip($scope.screens[0])).toEqual(expectedTooltipText);
}));
it('should refresh metadata for particular screen', inject(function (systemAlertService) {
spyOn(screenConfigurationModel, 'refreshMetadataForDatasource').and.callThrough();
spyOn(systemAlertService, 'success');
$controller('ScreenConfigurationController', { $scope: $scope });
$httpBackend.flush();
$scope.$digest();
var screen = $scope.screens[0];
$scope.onRefreshMetadataClick(screen);
expect(screenConfigurationModel.refreshMetadataForDatasource).toHaveBeenCalledWith(screen.datasource, screen.name);
$httpBackend.expectGET(/smartit\/rest\/v2\/customization\/metadata\/field\/available\/refresh/).respond(200);
$httpBackend.expectGET(/smartit\/rest\/v2\/customization\/application\/search/).respond(200, readJSON('mocks/workOrderViewScreen.json'));
$httpBackend.expectGET(/smartit\/rest\/v2\/customization\/field\/available\/search/);
$httpBackend.flush();
expect(systemAlertService.success).toHaveBeenCalled();
}));
});