Merge "General specs enclosure cleanup"

This commit is contained in:
Jenkins 2015-04-30 03:03:38 +00:00 committed by Gerrit Code Review
commit ae084c7160
12 changed files with 789 additions and 781 deletions

View File

@ -1,88 +1,90 @@
/* jshint globalstrict: true */
'use strict';
(function(){
describe('hz.widget.charts module', function () {
it('should be defined', function () {
expect(angular.module('hz.widget.charts')).toBeDefined();
});
});
'use strict';
describe('pie chart directive', function() {
var $scope, $element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.charts'));
beforeEach(inject(function($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
$scope.testData = {
title: 'Total Instances',
label: '25%',
data: [
{ label: 'Current', value: 1, color: '#1f83c6' },
{ label: 'Added', value: 1, color: '#81c1e7' },
{ label: 'Remaining', value: 6, color: '#d1d3d4', hideKey: true }
]
};
var settings = '{ "innerRadius": 25 }';
var markup = "<pie-chart chart-data='testData' chart-settings='" + settings + "'></pie-chart>";
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
it('should be compiled', function() {
expect($element.html().trim()).not.toBe('');
describe('hz.widget.charts module', function () {
it('should be defined', function () {
expect(angular.module('hz.widget.charts')).toBeDefined();
});
});
it('should have svg element', function() {
expect($element.find('svg')).toBeDefined();
describe('pie chart directive', function() {
var $scope, $element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.charts'));
beforeEach(inject(function($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
$scope.testData = {
title: 'Total Instances',
label: '25%',
data: [
{ label: 'Current', value: 1, color: '#1f83c6' },
{ label: 'Added', value: 1, color: '#81c1e7' },
{ label: 'Remaining', value: 6, color: '#d1d3d4', hideKey: true }
]
};
var settings = '{ "innerRadius": 25 }';
var markup = "<pie-chart chart-data='testData' chart-settings='" + settings + "'></pie-chart>";
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
it('should be compiled', function() {
expect($element.html().trim()).not.toBe('');
});
it('should have svg element', function() {
expect($element.find('svg')).toBeDefined();
});
it('should have 3 path elements', function() {
expect($element.find('path.slice').length).toBe(3);
});
it('should have correct colors for slices', function() {
var slices = $element.find('path.slice');
var slice1Color = slices[0].style.fill;
if (slice1Color.indexOf('rgb') === 0) {
expect(slices[0].style.fill).toBe('rgb(31, 131, 198)');
expect(slices[1].style.fill).toBe('rgb(129, 193, 231)');
expect(slices[2].style.fill).toBe('rgb(209, 211, 212)');
} else {
expect(slices[0].style.fill).toBe('#1f83c6');
expect(slices[1].style.fill).toBe('#81c1e7');
expect(slices[2].style.fill).toBe('#d1d3d4');
}
});
it('should have a correct title "Total Instances (8 Max)"', function() {
var title = $element.find('.pie-chart-title').text().trim();
expect(title).toBe('Total Instances (8 Max)');
});
it('should have a legend', function() {
expect($element.find('.pie-chart-legend')).toBeDefined();
});
it ('should have correct legend keys and labels', function() {
var legendKeys = $element.find('.pie-chart-legend .slice-legend');
var firstKeyLabel = legendKeys[0];
var secondKeyLabel = legendKeys[1];
expect(firstKeyLabel.textContent.trim()).toBe('1 Current');
expect(secondKeyLabel.textContent.trim()).toBe('1 Added');
});
});
it('should have 3 path elements', function() {
expect($element.find('path.slice').length).toBe(3);
});
it('should have correct colors for slices', function() {
var slices = $element.find('path.slice');
var slice1Color = slices[0].style.fill;
if (slice1Color.indexOf('rgb') === 0) {
expect(slices[0].style.fill).toBe('rgb(31, 131, 198)');
expect(slices[1].style.fill).toBe('rgb(129, 193, 231)');
expect(slices[2].style.fill).toBe('rgb(209, 211, 212)');
} else {
expect(slices[0].style.fill).toBe('#1f83c6');
expect(slices[1].style.fill).toBe('#81c1e7');
expect(slices[2].style.fill).toBe('#d1d3d4');
}
});
it('should have a correct title "Total Instances (8 Max)"', function() {
var title = $element.find('.pie-chart-title').text().trim();
expect(title).toBe('Total Instances (8 Max)');
});
it('should have a legend', function() {
expect($element.find('.pie-chart-legend')).toBeDefined();
});
it ('should have correct legend keys and labels', function() {
var legendKeys = $element.find('.pie-chart-legend .slice-legend');
var firstKeyLabel = legendKeys[0];
var secondKeyLabel = legendKeys[1];
expect(firstKeyLabel.textContent.trim()).toBe('1 Current');
expect(secondKeyLabel.textContent.trim()).toBe('1 Added');
});
});
})();

View File

@ -1,93 +1,94 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hz.widget.form module', function(){
it('should have been defined', function(){
expect(angular.module('hz.widget.form')).toBeDefined();
describe('hz.widget.form module', function(){
it('should have been defined', function(){
expect(angular.module('hz.widget.form')).toBeDefined();
});
});
});
describe('form directives', function() {
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.form'));
describe('form directives', function() {
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.form'));
describe('hzPasswordMatch directive', function() {
describe('hzPasswordMatch directive', function() {
var $compile, $rootScope;
var element, password, cpassword;
var markup =
'<form name="form">' +
'<input type="password" ng-model="user.password" name="password">' +
'<input type="password" ng-model="user.cpassword" ' +
'hz-password-match="form.password">' +
'</form>';
var $compile, $rootScope;
var element, password, cpassword;
var markup =
'<form name="form">' +
'<input type="password" ng-model="user.password" name="password">' +
'<input type="password" ng-model="user.cpassword" ' +
'hz-password-match="form.password">' +
'</form>';
beforeEach(inject(function($injector){
$compile = $injector.get('$compile');
$rootScope = $injector.get('$rootScope').$new();
beforeEach(inject(function($injector){
$compile = $injector.get('$compile');
$rootScope = $injector.get('$rootScope').$new();
// generate dom from markup
element = $compile(markup)($rootScope);
password = element.children('input[name]');
cpassword = element.children('input[hz-password-match]');
// generate dom from markup
element = $compile(markup)($rootScope);
password = element.children('input[name]');
cpassword = element.children('input[hz-password-match]');
// setup up initial data
$rootScope.user = {};
$rootScope.$digest();
}));
// setup up initial data
$rootScope.user = {};
$rootScope.$digest();
}));
it('should be initially empty', function() {
expect(password.val()).toEqual('');
expect(password.val()).toEqual(cpassword.val());
expect(cpassword.hasClass('ng-valid')).toBe(true);
});
it('should not match if user changes only password', function(done) {
$rootScope.user.password = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
it('should not match if user changes only confirmation password', function(done) {
$rootScope.user.cpassword = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
it('should match if both passwords are the same', function(done) {
$rootScope.user.password = 'password';
$rootScope.user.cpassword = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).toEqual(password.val());
it('should be initially empty', function() {
expect(password.val()).toEqual('');
expect(password.val()).toEqual(cpassword.val());
expect(cpassword.hasClass('ng-valid')).toBe(true);
done();
}, 1000);
});
});
it('should not match if both passwords are different', function(done) {
$rootScope.user.password = 'password123';
$rootScope.user.cpassword = 'password345';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
it('should not match if user changes only password', function(done) {
$rootScope.user.password = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
}); // end of hzPasswordMatch directive
}); // end of form directives
it('should not match if user changes only confirmation password', function(done) {
$rootScope.user.cpassword = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
it('should match if both passwords are the same', function(done) {
$rootScope.user.password = 'password';
$rootScope.user.cpassword = 'password';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).toEqual(password.val());
expect(cpassword.hasClass('ng-valid')).toBe(true);
done();
}, 1000);
});
it('should not match if both passwords are different', function(done) {
$rootScope.user.password = 'password123';
$rootScope.user.cpassword = 'password345';
$rootScope.$digest();
cpassword.change();
setTimeout(function(){
expect(cpassword.val()).not.toEqual(password.val());
expect(cpassword.hasClass('ng-invalid')).toBe(true);
done();
}, 1000);
});
}); // end of hzPasswordMatch directive
}); // end of form directives
})();

View File

@ -1,48 +1,49 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hz.widget.help-panel module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.help-panel')).toBeDefined();
});
});
describe('help-panel directive', function () {
var $compile,
$scope,
element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.help-panel'));
beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile');
element = $compile('<help-panel>Help</help-panel>')($scope);
$scope.$digest();
}));
it('should be compiled', function () {
expect(element.html().trim()).not.toBe('Help');
expect(element.text().trim()).toBe('Help');
describe('hz.widget.help-panel module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.help-panel')).toBeDefined();
});
});
it('should be closed by default', function () {
expect(element[0].querySelector('.help-panel').className).toBe('help-panel');
});
describe('help-panel directive', function () {
var $compile,
$scope,
element;
it('should add "open" to class name if $scope.openHelp===true', function () {
$scope.openHelp = true;
$scope.$digest();
expect(element[0].querySelector('.help-panel').className).toBe('help-panel open');
});
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.help-panel'));
beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile');
element = $compile('<help-panel>Help</help-panel>')($scope);
$scope.$digest();
}));
it('should remove "open" from class name if $scope.openHelp===false', function () {
$scope.openHelp = true;
$scope.$digest();
$scope.openHelp = false;
$scope.$digest();
expect(element[0].querySelector('.help-panel').className).toBe('help-panel');
it('should be compiled', function () {
expect(element.html().trim()).not.toBe('Help');
expect(element.text().trim()).toBe('Help');
});
it('should be closed by default', function () {
expect(element[0].querySelector('.help-panel').className).toBe('help-panel');
});
it('should add "open" to class name if $scope.openHelp===true', function () {
$scope.openHelp = true;
$scope.$digest();
expect(element[0].querySelector('.help-panel').className).toBe('help-panel open');
});
it('should remove "open" from class name if $scope.openHelp===false', function () {
$scope.openHelp = true;
$scope.$digest();
$scope.openHelp = false;
$scope.$digest();
expect(element[0].querySelector('.help-panel').className).toBe('help-panel');
});
});
});
})();

View File

@ -14,153 +14,154 @@
* under the License.
*/
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hzLoginCtrl', function(){
describe('hzLoginCtrl', function(){
var $controller;
var $controller;
beforeEach(module('hz'));
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
beforeEach(module('hz'));
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
describe('$scope.auth_type', function(){
it('should initialize to credentials', function(){
var scope = {};
$controller('hzLoginCtrl', { $scope: scope });
expect(scope.auth_type).toEqual('credentials');
});
});
});
describe('hzLoginFinder', function(){
var $compile, $rootScope, $timeout;
var websso_markup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div>' +
'<select id="id_auth_type">' +
'<option value="credentials">Credentials</option>' +
'<option value="oidc">OpenID Connect</option>' +
'</select>' +
'</div>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
var regular_markup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
beforeEach(module('hz'));
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_){
$compile = _$compile_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
jasmine.addMatchers({
// jquery show is not consistent across different browsers
// on FF, it is 'block' while on chrome it is 'inline'
// to reconcile this difference, we need a custom matcher
toBeVisible: function(){
return {
compare: function(actual){
var pass = (actual.css('display') !== 'none');
var result = {
pass: pass,
message: pass?
'Expected element to be visible':
'Expected element to be visible, but it is hidden'
};
return result;
}
};
}
});
}));
describe('when websso is not enabled', function(){
var element,
helpText, authType,
userInput, passwordInput;
beforeEach(function(){
element = $compile(regular_markup)($rootScope);
authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group');
helpText = element.find('#help_text');
$rootScope.$digest();
});
it('should not contain auth_type select input', function(){
expect(authType.length).toEqual(0);
});
it('should hide help text', function(){
expect(helpText).not.toBeVisible();
});
it('should show username and password inputs', function(){
expect(userInput).toBeVisible();
expect(passwordInput).toBeVisible();
describe('$scope.auth_type', function(){
it('should initialize to credentials', function(){
var scope = {};
$controller('hzLoginCtrl', { $scope: scope });
expect(scope.auth_type).toEqual('credentials');
});
});
});
describe('when websso is enabled', function(){
describe('hzLoginFinder', function(){
var element,
helpText, authType,
userInput, passwordInput;
var $compile, $rootScope, $timeout;
var websso_markup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div>' +
'<select id="id_auth_type">' +
'<option value="credentials">Credentials</option>' +
'<option value="oidc">OpenID Connect</option>' +
'</select>' +
'</div>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
var regular_markup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
beforeEach(module('hz'));
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_){
$compile = _$compile_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
jasmine.addMatchers({
// jquery show is not consistent across different browsers
// on FF, it is 'block' while on chrome it is 'inline'
// to reconcile this difference, we need a custom matcher
toBeVisible: function(){
return {
compare: function(actual){
var pass = (actual.css('display') !== 'none');
var result = {
pass: pass,
message: pass?
'Expected element to be visible':
'Expected element to be visible, but it is hidden'
};
return result;
}
};
}
});
}));
describe('when websso is not enabled', function(){
var element,
helpText, authType,
userInput, passwordInput;
beforeEach(function(){
element = $compile(regular_markup)($rootScope);
authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group');
helpText = element.find('#help_text');
$rootScope.$digest();
});
it('should not contain auth_type select input', function(){
expect(authType.length).toEqual(0);
});
it('should hide help text', function(){
expect(helpText).not.toBeVisible();
});
it('should show username and password inputs', function(){
expect(userInput).toBeVisible();
expect(passwordInput).toBeVisible();
});
beforeEach(function(){
element = $compile(websso_markup)($rootScope);
authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group');
helpText = element.find('#help_text');
$rootScope.$digest();
});
it('should contain auth_type select input', function(){
expect(authType.length).toEqual(1);
});
describe('when websso is enabled', function(){
it('should show help text below auth_type', function(){
expect(authType.next().get(0)).toEqual(helpText.get(0));
});
var element,
helpText, authType,
userInput, passwordInput;
it('should show help text', function(){
expect(helpText).toBeVisible();
});
beforeEach(function(){
element = $compile(websso_markup)($rootScope);
authType = element.find('#id_auth_type');
userInput = element.find("#id_username").parents('.form-group');
passwordInput = element.find("#id_password").parents('.form-group');
helpText = element.find('#help_text');
$rootScope.$digest();
});
it('should show username and password inputs', function(){
expect(userInput).toBeVisible();
expect(passwordInput).toBeVisible();
});
it('should contain auth_type select input', function(){
expect(authType.length).toEqual(1);
});
it('should show help text below auth_type', function(){
expect(authType.next().get(0)).toEqual(helpText.get(0));
});
it('should show help text', function(){
expect(helpText).toBeVisible();
});
it('should show username and password inputs', function(){
expect(userInput).toBeVisible();
expect(passwordInput).toBeVisible();
});
it('should hide username and password when user picks oidc', function(){
authType.val('oidc');
authType.change();
$timeout.flush();
expect(userInput).not.toBeVisible();
expect(passwordInput).not.toBeVisible();
});
it('should hide username and password when user picks oidc', function(){
authType.val('oidc');
authType.change();
$timeout.flush();
expect(userInput).not.toBeVisible();
expect(passwordInput).not.toBeVisible();
});
});
});
})();

View File

@ -1,135 +1,136 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hz.widget.metadata-display module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.metadata-display')).toBeDefined();
});
describe('hz.widget.metadata-display module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.metadata-display')).toBeDefined();
});
var namespaces = [
{
"display_name": "Test Namespace A",
"description": "Test namespace description",
"properties": {
"test:A:1": {
"title": "Test A.1 - string",
"type": "string",
"default": "foo",
"enum": [
"option-1", "option-2", "option-3"
]
},
"test:A:2": {
"title": "Test A.2 - integer",
"type": "integer",
"default": "1",
"minimum": 0,
"maximum": 10
},
"test:A:3": {
"title": "Test A.3 - number",
"type": "number",
"default": "1.1",
"minimum": 0,
"maximum": 10
},
"test:A:4": {
"title": "Test A.4 - boolean",
"type": "boolean",
"default": "True"
},
"test:A:5": {
"title": "Test A.5 - boolean",
"type": "boolean",
"default": "false"
},
"test:A:6": {
"title": "Test A.6 - array",
"type": "array",
"items": {
var namespaces = [
{
"display_name": "Test Namespace A",
"description": "Test namespace description",
"properties": {
"test:A:1": {
"title": "Test A.1 - string",
"type": "string",
"default": "foo",
"enum": [
"val-1", "val-2", "val-3"
"option-1", "option-2", "option-3"
]
},
"test:A:2": {
"title": "Test A.2 - integer",
"type": "integer",
"default": "1",
"minimum": 0,
"maximum": 10
},
"test:A:3": {
"title": "Test A.3 - number",
"type": "number",
"default": "1.1",
"minimum": 0,
"maximum": 10
},
"test:A:4": {
"title": "Test A.4 - boolean",
"type": "boolean",
"default": "True"
},
"test:A:5": {
"title": "Test A.5 - boolean",
"type": "boolean",
"default": "false"
},
"test:A:6": {
"title": "Test A.6 - array",
"type": "array",
"items": {
"type": "string",
"enum": [
"val-1", "val-2", "val-3"
]
}
}
}
},
{
"display_name": "Test Namespace B",
"description": "Test namespace description",
"objects": [
{
"name": "Test Object A",
"description": "Test object description",
"properties": {
"test:B:A:1": {
"title": "Test B.A.1",
"description": "Test description"
},
"test:B:A:2": {}
}
},
{
"name": "Test Object B",
"description": "Test object description",
"properties": {
"test:B:B:1": {},
"test:B:B:2": {}
}
}
]
}
},
{
"display_name": "Test Namespace B",
"description": "Test namespace description",
"objects": [
{
"name": "Test Object A",
"description": "Test object description",
"properties": {
"test:B:A:1": {
"title": "Test B.A.1",
"description": "Test description"
},
"test:B:A:2": {}
}
},
{
"name": "Test Object B",
"description": "Test object description",
"properties": {
"test:B:B:1": {},
"test:B:B:2": {}
}
}
]
}
];
];
var existing = {
'test:A:1': 'option-2',
'test:A:2': '5',
'test:B:A:1': 'foo',
'test:B:B:1': 'bar'
};
var existing = {
'test:A:1': 'option-2',
'test:A:2': '5',
'test:B:A:1': 'foo',
'test:B:B:1': 'bar'
};
describe('hzMetadataDisplay directive', function () {
var $scope, $element;
describe('hzMetadataDisplay directive', function () {
var $scope, $element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.metadata-tree'));
beforeEach(module('hz.widget.metadata-display'));
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.metadata-tree'));
beforeEach(module('hz.widget.metadata-display'));
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
$scope.available = namespaces;
$scope.existing = existing;
$scope.available = namespaces;
$scope.existing = existing;
var markup =
'<hz-metadata-display available="available" existing="existing"></hz-metadata-display>';
var markup =
'<hz-metadata-display available="available" existing="existing"></hz-metadata-display>';
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
it('should have 3 rows in selector list', function() {
expect($element.find('.selector .selector-item').length).toBe(3);
it('should have 3 rows in selector list', function() {
expect($element.find('.selector .selector-item').length).toBe(3);
});
it('should have 2 items in first group', function() {
expect($element.find('div[ng-repeat] div.auto-width').length).toBe(2);
});
it('should have 1 item in second group', function() {
$element.find('.selector .selector-item:nth-child(2)').trigger('click');
expect($element.find('div[ng-repeat] div.auto-width').length).toBe(1);
});
it('should have proper description', function() {
expect($element.find('span[ng-bind="selected.description"]').text()).toBe(namespaces[0].description);
$element.find('.selector .selector-item:nth-child(2)').trigger('click');
expect($element.find('span[ng-bind="selected.description"]').text()).toBe(namespaces[1].objects[0].description);
});
});
it('should have 2 items in first group', function() {
expect($element.find('div[ng-repeat] div.auto-width').length).toBe(2);
});
it('should have 1 item in second group', function() {
$element.find('.selector .selector-item:nth-child(2)').trigger('click');
expect($element.find('div[ng-repeat] div.auto-width').length).toBe(1);
});
it('should have proper description', function() {
expect($element.find('span[ng-bind="selected.description"]').text()).toBe(namespaces[0].description);
$element.find('.selector .selector-item:nth-child(2)').trigger('click');
expect($element.find('span[ng-bind="selected.description"]').text()).toBe(namespaces[1].objects[0].description);
});
});
});
})();

View File

@ -1,189 +1,190 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hz.widget.metadata-tree module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.metadata-tree')).toBeDefined();
});
describe('hz.widget.metadata-tree module', function() {
it('should have been defined', function () {
expect(angular.module('hz.widget.metadata-tree')).toBeDefined();
});
var namespaces = [
{
"display_name": "Test Namespace A",
"description": "Test namespace description",
"properties": {
"test:A:1": {
"title": "Test A.1 - string",
"type": "string",
"default": "foo",
"enum": [
"option-1", "option-2", "option-3"
]
},
"test:A:2": {
"title": "Test A.2 - integer",
"type": "integer",
"default": "1",
"minimum": 0,
"maximum": 10
},
"test:A:3": {
"title": "Test A.3 - number",
"type": "number",
"default": "1.1",
"minimum": 0,
"maximum": 10
},
"test:A:4": {
"title": "Test A.4 - boolean",
"type": "boolean",
"default": "True"
},
"test:A:5": {
"title": "Test A.5 - boolean",
"type": "boolean",
"default": "false"
},
"test:A:6": {
"title": "Test A.6 - array",
"type": "array",
"items": {
var namespaces = [
{
"display_name": "Test Namespace A",
"description": "Test namespace description",
"properties": {
"test:A:1": {
"title": "Test A.1 - string",
"type": "string",
"default": "foo",
"enum": [
"val-1", "val-2", "val-3", "val-4"
"option-1", "option-2", "option-3"
]
},
"default": "<in> val-2,val-3"
}
}
},
{
"display_name": "Test Namespace B",
"description": "Test namespace description",
"objects": [
{
"name": "Test Object A",
"description": "Test object description",
"properties": {
"test:B:A:1": {
"title": "Test B.A.1",
"description": "Test description"
"test:A:2": {
"title": "Test A.2 - integer",
"type": "integer",
"default": "1",
"minimum": 0,
"maximum": 10
},
"test:A:3": {
"title": "Test A.3 - number",
"type": "number",
"default": "1.1",
"minimum": 0,
"maximum": 10
},
"test:A:4": {
"title": "Test A.4 - boolean",
"type": "boolean",
"default": "True"
},
"test:A:5": {
"title": "Test A.5 - boolean",
"type": "boolean",
"default": "false"
},
"test:A:6": {
"title": "Test A.6 - array",
"type": "array",
"items": {
"type": "string",
"enum": [
"val-1", "val-2", "val-3", "val-4"
]
},
"test:B:A:2": {}
}
},
{
"name": "Test Object B",
"description": "Test object description",
"properties": {
"test:B:B:1": {},
"test:B:B:2": {}
"default": "<in> val-2,val-3"
}
}
]
}
];
},
{
"display_name": "Test Namespace B",
"description": "Test namespace description",
"objects": [
{
"name": "Test Object A",
"description": "Test object description",
"properties": {
"test:B:A:1": {
"title": "Test B.A.1",
"description": "Test description"
},
"test:B:A:2": {}
}
},
{
"name": "Test Object B",
"description": "Test object description",
"properties": {
"test:B:B:1": {},
"test:B:B:2": {}
}
}
]
}
];
describe('directives', function () {
var $scope, $element;
describe('directives', function () {
var $scope, $element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.metadata-tree'));
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.metadata-tree'));
describe('hzMetadataTree directive', function() {
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
describe('hzMetadataTree directive', function() {
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
$scope.available = namespaces;
$scope.existing = {'test:B:A:1':'foo'};
$scope.available = namespaces;
$scope.existing = {'test:B:A:1':'foo'};
var markup =
'<hz-metadata-tree available="available" existing="existing"></hz-metadata-tree>';
var markup =
'<hz-metadata-tree available="available" existing="existing"></hz-metadata-tree>';
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
it('should have 2 rows in available list', function() {
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(2);
it('should have 2 rows in available list', function() {
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(2);
});
it('should have 1 row in existing list', function() {
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(1);
expect($element.find('ul.list-group:last li[ng-repeat]:first').scope().item.leaf.name).toBe('test:B:A:1');
expect($element.find('ul.list-group:last li[ng-repeat]:first').scope().item.leaf.value).toBe('foo');
});
it('should have 10 rows in available list when expanded items', function() {
$element.find('ul.list-group:first li[ng-repeat]:first').trigger('click');
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(10);
});
it('should remove item from available and add it in existing list when added', function() {
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(6);
$element.find('ul.list-group:first li[ng-repeat]:last .btn').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(5);
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(2);
expect($element.find('ul.list-group:last li[ng-repeat].active').scope().item.leaf.name).toBe('test:B:B:2');
});
it('should add item to available and remove it from existing list when removed', function() {
$element.find('ul.list-group:last li[ng-repeat]:first .btn').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(6);
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(0);
expect($element.find('ul.list-group:first li[ng-repeat].active').scope().item.leaf.name).toBe('test:B:A:1');
});
it('should add custom item to existing list', function() {
$element.find('ul.list-group:first li:first input').val('custom').trigger('input');
$element.find('ul.list-group:first li:first .btn').trigger('click');
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(2);
expect($element.find('ul.list-group:last li[ng-repeat].active').scope().item.leaf.name).toBe('custom');
});
});
it('should have 1 row in existing list', function() {
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(1);
expect($element.find('ul.list-group:last li[ng-repeat]:first').scope().item.leaf.name).toBe('test:B:A:1');
expect($element.find('ul.list-group:last li[ng-repeat]:first').scope().item.leaf.value).toBe('foo');
});
describe('hzMetadataTreeItem directive', function() {
var $scope, $element, item;
it('should have 10 rows in available list when expanded items', function() {
$element.find('ul.list-group:first li[ng-repeat]:first').trigger('click');
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(10);
});
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
it('should remove item from available and add it in existing list when added', function() {
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(6);
$element.find('ul.list-group:first li[ng-repeat]:last .btn').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(5);
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(2);
expect($element.find('ul.list-group:last li[ng-repeat].active').scope().item.leaf.name).toBe('test:B:B:2');
});
item = new ($injector.get('metadataTreeService').Item)();
$scope.item = item.fromProperty('test', namespaces[0].properties['test:A:6']);
it('should add item to available and remove it from existing list when removed', function() {
$element.find('ul.list-group:last li[ng-repeat]:first .btn').trigger('click');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(6);
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(0);
expect($element.find('ul.list-group:first li[ng-repeat].active').scope().item.leaf.name).toBe('test:B:A:1');
});
var markup =
'<hz-metadata-tree-item item="item" text="text" action=""></hz-metadata-tree-item>';
it('should add custom item to existing list', function() {
$element.find('ul.list-group:first li:first input').val('custom').trigger('input');
$element.find('ul.list-group:first li:first .btn').trigger('click');
expect($element.find('ul.list-group:last li[ng-repeat]').length).toBe(2);
expect($element.find('ul.list-group:last li[ng-repeat].active').scope().item.leaf.name).toBe('custom');
});
});
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
describe('hzMetadataTreeItem directive', function() {
var $scope, $element, item;
it('should have additional methods for array ', function () {
expect($element.isolateScope().opened).toBe(false);
expect($element.isolateScope().add).toBeDefined();
expect($element.isolateScope().remove).toBeDefined();
expect($element.isolateScope().open).toBeDefined();
});
beforeEach(inject(function ($injector) {
var $compile = $injector.get('$compile');
$scope = $injector.get('$rootScope').$new();
it('should add values to array ', function () {
$element.find('.options li:last').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-2,val-3,val-4');
$element.find('.options li:first').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-1,val-2,val-3,val-4');
});
item = new ($injector.get('metadataTreeService').Item)();
$scope.item = item.fromProperty('test', namespaces[0].properties['test:A:6']);
var markup =
'<hz-metadata-tree-item item="item" text="text" action=""></hz-metadata-tree-item>';
$element = angular.element(markup);
$compile($element)($scope);
$scope.$digest();
}));
it('should have additional methods for array ', function () {
expect($element.isolateScope().opened).toBe(false);
expect($element.isolateScope().add).toBeDefined();
expect($element.isolateScope().remove).toBeDefined();
expect($element.isolateScope().open).toBeDefined();
});
it('should add values to array ', function () {
$element.find('.options li:last').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-2,val-3,val-4');
$element.find('.options li:first').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-1,val-2,val-3,val-4');
});
it('should remove value from array ', function () {
$element.find('.values .label:first').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-3');
it('should remove value from array ', function () {
$element.find('.values .label:first').trigger('click');
expect(item.leaf.getValue()).toBe('<in> val-3');
});
});
});
});
});
})();

View File

@ -1,4 +1,3 @@
/* jshint globalstrict: true */
(function() {
'use strict';

View File

@ -1,163 +1,163 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
describe('hz.widget.wizard module', function () {
it('should have been defined', function () {
expect(angular.module('hz.widget.wizard')).toBeDefined();
});
});
describe('wizard directive', function () {
var $compile,
$scope,
element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.wizard'));
beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile');
element = $compile('<wizard></wizard>')($scope);
}));
it('should be compiled', function () {
var element = $compile('<wizard>some text</wizard>')($scope);
$scope.$digest();
expect(element.html().trim()).not.toBe('some text');
describe('hz.widget.wizard module', function () {
it('should have been defined', function () {
expect(angular.module('hz.widget.wizard')).toBeDefined();
});
});
it('should have empty title by default', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelector('.title').textContent).toBe('');
describe('wizard directive', function () {
var $compile,
$scope,
element;
beforeEach(module('templates'));
beforeEach(module('hz'));
beforeEach(module('hz.widgets'));
beforeEach(module('hz.widget.wizard'));
beforeEach(inject(function ($injector) {
$scope = $injector.get('$rootScope').$new();
$compile = $injector.get('$compile');
element = $compile('<wizard></wizard>')($scope);
}));
it('should be compiled', function () {
var element = $compile('<wizard>some text</wizard>')($scope);
$scope.$digest();
expect(element.html().trim()).not.toBe('some text');
});
it('should have empty title by default', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelector('.title').textContent).toBe('');
});
it('should have title if it is specified by workflow', function () {
var titleText = 'Some title';
$scope.workflow = {};
$scope.workflow.title = titleText;
$scope.$digest();
expect(element[0].querySelector('.title').textContent).toBe(titleText);
});
it('should have no steps if no steps defined', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelectorAll('.step').length).toBe(0);
});
it('should have 3 steps if 3 steps defined', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect(element[0].querySelectorAll('.step').length).toBe(3);
});
it('should have no nav items if no steps defined', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelectorAll('.nav-item').length).toBe(0);
});
it('should have 3 nav items if 3 steps defined', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect(element[0].querySelectorAll('.nav-item').length).toBe(3);
});
it('should navigate correctly', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect($scope.currentIndex).toBe(0);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(false);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(true);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(true);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(false);
$scope.switchTo(1);
$scope.$digest();
expect($scope.currentIndex).toBe(1);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(false);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(true);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(true);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(false);
$scope.switchTo(2);
$scope.$digest();
expect($scope.currentIndex).toBe(2);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(false);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(true);
});
it('should not show back button in step 1/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(true);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(false);
});
it('should show both back and next button in step 2/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
$scope.switchTo(1);
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(false);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(false);
});
it('should not show next button in step 3/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
$scope.switchTo(2);
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(false);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(true);
});
it('should have finish button disabled if wizardForm is invalid', function () {
$scope.wizardForm = { };
$scope.$digest();
$scope.wizardForm.$invalid = true;
$scope.$digest();
expect(element[0].querySelector('button.finish').hasAttribute('disabled')).toBe(true);
});
it('should have finish button enabled if wizardForm is valid', function () {
$scope.wizardForm = { };
$scope.$digest();
$scope.wizardForm.$invalid = false;
$scope.$digest();
expect(element[0].querySelector('button.finish').hasAttribute('disabled')).toBe(false);
});
it('should show error message after calling method showError', function () {
var errorMessage = 'some error message';
$scope.$digest();
$scope.showError(errorMessage);
$scope.$digest();
expect(element[0].querySelector('.error-message').textContent).toBe(errorMessage);
});
});
it('should have title if it is specified by workflow', function () {
var titleText = 'Some title';
$scope.workflow = {};
$scope.workflow.title = titleText;
$scope.$digest();
expect(element[0].querySelector('.title').textContent).toBe(titleText);
});
it('should have no steps if no steps defined', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelectorAll('.step').length).toBe(0);
});
it('should have 3 steps if 3 steps defined', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect(element[0].querySelectorAll('.step').length).toBe(3);
});
it('should have no nav items if no steps defined', function () {
$scope.workflow = {};
$scope.$digest();
expect(element[0].querySelectorAll('.nav-item').length).toBe(0);
});
it('should have 3 nav items if 3 steps defined', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect(element[0].querySelectorAll('.nav-item').length).toBe(3);
});
it('should navigate correctly', function () {
$scope.workflow = {
steps: [ {}, {}, {} ]
};
$scope.$digest();
expect($scope.currentIndex).toBe(0);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(false);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(true);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(true);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(false);
$scope.switchTo(1);
$scope.$digest();
expect($scope.currentIndex).toBe(1);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(false);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(true);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(true);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(false);
$scope.switchTo(2);
$scope.$digest();
expect($scope.currentIndex).toBe(2);
expect($(element).find('.step').eq(0).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(1).hasClass('ng-hide')).toBe(true);
expect($(element).find('.step').eq(2).hasClass('ng-hide')).toBe(false);
expect($(element).find('.nav-item').eq(0).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(1).hasClass('current')).toBe(false);
expect($(element).find('.nav-item').eq(2).hasClass('current')).toBe(true);
});
it('should not show back button in step 1/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(true);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(false);
});
it('should show both back and next button in step 2/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
$scope.switchTo(1);
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(false);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(false);
});
it('should not show next button in step 3/3', function () {
$scope.workflow = {
steps: [{}, {}, {}]
};
$scope.$digest();
$scope.switchTo(2);
$scope.$digest();
expect($(element).find('button.back').hasClass('ng-hide')).toBe(false);
expect($(element).find('button.next').hasClass('ng-hide')).toBe(true);
});
it('should have finish button disabled if wizardForm is invalid', function () {
$scope.wizardForm = { };
$scope.$digest();
$scope.wizardForm.$invalid = true;
$scope.$digest();
expect(element[0].querySelector('button.finish').hasAttribute('disabled')).toBe(true);
});
it('should have finish button enabled if wizardForm is valid', function () {
$scope.wizardForm = { };
$scope.$digest();
$scope.wizardForm.$invalid = false;
$scope.$digest();
expect(element[0].querySelector('button.finish').hasAttribute('disabled')).toBe(false);
});
it('should show error message after calling method showError', function () {
var errorMessage = 'some error message';
$scope.$digest();
$scope.showError(errorMessage);
$scope.$digest();
expect(element[0].querySelector('.error-message').textContent).toBe(errorMessage);
});
});
})();

View File

@ -1,4 +1,3 @@
/* jshint globalstrict: true */
/*
* (c) Copyright 2015 Hewlett-Packard Development Company, L.P.
*

View File

@ -1,2 +1,4 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
})();

View File

@ -1,2 +1,4 @@
/* jshint globalstrict: true */
'use strict';
(function(){
'use strict';
})();

View File

@ -1,4 +1,3 @@
/* jshint globalstrict: true */
/*
* (c) Copyright 2015 Hewlett-Packard Development Company, L.P.
*