Commit 8a580c69 by Sam Padgett Committed by GitHub

Merge pull request #229 from spadgett/unit-tests

Add more unit tests
parents 41e0cc28 ef2075a6
node_modules
coverage
.tmp
.bundle
.idea
......@@ -7,5 +8,3 @@ phantomjsdriver.log
.DS_Store
test/test-results.xml
npm-debug.log
......@@ -24,8 +24,8 @@ module.exports = function (grunt) {
},
watch: {
scripts: {
files: ['src/**/*'],
tasks: ['deploy'],
files: ['src/**/*', 'test/**/*.js'],
tasks: ['deploy', 'test'],
options: {
spawn: false,
},
......
......@@ -1262,55 +1262,42 @@ angular.module('openshiftCommonUI')
angular.module('openshiftCommonUI')
.filter("alertStatus", function() {
return function (type) {
var status;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
status = 'alert-danger';
break;
return 'alert-danger';
case 'warning':
status = 'alert-warning';
break;
return 'alert-warning';
case 'success':
status = 'alert-success';
break;
return 'alert-success';
case 'normal':
status = 'alert-info';
break;
default:
status = 'alert-info';
return 'alert-info';
}
return status;
return 'alert-info';
};
})
.filter('alertIcon', function() {
return function (type) {
var icon;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
icon = 'pficon pficon-error-circle-o';
break;
return 'pficon pficon-error-circle-o';
case 'warning':
icon = 'pficon pficon-warning-triangle-o';
break;
return 'pficon pficon-warning-triangle-o';
case 'success':
icon = 'pficon pficon-ok';
break;
return 'pficon pficon-ok';
case 'normal':
icon = 'pficon pficon-info';
break;
default:
icon = 'pficon pficon-info';
return 'pficon pficon-info';
}
return icon;
return 'pficon pficon-info';
};
});
;'use strict';
......@@ -1541,24 +1528,24 @@ angular.module('openshiftCommonUI')
// color SVG images for. Depends on window.OPENSHIFT_CONSTANTS.LOGOS and
// window.OPENSHIFT_CONSTANTS.LOGO_BASE_URL, which is set by origin-web-console
// (or an extension).
.filter('imageForIconClass', function(isAbsoluteURLFilter) {
.filter('imageForIconClass', function($window, isAbsoluteURLFilter) {
return function(iconClass) {
if (!iconClass) {
return '';
}
var logoImage = _.get(window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
var logoImage = _.get($window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
if (!logoImage) {
return '';
}
// Make sure the logo base has a trailing slash.
var logoBaseUrl = _.get(window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
var logoBaseUrl = _.get($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
if (!logoBaseUrl || isAbsoluteURLFilter(logoImage)) {
return logoImage;
}
if (!logoBaseUrl.endsWith('/')) {
if (!_.endsWith(logoBaseUrl, '/')) {
logoBaseUrl += '/';
}
......@@ -1570,7 +1557,7 @@ angular.module('openshiftCommonUI')
angular.module('openshiftCommonUI')
.filter('isAbsoluteURL', function() {
return function(url) {
if (!url) {
if (!url || !_.isString(url)) {
return false;
}
var uri = new URI(url);
......@@ -1823,12 +1810,7 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayName;
}
var serviceClassExternalName = _.get(serviceClass, 'spec.externalName');
if (serviceClassExternalName) {
return serviceClassExternalName;
}
return _.get(serviceClass, 'metadata.name');
return _.get(serviceClass, 'spec.externalName');
};
})
.filter('serviceInstanceDisplayName', function(serviceClassDisplayNameFilter) {
......@@ -1837,6 +1819,11 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayNameFilter(serviceClass);
}
var externalServiceClassName = _.get(instance, 'spec.externalClusterServiceClassName');
if (externalServiceClassName) {
return externalServiceClassName;
}
return _.get(instance, 'metadata.name');
};
})
......@@ -1861,7 +1848,7 @@ angular.module('openshiftCommonUI')
.filter('camelToLower', function() {
return function(str) {
if (!str) {
return str;
return '';
}
// Use the special logic in _.startCase to handle camel case strings, kebab
......@@ -1872,40 +1859,20 @@ angular.module('openshiftCommonUI')
.filter('upperFirst', function() {
// Uppercase the first letter of a string (without making any other changes).
// Different than `capitalize` because it doesn't lowercase other letters.
return function(str) {
if (!str) {
return str;
}
return str.charAt(0).toUpperCase() + str.slice(1);
};
return _.upperFirst;
})
.filter('sentenceCase', function(camelToLowerFilter, upperFirstFilter) {
.filter('sentenceCase', function(camelToLowerFilter) {
// Converts a camel case string to sentence case
return function(str) {
if (!str) {
return str;
}
// Unfortunately, _.lowerCase() and _.upperFirst() aren't in our lodash version.
var lower = camelToLowerFilter(str);
return upperFirstFilter(lower);
return _.upperFirst(lower);
};
})
.filter('startCase', function () {
return function(str) {
if (!str) {
return str;
}
// https://lodash.com/docs#startCase
return _.startCase(str);
};
return _.startCase;
})
.filter('capitalize', function() {
return function(input) {
return _.capitalize(input);
};
return _.capitalize;
})
.filter('isMultiline', function() {
return function(str, ignoreTrailing) {
......@@ -1967,7 +1934,7 @@ angular.module('openshiftCommonUI')
.filter('size', function() {
return _.size;
})
.filter('hashSize', function($log) {
.filter('hashSize', function() {
return function(hash) {
if (!hash) {
return 0;
......@@ -1999,6 +1966,10 @@ angular.module('openshiftCommonUI')
})
.filter("getErrorDetails", function(upperFirstFilter) {
return function(result, capitalize) {
if (!result) {
return "";
}
var error = result.data || {};
if (error.message) {
return capitalize ? upperFirstFilter(error.message) : error.message;
......@@ -2194,19 +2165,14 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XXS:
return false; // Nothing is below xxs
break;
case WINDOW_SIZE_XS:
return window.innerWidth < BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth < BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth < BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth < BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......@@ -2216,16 +2182,12 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XS:
return window.innerWidth >= BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth >= BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth >= BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth >= BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......@@ -2315,7 +2277,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
};
var clearNotifications = function () {
_.take(notifications, 0);
notifications.length = 0;
};
var isNotificationPermanentlyHidden = function (notification) {
......
......@@ -1472,55 +1472,42 @@ angular.module('openshiftCommonServices')
angular.module('openshiftCommonUI')
.filter("alertStatus", function() {
return function (type) {
var status;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
status = 'alert-danger';
break;
return 'alert-danger';
case 'warning':
status = 'alert-warning';
break;
return 'alert-warning';
case 'success':
status = 'alert-success';
break;
return 'alert-success';
case 'normal':
status = 'alert-info';
break;
default:
status = 'alert-info';
return 'alert-info';
}
return status;
return 'alert-info';
};
})
.filter('alertIcon', function() {
return function (type) {
var icon;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
icon = 'pficon pficon-error-circle-o';
break;
return 'pficon pficon-error-circle-o';
case 'warning':
icon = 'pficon pficon-warning-triangle-o';
break;
return 'pficon pficon-warning-triangle-o';
case 'success':
icon = 'pficon pficon-ok';
break;
return 'pficon pficon-ok';
case 'normal':
icon = 'pficon pficon-info';
break;
default:
icon = 'pficon pficon-info';
return 'pficon pficon-info';
}
return icon;
return 'pficon pficon-info';
};
});
;'use strict';
......@@ -1751,24 +1738,24 @@ angular.module('openshiftCommonUI')
// color SVG images for. Depends on window.OPENSHIFT_CONSTANTS.LOGOS and
// window.OPENSHIFT_CONSTANTS.LOGO_BASE_URL, which is set by origin-web-console
// (or an extension).
.filter('imageForIconClass', ["isAbsoluteURLFilter", function(isAbsoluteURLFilter) {
.filter('imageForIconClass', ["$window", "isAbsoluteURLFilter", function($window, isAbsoluteURLFilter) {
return function(iconClass) {
if (!iconClass) {
return '';
}
var logoImage = _.get(window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
var logoImage = _.get($window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
if (!logoImage) {
return '';
}
// Make sure the logo base has a trailing slash.
var logoBaseUrl = _.get(window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
var logoBaseUrl = _.get($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
if (!logoBaseUrl || isAbsoluteURLFilter(logoImage)) {
return logoImage;
}
if (!logoBaseUrl.endsWith('/')) {
if (!_.endsWith(logoBaseUrl, '/')) {
logoBaseUrl += '/';
}
......@@ -1780,7 +1767,7 @@ angular.module('openshiftCommonUI')
angular.module('openshiftCommonUI')
.filter('isAbsoluteURL', function() {
return function(url) {
if (!url) {
if (!url || !_.isString(url)) {
return false;
}
var uri = new URI(url);
......@@ -2033,12 +2020,7 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayName;
}
var serviceClassExternalName = _.get(serviceClass, 'spec.externalName');
if (serviceClassExternalName) {
return serviceClassExternalName;
}
return _.get(serviceClass, 'metadata.name');
return _.get(serviceClass, 'spec.externalName');
};
})
.filter('serviceInstanceDisplayName', ["serviceClassDisplayNameFilter", function(serviceClassDisplayNameFilter) {
......@@ -2047,6 +2029,11 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayNameFilter(serviceClass);
}
var externalServiceClassName = _.get(instance, 'spec.externalClusterServiceClassName');
if (externalServiceClassName) {
return externalServiceClassName;
}
return _.get(instance, 'metadata.name');
};
}])
......@@ -2071,7 +2058,7 @@ angular.module('openshiftCommonUI')
.filter('camelToLower', function() {
return function(str) {
if (!str) {
return str;
return '';
}
// Use the special logic in _.startCase to handle camel case strings, kebab
......@@ -2082,40 +2069,20 @@ angular.module('openshiftCommonUI')
.filter('upperFirst', function() {
// Uppercase the first letter of a string (without making any other changes).
// Different than `capitalize` because it doesn't lowercase other letters.
return function(str) {
if (!str) {
return str;
}
return str.charAt(0).toUpperCase() + str.slice(1);
};
return _.upperFirst;
})
.filter('sentenceCase', ["camelToLowerFilter", "upperFirstFilter", function(camelToLowerFilter, upperFirstFilter) {
.filter('sentenceCase', ["camelToLowerFilter", function(camelToLowerFilter) {
// Converts a camel case string to sentence case
return function(str) {
if (!str) {
return str;
}
// Unfortunately, _.lowerCase() and _.upperFirst() aren't in our lodash version.
var lower = camelToLowerFilter(str);
return upperFirstFilter(lower);
return _.upperFirst(lower);
};
}])
.filter('startCase', function () {
return function(str) {
if (!str) {
return str;
}
// https://lodash.com/docs#startCase
return _.startCase(str);
};
return _.startCase;
})
.filter('capitalize', function() {
return function(input) {
return _.capitalize(input);
};
return _.capitalize;
})
.filter('isMultiline', function() {
return function(str, ignoreTrailing) {
......@@ -2177,14 +2144,14 @@ angular.module('openshiftCommonUI')
.filter('size', function() {
return _.size;
})
.filter('hashSize', ["$log", function($log) {
.filter('hashSize', function() {
return function(hash) {
if (!hash) {
return 0;
}
return Object.keys(hash).length;
};
}])
})
// Wraps _.filter. Works with hashes, unlike ngFilter, which only works
// with arrays.
.filter('filterCollection', function() {
......@@ -2209,6 +2176,10 @@ angular.module('openshiftCommonUI')
})
.filter("getErrorDetails", ["upperFirstFilter", function(upperFirstFilter) {
return function(result, capitalize) {
if (!result) {
return "";
}
var error = result.data || {};
if (error.message) {
return capitalize ? upperFirstFilter(error.message) : error.message;
......@@ -5896,19 +5867,14 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XXS:
return false; // Nothing is below xxs
break;
case WINDOW_SIZE_XS:
return window.innerWidth < BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth < BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth < BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth < BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......@@ -5918,16 +5884,12 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XS:
return window.innerWidth >= BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth >= BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth >= BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth >= BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......@@ -6017,7 +5979,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
};
var clearNotifications = function () {
_.take(notifications, 0);
notifications.length = 0;
};
var isNotificationPermanentlyHidden = function (notification) {
......
......@@ -642,53 +642,37 @@ resource:"templates"
}
}), angular.module("openshiftCommonUI").filter("alertStatus", function() {
return function(type) {
var status;
switch (type.toLowerCase()) {
switch (type = type || "", type.toLowerCase()) {
case "error":
status = "alert-danger";
break;
return "alert-danger";
case "warning":
status = "alert-warning";
break;
return "alert-warning";
case "success":
status = "alert-success";
break;
return "alert-success";
case "normal":
status = "alert-info";
break;
default:
status = "alert-info";
return "alert-info";
}
return status;
return "alert-info";
};
}).filter("alertIcon", function() {
return function(type) {
var icon;
switch (type.toLowerCase()) {
switch (type = type || "", type.toLowerCase()) {
case "error":
icon = "pficon pficon-error-circle-o";
break;
return "pficon pficon-error-circle-o";
case "warning":
icon = "pficon pficon-warning-triangle-o";
break;
return "pficon pficon-warning-triangle-o";
case "success":
icon = "pficon pficon-ok";
break;
return "pficon pficon-ok";
case "normal":
icon = "pficon pficon-info";
break;
default:
icon = "pficon pficon-info";
return "pficon pficon-info";
}
return icon;
return "pficon pficon-info";
};
}), angular.module("openshiftCommonUI").filter("annotationName", function() {
var annotationMap = {
......@@ -787,17 +771,17 @@ return _.isRegExp(keyword) ? keyword.source :_.escapeRegExp(keyword);
}).join("|"), result = "", lastIndex = 0, flags = caseSensitive ? "g" :"ig", regex = new RegExp(source, flags); null !== (match = regex.exec(str)); ) lastIndex < match.index && (result += _.escape(str.substring(lastIndex, match.index))), result += "<mark>" + _.escape(match[0]) + "</mark>", lastIndex = regex.lastIndex;
return lastIndex < str.length && (result += _.escape(str.substring(lastIndex))), result;
};
} ]), angular.module("openshiftCommonUI").filter("imageForIconClass", [ "isAbsoluteURLFilter", function(isAbsoluteURLFilter) {
} ]), angular.module("openshiftCommonUI").filter("imageForIconClass", [ "$window", "isAbsoluteURLFilter", function($window, isAbsoluteURLFilter) {
return function(iconClass) {
if (!iconClass) return "";
var logoImage = _.get(window, [ "OPENSHIFT_CONSTANTS", "LOGOS", iconClass ]);
var logoImage = _.get($window, [ "OPENSHIFT_CONSTANTS", "LOGOS", iconClass ]);
if (!logoImage) return "";
var logoBaseUrl = _.get(window, "OPENSHIFT_CONSTANTS.LOGO_BASE_URL");
return !logoBaseUrl || isAbsoluteURLFilter(logoImage) ? logoImage :(logoBaseUrl.endsWith("/") || (logoBaseUrl += "/"), logoBaseUrl + logoImage);
var logoBaseUrl = _.get($window, "OPENSHIFT_CONSTANTS.LOGO_BASE_URL");
return !logoBaseUrl || isAbsoluteURLFilter(logoImage) ? logoImage :(_.endsWith(logoBaseUrl, "/") || (logoBaseUrl += "/"), logoBaseUrl + logoImage);
};
} ]), angular.module("openshiftCommonUI").filter("isAbsoluteURL", function() {
return function(url) {
if (!url) return !1;
if (!url || !_.isString(url)) return !1;
var uri = new URI(url), protocol = uri.protocol();
return uri.is("absolute") && ("http" === protocol || "https" === protocol);
};
......@@ -916,13 +900,13 @@ return !!annotationFilter(deployment, "deploymentConfig");
} ]).filter("serviceClassDisplayName", function() {
return function(serviceClass) {
var serviceClassDisplayName = _.get(serviceClass, "spec.externalMetadata.displayName");
if (serviceClassDisplayName) return serviceClassDisplayName;
var serviceClassExternalName = _.get(serviceClass, "spec.externalName");
return serviceClassExternalName ? serviceClassExternalName :_.get(serviceClass, "metadata.name");
return serviceClassDisplayName ? serviceClassDisplayName :_.get(serviceClass, "spec.externalName");
};
}).filter("serviceInstanceDisplayName", [ "serviceClassDisplayNameFilter", function(serviceClassDisplayNameFilter) {
return function(instance, serviceClass) {
return serviceClass ? serviceClassDisplayNameFilter(serviceClass) :_.get(instance, "metadata.name");
if (serviceClass) return serviceClassDisplayNameFilter(serviceClass);
var externalServiceClassName = _.get(instance, "spec.externalClusterServiceClassName");
return externalServiceClassName ? externalServiceClassName :_.get(instance, "metadata.name");
};
} ]).filter("serviceInstanceStatus", [ "isServiceInstanceReadyFilter", function(isServiceInstanceReadyFilter) {
return function(instance) {
......@@ -934,26 +918,19 @@ return instanceError ? status = "Failed" :isServiceInstanceReadyFilter(instance)
};
} ]), angular.module("openshiftCommonUI").filter("camelToLower", function() {
return function(str) {
return str ? _.startCase(str).toLowerCase() :str;
return str ? _.startCase(str).toLowerCase() :"";
};
}).filter("upperFirst", function() {
return _.upperFirst;
}).filter("sentenceCase", [ "camelToLowerFilter", function(camelToLowerFilter) {
return function(str) {
return str ? str.charAt(0).toUpperCase() + str.slice(1) :str;
};
}).filter("sentenceCase", [ "camelToLowerFilter", "upperFirstFilter", function(camelToLowerFilter, upperFirstFilter) {
return function(str) {
if (!str) return str;
var lower = camelToLowerFilter(str);
return upperFirstFilter(lower);
return _.upperFirst(lower);
};
} ]).filter("startCase", function() {
return function(str) {
return str ? _.startCase(str) :str;
};
return _.startCase;
}).filter("capitalize", function() {
return function(input) {
return _.capitalize(input);
};
return _.capitalize;
}).filter("isMultiline", function() {
return function(str, ignoreTrailing) {
if (!str) return !1;
......@@ -978,11 +955,11 @@ return truncated;
return _.toArray;
}).filter("size", function() {
return _.size;
}).filter("hashSize", [ "$log", function($log) {
}).filter("hashSize", function() {
return function(hash) {
return hash ? Object.keys(hash).length :0;
};
} ]).filter("filterCollection", function() {
}).filter("filterCollection", function() {
return function(collection, predicate) {
return collection && predicate ? _.filter(collection, predicate) :collection;
};
......@@ -994,6 +971,7 @@ return prefix + randomString;
};
}).filter("getErrorDetails", [ "upperFirstFilter", function(upperFirstFilter) {
return function(result, capitalize) {
if (!result) return "";
var error = result.data || {};
if (error.message) return capitalize ? upperFirstFilter(error.message) :error.message;
var status = result.status || error.status;
......@@ -2673,7 +2651,7 @@ notification.id === notificationID && (notification.hidden = !0);
}, getNotifications = function() {
return notifications;
}, clearNotifications = function() {
_.take(notifications, 0);
notifications.length = 0;
}, isNotificationPermanentlyHidden = function(notification) {
if (!notification.id) return !1;
var key = notificationHiddenKey(notification.id, notification.namespace);
......
......@@ -2,54 +2,41 @@
angular.module('openshiftCommonUI')
.filter("alertStatus", function() {
return function (type) {
var status;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
status = 'alert-danger';
break;
return 'alert-danger';
case 'warning':
status = 'alert-warning';
break;
return 'alert-warning';
case 'success':
status = 'alert-success';
break;
return 'alert-success';
case 'normal':
status = 'alert-info';
break;
default:
status = 'alert-info';
return 'alert-info';
}
return status;
return 'alert-info';
};
})
.filter('alertIcon', function() {
return function (type) {
var icon;
return function(type) {
type = type || '';
// API events have just two types: Normal, Warning
// our notifications have four: info, success, error, and warning
switch(type.toLowerCase()) {
case 'error':
icon = 'pficon pficon-error-circle-o';
break;
return 'pficon pficon-error-circle-o';
case 'warning':
icon = 'pficon pficon-warning-triangle-o';
break;
return 'pficon pficon-warning-triangle-o';
case 'success':
icon = 'pficon pficon-ok';
break;
return 'pficon pficon-ok';
case 'normal':
icon = 'pficon pficon-info';
break;
default:
icon = 'pficon pficon-info';
return 'pficon pficon-info';
}
return icon;
return 'pficon pficon-info';
};
});
......@@ -5,24 +5,24 @@ angular.module('openshiftCommonUI')
// color SVG images for. Depends on window.OPENSHIFT_CONSTANTS.LOGOS and
// window.OPENSHIFT_CONSTANTS.LOGO_BASE_URL, which is set by origin-web-console
// (or an extension).
.filter('imageForIconClass', function(isAbsoluteURLFilter) {
.filter('imageForIconClass', function($window, isAbsoluteURLFilter) {
return function(iconClass) {
if (!iconClass) {
return '';
}
var logoImage = _.get(window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
var logoImage = _.get($window, ['OPENSHIFT_CONSTANTS', 'LOGOS', iconClass]);
if (!logoImage) {
return '';
}
// Make sure the logo base has a trailing slash.
var logoBaseUrl = _.get(window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
var logoBaseUrl = _.get($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL');
if (!logoBaseUrl || isAbsoluteURLFilter(logoImage)) {
return logoImage;
}
if (!logoBaseUrl.endsWith('/')) {
if (!_.endsWith(logoBaseUrl, '/')) {
logoBaseUrl += '/';
}
......
......@@ -3,7 +3,7 @@
angular.module('openshiftCommonUI')
.filter('isAbsoluteURL', function() {
return function(url) {
if (!url) {
if (!url || !_.isString(url)) {
return false;
}
var uri = new URI(url);
......
......@@ -181,12 +181,7 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayName;
}
var serviceClassExternalName = _.get(serviceClass, 'spec.externalName');
if (serviceClassExternalName) {
return serviceClassExternalName;
}
return _.get(serviceClass, 'metadata.name');
return _.get(serviceClass, 'spec.externalName');
};
})
.filter('serviceInstanceDisplayName', function(serviceClassDisplayNameFilter) {
......@@ -195,6 +190,11 @@ angular.module('openshiftCommonUI')
return serviceClassDisplayNameFilter(serviceClass);
}
var externalServiceClassName = _.get(instance, 'spec.externalClusterServiceClassName');
if (externalServiceClassName) {
return externalServiceClassName;
}
return _.get(instance, 'metadata.name');
};
})
......
......@@ -3,7 +3,7 @@ angular.module('openshiftCommonUI')
.filter('camelToLower', function() {
return function(str) {
if (!str) {
return str;
return '';
}
// Use the special logic in _.startCase to handle camel case strings, kebab
......@@ -14,40 +14,20 @@ angular.module('openshiftCommonUI')
.filter('upperFirst', function() {
// Uppercase the first letter of a string (without making any other changes).
// Different than `capitalize` because it doesn't lowercase other letters.
return function(str) {
if (!str) {
return str;
}
return str.charAt(0).toUpperCase() + str.slice(1);
};
return _.upperFirst;
})
.filter('sentenceCase', function(camelToLowerFilter, upperFirstFilter) {
.filter('sentenceCase', function(camelToLowerFilter) {
// Converts a camel case string to sentence case
return function(str) {
if (!str) {
return str;
}
// Unfortunately, _.lowerCase() and _.upperFirst() aren't in our lodash version.
var lower = camelToLowerFilter(str);
return upperFirstFilter(lower);
return _.upperFirst(lower);
};
})
.filter('startCase', function () {
return function(str) {
if (!str) {
return str;
}
// https://lodash.com/docs#startCase
return _.startCase(str);
};
return _.startCase;
})
.filter('capitalize', function() {
return function(input) {
return _.capitalize(input);
};
return _.capitalize;
})
.filter('isMultiline', function() {
return function(str, ignoreTrailing) {
......
......@@ -7,7 +7,7 @@ angular.module('openshiftCommonUI')
.filter('size', function() {
return _.size;
})
.filter('hashSize', function($log) {
.filter('hashSize', function() {
return function(hash) {
if (!hash) {
return 0;
......@@ -39,6 +39,10 @@ angular.module('openshiftCommonUI')
})
.filter("getErrorDetails", function(upperFirstFilter) {
return function(result, capitalize) {
if (!result) {
return "";
}
var error = result.data || {};
if (error.message) {
return capitalize ? upperFirstFilter(error.message) : error.message;
......
......@@ -40,19 +40,14 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XXS:
return false; // Nothing is below xxs
break;
case WINDOW_SIZE_XS:
return window.innerWidth < BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth < BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth < BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth < BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......@@ -62,16 +57,12 @@ angular.module("openshiftCommonUI")
switch(size) {
case WINDOW_SIZE_XS:
return window.innerWidth >= BREAKPOINTS.screenXsMin;
break;
case WINDOW_SIZE_SM:
return window.innerWidth >= BREAKPOINTS.screenSmMin;
break;
case WINDOW_SIZE_MD:
return window.innerWidth >= BREAKPOINTS.screenMdMin;
break;
case WINDOW_SIZE_LG:
return window.innerWidth >= BREAKPOINTS.screenLgMin;
break;
default:
return true;
}
......
......@@ -49,7 +49,7 @@ angular.module('openshiftCommonUI').provider('NotificationsService', function()
};
var clearNotifications = function () {
_.take(notifications, 0);
notifications.length = 0;
};
var isNotificationPermanentlyHidden = function (notification) {
......
......@@ -48,7 +48,7 @@ module.exports = function(config) {
// use dots reporter, as travis terminal does not support escaping sequences
// possible values: 'dots', 'progress'
// CLI --reporters progress
reporters: ['progress', 'junit'],
reporters: ['progress', 'junit', 'coverage'],
junitReporter: {
// will be resolved to basePath (in the same way as files/exclude patterns)
......@@ -58,7 +58,6 @@ module.exports = function(config) {
// web server port
port: 8443,
colors: true,
// level of logging
......@@ -90,6 +89,14 @@ module.exports = function(config) {
// report which specs are slower than 500ms
// CLI --report-slower-than 500
reportSlowerThan: 500
reportSlowerThan: 500,
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
'src/filters/*.js': ['coverage'],
'src/services/*.js': ['coverage'],
'src/ui-services/*.js': ['coverage']
}
});
};
describe("Filter: alertIcon", function() {
'use strict';
var alertIconFilter;
beforeEach(inject(function (_alertIconFilter_) {
alertIconFilter = _alertIconFilter_;
}));
var tc = [
['error', 'pficon pficon-error-circle-o'],
['Error', 'pficon pficon-error-circle-o'],
['ERROR', 'pficon pficon-error-circle-o'],
['warning', 'pficon pficon-warning-triangle-o'],
['Warning', 'pficon pficon-warning-triangle-o'],
['WARNING', 'pficon pficon-warning-triangle-o'],
['success', 'pficon pficon-ok'],
['Success', 'pficon pficon-ok'],
['SUCCESS', 'pficon pficon-ok'],
['normal', 'pficon pficon-info'],
['unknown', 'pficon pficon-info'],
['', 'pficon pficon-info'],
[undefined, 'pficon pficon-info'],
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = alertIconFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: alertStatus", function() {
'use strict';
var alertStatusFilter;
beforeEach(inject(function (_alertStatusFilter_) {
alertStatusFilter = _alertStatusFilter_;
}));
var tc = [
['error', 'alert-danger'],
['Error', 'alert-danger'],
['ERROR', 'alert-danger'],
['warning', 'alert-warning'],
['Warning', 'alert-warning'],
['WARNING', 'alert-warning'],
['success', 'alert-success'],
['Success', 'alert-success'],
['SUCCESS', 'alert-success'],
['normal', 'alert-info'],
['Normal', 'alert-info'],
['', 'alert-info'],
[undefined, 'alert-info'],
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = alertStatusFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: camelToLower", function() {
'use strict';
var camelToLowerFilter;
beforeEach(inject(function (_camelToLowerFilter_) {
camelToLowerFilter = _camelToLowerFilter_;
}));
var tc = [
['FooBar', 'foo bar'],
['fooBar', 'foo bar'],
['Foo', 'foo'],
['foo-bar', 'foo bar'],
['FooBarBaz', 'foo bar baz'],
['', ''],
[null, ''],
[undefined, '']
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = camelToLowerFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: capitalize", function() {
'use strict';
var capitalizeFilter;
beforeEach(inject(function (_capitalizeFilter_) {
capitalizeFilter = _capitalizeFilter_;
}));
var tc = [
['FooBar', 'Foobar'],
['fooBar', 'Foobar'],
['foo', 'Foo'],
['Foo', 'Foo'],
['foo-bar', 'Foo-bar'],
['Foo Bar Baz', 'Foo bar baz'],
['', ''],
[null, ''],
[undefined, '']
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = capitalizeFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: description", function() {
'use strict';
var descriptionFilter;
beforeEach(inject(function (_descriptionFilter_) {
descriptionFilter = _descriptionFilter_;
}));
it('should return the description for the openshift.io/description annotation', function() {
var testDescription = 'My project.';
var result = descriptionFilter({
metadata: {
annotations: {
'openshift.io/description': testDescription
}
}
});
expect(result).toEqual(testDescription);
});
it('should return the description for the kubernetes.io/description annotation', function() {
var testDescription = 'My project.';
var result = descriptionFilter({
metadata: {
annotations: {
'kubernetes.io/description': testDescription
}
}
});
expect(result).toEqual(testDescription);
});
it('should return the description for the description annotation with no namespace', function() {
var testDescription = 'My project.';
var result = descriptionFilter({
metadata: {
annotations: {
'description': testDescription
}
}
});
expect(result).toEqual(testDescription);
});
it('should prefer the openshift.io/description annotation', function() {
var testDescription = 'My project.';
var result = descriptionFilter({
metadata: {
annotations: {
'description': 'not this one',
'kubernetes.io/description': 'or this one',
'openshift.io/description': testDescription
}
}
});
expect(result).toEqual(testDescription);
});
it('should prefer the kubernetes.io/description annotation over the one with no namespace', function() {
var testDescription = 'My project.';
var result = descriptionFilter({
metadata: {
annotations: {
'description': 'not this one',
'kubernetes.io/description': testDescription
}
}
});
expect(result).toEqual(testDescription);
});
it('should return the null if no description annotation', function() {
var object = {
metadata: {
name: 'my-new-object'
}
};
var result = descriptionFilter(object);
expect(result).toBeNull();
});
it('should return null if input is null or undefined', function() {
var result = descriptionFilter(null);
expect(result).toBeNull();
result = descriptionFilter();
expect(result).toBeNull();
});
});
describe("Filter: displayName", function() {
'use strict';
var displayNameFilter;
beforeEach(inject(function (_displayNameFilter_) {
displayNameFilter = _displayNameFilter_;
}));
it('should return metadata.name if no display name annotation', function() {
var name = 'my-project';
var result = displayNameFilter({
metadata: {
name: name
}
});
expect(result).toEqual(name);
});
it('should return null if no display name annotation and annotationOnly is true', function() {
var name = 'my-object';
var result = displayNameFilter({
metadata: {
name: name
}
}, true);
expect(result).toBeNull();
});
it('should return the openshift.io/display-name annotation value', function() {
var displayName = 'My Project';
var object = {
metadata: {
name: name,
annotations: {
'openshift.io/display-name': displayName
}
}
};
var result = displayNameFilter(object);
expect(result).toEqual(displayName);
// Check that the result is the same if specifying annotationOnly.
result = displayNameFilter(object, true);
expect(result).toEqual(displayName);
});
it('should return the null if input is null, undefined, or empty', function() {
var result = displayNameFilter(null);
expect(result).toBeNull();
result = displayNameFilter();
expect(result).toBeNull();
result = displayNameFilter({});
expect(result).toBeNull();
});
});
describe("Filter: getErrorDetails", function() {
'use strict';
var getErrorDetailsFilter;
beforeEach(inject(function (_getErrorDetailsFilter_) {
getErrorDetailsFilter = _getErrorDetailsFilter_;
}));
var mockError = {
data: {
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "project.project.openshift.io \"openshift-project\" is forbidden: cannot request a project starting with \"openshift-\"",
"reason": "Forbidden",
"details": {
"name": "openshift-project",
"group": "project.openshift.io",
"kind": "project"
},
"code": 403
},
status: 403
};
it('should return the error message', function() {
var result = getErrorDetailsFilter(mockError);
expect(result).toEqual(mockError.data.message);
});
it('should captilize the message when asked', function() {
var result = getErrorDetailsFilter(mockError, true);
expect(result).toEqual(_.upperFirst(mockError.data.message));
});
it('should return the status code if no message', function() {
var error = angular.copy(mockError);
delete error.data.message;
var result = getErrorDetailsFilter(error);
expect(result).toEqual('Status: 403');
});
it('should return the empty string if no message or status', function() {
var result = getErrorDetailsFilter({});
expect(result).toEqual('');
});
it('should return the empty string if no result', function() {
var result = getErrorDetailsFilter();
expect(result).toEqual('');
});
});
describe("Filter: highlightKeywords", function() {
'use strict';
var highlightKeywordsFilter, KeywordService;
beforeEach(inject(function (_highlightKeywordsFilter_, _KeywordService_) {
highlightKeywordsFilter = _highlightKeywordsFilter_;
KeywordService = _KeywordService_;
}));
it('should return escaped HTML', function() {
var original = 'test <script>alert("test")</sciprt>';
var result = highlightKeywordsFilter(original, [], false);
expect(result).not.toContain('<script>');
var keywords = KeywordService.generateKeywords('test');
result = highlightKeywordsFilter(original, keywords, false);
expect(result).not.toContain('<script>');
});
it('should mark keywords', function() {
var original = 'my test value';
var keywords = KeywordService.generateKeywords('test');
var result = highlightKeywordsFilter(original, keywords, false);
expect(result).toContain('<mark>test</mark>');
});
it('should mark multiple keywords', function() {
var original = 'foo: and bar';
var keywords = KeywordService.generateKeywords('foo bar baz');
var result = highlightKeywordsFilter(original, keywords, false);
expect(result).toContain('<mark>foo</mark>');
expect(result).toContain('<mark>bar</mark>');
});
it('should not add mark tags when no matches', function() {
var original = 'foo: and bar';
var keywords = KeywordService.generateKeywords('no matches');
var result = highlightKeywordsFilter(original, keywords, false);
expect(result).not.toContain('<mark>');
});
it('should handle null, undefined, and empty values', function() {
var result = highlightKeywordsFilter(null);
expect(result).toBeNull();
result = highlightKeywordsFilter();
expect(result).toBeUndefined();
result = highlightKeywordsFilter('');
expect(result).toBe('');
});
});
describe("Filter: humanizeKind", function() {
'use strict';
var humanizeKindFilter;
beforeEach(inject(function (_humanizeKindFilter_) {
humanizeKindFilter = _humanizeKindFilter_;
}));
it('should return a lowercase display kind', function() {
var result = humanizeKindFilter('DeploymentConfig');
expect(result).toEqual('deployment config');
});
it('should return a title case display kind', function() {
var result = humanizeKindFilter('DeploymentConfig', true);
expect(result).toEqual('Deployment Config');
});
it('should special case ServiceInstance as "provisioned service"', function() {
var result = humanizeKindFilter('ServiceInstance');
expect(result).toEqual('provisioned service');
result = humanizeKindFilter('ServiceInstance', true);
expect(result).toEqual('Provisioned Service');
});
it('should return the original value if null, undefined, or empty', function() {
var result = humanizeKindFilter(null);
expect(result).toBeNull();
result = humanizeKindFilter();
expect(result).toBeUndefined();
result = humanizeKindFilter('');
expect(result).toEqual('');
});
});
describe("Filter: imageForIconClass", function() {
'use strict';
var $window;
var OPENSHIFT_CONSTANTS;
var imageForIconClassFilter;
beforeEach(function() {
inject(function (_imageForIconClassFilter_, _$window_) {
imageForIconClassFilter = _imageForIconClassFilter_;
$window = _$window_;
});
OPENSHIFT_CONSTANTS = $window.OPENSHIFT_CONSTANTS;
});
afterEach(function () {
// Restore original constants value.
$window.OPENSHIFT_CONSTANTS = OPENSHIFT_CONSTANTS;
});
it('should find the image URL for the icon class', function() {
_.set($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL', 'images/logos/');
_.set($window, 'OPENSHIFT_CONSTANTS.LOGOS', {
'icon_jenkins': 'icon_jenkins.svg'
});
var image = imageForIconClassFilter('icon_jenkins');
expect(image).toEqual('images/logos/icon_jenkins.svg');
});
it('should find the image URL for the icon class with no base URL', function() {
_.set($window, 'OPENSHIFT_CONSTANTS.LOGOS', {
'icon_jenkins': 'icon_jenkins.svg'
});
delete $window.OPENSHIFT_CONSTANTS.LOGO_BASE_URL;
var image = imageForIconClassFilter('icon_jenkins');
expect(image).toEqual('icon_jenkins.svg');
});
it('should not prepend base URL to an absolute URL', function() {
_.set($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL', 'images/logos/');
_.set($window, 'OPENSHIFT_CONSTANTS.LOGOS', {
'icon_jenkins': 'http://example.com/images/logos/icon_jenkins.svg'
});
var image = imageForIconClassFilter('icon_jenkins');
expect(image).toEqual('http://example.com/images/logos/icon_jenkins.svg');
});
it('should return the empty string for unrecognized icon classes', function() {
_.set($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL', 'images/logos/');
_.set($window, 'OPENSHIFT_CONSTANTS.LOGOS', {
'icon_jenkins': 'icon_jenkins.svg'
});
var image = imageForIconClassFilter('icon_unrecognized');
expect(image).toEqual('');
});
it('should return the empty string for falsey values', function() {
_.set($window, 'OPENSHIFT_CONSTANTS.LOGO_BASE_URL', 'images/logos/');
_.set($window, 'OPENSHIFT_CONSTANTS.LOGOS', {
'icon_jenkins': 'icon_jenkins.svg'
});
var image = imageForIconClassFilter('');
expect(image).toEqual('');
image = imageForIconClassFilter(null);
expect(image).toEqual('');
image = imageForIconClassFilter();
expect(image).toEqual('');
});
it('should not fail if no OPENSHIFT_CONSTANTS', function() {
delete $window.OPENSHIFT_CONSTANTS;
var image = imageForIconClassFilter('icon_jenkins');
expect(image).toEqual('');
});
});
describe("Filter: isAbsoluteURL", function() {
'use strict';
var isAbsoluteURLFilter;
beforeEach(inject(function (_isAbsoluteURLFilter_) {
isAbsoluteURLFilter = _isAbsoluteURLFilter_;
}));
it('should recognize an absolute URL with http protocol', function() {
var isAbsolute = isAbsoluteURLFilter('http://www.example.com/console');
expect(isAbsolute).toBe(true);
});
it('should recognize an absolute URL with https protocol', function() {
var isAbsolute = isAbsoluteURLFilter('https://www.example.com/console');
expect(isAbsolute).toBe(true);
});
it('should not consider a relative URL to be absolute', function() {
var isAbsolute = isAbsoluteURLFilter('foo');
expect(isAbsolute).toBe(false);
isAbsolute = isAbsoluteURLFilter('foo/bar');
expect(isAbsolute).toBe(false);
isAbsolute = isAbsoluteURLFilter('foo/bar/baz?param=false#some-id');
expect(isAbsolute).toBe(false);
});
it('should not consider non-HTTP URLs to be absolute', function() {
var isAbsolute = isAbsoluteURLFilter('git@github.com:openshift/origin-web-console.git');
expect(isAbsolute).toBe(false);
isAbsolute = isAbsoluteURLFilter('ftp://ftp.example.com');
expect(isAbsolute).toBe(false);
});
it('should not consider an empty string to be absolute', function() {
var isAbsolute = isAbsoluteURLFilter('');
expect(isAbsolute).toBe(false);
});
it('should not consider null or undefined to be absolute', function() {
var isAbsolute = isAbsoluteURLFilter(null);
expect(isAbsolute).toBe(false);
isAbsolute = isAbsoluteURLFilter();
expect(isAbsolute).toBe(false);
});
it('should not consider invalid types to be absolute', function() {
var isAbsolute = isAbsoluteURLFilter(1);
expect(isAbsolute).toBe(false);
isAbsolute = isAbsoluteURLFilter(true);
expect(isAbsolute).toBe(false);
});
});
describe("Filter: isMultiline", function() {
'use strict';
var isMultilineFilter;
beforeEach(inject(function (_isMultilineFilter_) {
isMultilineFilter = _isMultilineFilter_;
}));
var tc = [
['foo', false, false],
['foo\nbar', false, true],
['foo\nbar', true, true],
['foo\rbar', false, true],
['foo\rbar', true, true],
['foo\nbar\n', true, true],
['foo\rbar\r', true, true],
['foo\n', false, true],
['foo\n', true, false],
['foo\r', false, true],
['foo\r', true, false],
['', false, false],
['', true, false],
[undefined, false, false],
[undefined, true, false]
];
_.each(tc, _.spread(function(input, ignoreTrailing, expected) {
it('should result in ' + expected +
' when called with ' + JSON.stringify(input) +
' (ignore trailing newline: ' + ignoreTrailing + ')', function() {
var actual = isMultilineFilter(input, ignoreTrailing);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: isNewerResource", function() {
'use strict';
var isNewerResourceFilter;
beforeEach(inject(function (_isNewerResourceFilter_) {
isNewerResourceFilter = _isNewerResourceFilter_;
}));
var olderDate = new Date('Wed, 14 Jun 2017 00:00:00 PDT').toISOString();
var newerDate = new Date('Thu, 15 Jun 2017 00:00:00 PDT').toISOString();
var mockObjectWithDate = function(dateString) {
return {
metadata: {
creationTimestamp: dateString
}
};
};
it('should determine one resource is newer than another', function() {
var older = mockObjectWithDate(olderDate);
var newer = mockObjectWithDate(newerDate);
var result = isNewerResourceFilter(newer, older);
expect(result).toBe(true);
// Reverse order of arguments.
result = isNewerResourceFilter(older, newer);
expect(result).toBe(false);
});
it('should return true when other date is undefined', function() {
var result = isNewerResourceFilter(mockObjectWithDate(newerDate));
expect(result).toBe(true);
});
it('should return false when candidate date is undefined', function() {
var result = isNewerResourceFilter();
expect(result).toBe(false);
var older = mockObjectWithDate(olderDate);
result = isNewerResourceFilter(undefined, older);
expect(result).toBe(false);
});
it('should return false when dates are the same', function() {
var left = mockObjectWithDate(olderDate);
var right = mockObjectWithDate(olderDate);
var result = isNewerResourceFilter(left, right);
expect(result).toBe(false);
});
it('should handle missing creation timestamps', function() {
var result = isNewerResourceFilter({}, {});
expect(result).toBe(false);
var newer = mockObjectWithDate(newerDate);
result = isNewerResourceFilter(newer, {});
expect(result).toBe(true);
result = isNewerResourceFilter({}, newer);
expect(result).toBe(false);
});
});
describe("Filter: isServiceInstanceFailed", function() {
'use strict';
var isServiceInstanceFailedFilter;
var mockServiceInstance = {
"apiVersion": "servicecatalog.k8s.io/v1beta1",
"kind": "ServceInstance",
"metadata": {
"name": "mariadb-persistent-6q4zn",
"namespace": "test",
"uid": "6a31b3ce-aec9-11e7-bae6-0242ac110002",
},
"spec": {
"externalClusterServiceClassName": "mariadb-persistent",
"externalClusterServicePlanName": "default",
"clusterServiceClassRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "581f692a-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "20"
},
"clusterServicePlanRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "5704c949-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "8"
},
"parametersFrom": [
{
"secretKeyRef": {
"name": "mariadb-persistent-parameters-s6zzf",
"key": "parameters"
}
}
],
"externalID": "8066697b-530b-486d-a6e2-5ff2b8d8febb",
"updateRequests": 0
},
"status": {
"conditions": []
}
};
var failedCondition = {
"type": "Failed",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionCallFailed",
"message": 'Provision call failed: ServiceInstance "test/mariadb-persistent-6q4zn": Error provisioning: "secrets \"mariadb\" already exists\nservices \"mariadb\" already exists\npersistentvolumeclaims \"mariadb\" already exists\ndeploymentconfigs \"mariadb\" already exists"'
};
beforeEach(inject(function (_isServiceInstanceFailedFilter_) {
isServiceInstanceFailedFilter = _isServiceInstanceFailedFilter_;
}));
it('should return true when the instance is failed', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(failedCondition);
var result = isServiceInstanceFailedFilter(serviceInstance);
expect(result).toBe(true);
});
it('should return false when there are no status conditions', function() {
var result = isServiceInstanceFailedFilter(mockServiceInstance);
expect(result).toBe(false);
});
it('should return false when a different status condition is set', function() {
var serviceInstance = angular.copy(mockServiceInstance);
var condition = angular.copy(failedCondition);
condition.type = "AnotherCondition";
serviceInstance.status.conditions.push(condition);
var result = isServiceInstanceFailedFilter(serviceInstance);
expect(result).toBe(false);
});
});
describe("Filter: isServiceInstanceReady", function() {
'use strict';
var isServiceInstanceReadyFilter;
var mockServiceInstance = {
"apiVersion": "servicecatalog.k8s.io/v1beta1",
"kind": "ServceInstance",
"metadata": {
"name": "mariadb-persistent-6q4zn",
"namespace": "test",
"uid": "6a31b3ce-aec9-11e7-bae6-0242ac110002",
},
"spec": {
"externalClusterServiceClassName": "mariadb-persistent",
"externalClusterServicePlanName": "default",
"clusterServiceClassRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "581f692a-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "20"
},
"clusterServicePlanRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "5704c949-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "8"
},
"parametersFrom": [
{
"secretKeyRef": {
"name": "mariadb-persistent-parameters-s6zzf",
"key": "parameters"
}
}
],
"externalID": "8066697b-530b-486d-a6e2-5ff2b8d8febb",
"updateRequests": 0
},
"status": {
"conditions": []
}
};
var readyCondition = {
"type": "Ready",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionedSuccessfully",
"message": "The instance was provisioned successfully"
};
var pendingCondition = {
"type": "Ready",
"status": "False",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "Provisioning",
"message": "The instance is being provisioned asynchronously"
};
beforeEach(inject(function (_isServiceInstanceReadyFilter_) {
isServiceInstanceReadyFilter = _isServiceInstanceReadyFilter_;
}));
it('should return true when the instance is ready', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(readyCondition);
var result = isServiceInstanceReadyFilter(serviceInstance);
expect(result).toBe(true);
});
it('should return false when the instance is not ready', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(pendingCondition);
var result = isServiceInstanceReadyFilter(serviceInstance);
expect(result).toBe(false);
});
it('should return false when there are no status conditions', function() {
var result = isServiceInstanceReadyFilter(mockServiceInstance);
expect(result).toBe(false);
});
it('should return false when a different status condition is set', function() {
var serviceInstance = angular.copy(mockServiceInstance);
var condition = angular.copy(readyCondition);
condition.type = "AnotherCondition";
serviceInstance.status.conditions.push(condition);
var result = isServiceInstanceReadyFilter(serviceInstance);
expect(result).toBe(false);
});
});
describe("Filter: mostRecent", function() {
'use strict';
var mostRecentFilter;
beforeEach(inject(function (_mostRecentFilter_) {
mostRecentFilter = _mostRecentFilter_;
}));
var olderDate = new Date('Wed, 14 Jun 2017 00:00:00 PDT').toISOString();
var newerDate = new Date('Thu, 15 Jun 2017 00:00:00 PDT').toISOString();
var evenNewerDate = new Date('Fri, 16 Jun 2017 00:00:00 PDT').toISOString();
var mockObjectWithDate = function(dateString) {
return {
metadata: {
name: _.uniqueId('object-'),
creationTimestamp: dateString
}
};
};
var older = mockObjectWithDate(olderDate);
var newer = mockObjectWithDate(newerDate);
var evenNewer = mockObjectWithDate(evenNewerDate);
it('should find the most recent resource', function() {
var objects = [ newer, older, evenNewer ];
var mostRecent = mostRecentFilter(objects);
expect(mostRecent).toEqual(evenNewer);
});
it('should find the most recent resource in a map', function() {
var objects = [ newer, older, evenNewer ];
var objectsByName = _.keyBy(objects, 'metadata.name');
var mostRecent = mostRecentFilter(objectsByName);
expect(mostRecent).toEqual(evenNewer);
});
it('should return null for an empty array', function() {
var mostRecent = mostRecentFilter([]);
expect(mostRecent).toBeNull();
});
it('should return null for undefined input', function() {
var mostRecent = mostRecentFilter();
expect(mostRecent).toBeNull();
});
it('should skip null items', function() {
var objects = [ newer, null, older, evenNewer ];
var mostRecent = mostRecentFilter(objects);
expect(mostRecent).toEqual(evenNewer);
});
});
describe("Filter: orderObjectsByDate", function() {
'use strict';
var orderObjectsByDateFilter;
beforeEach(inject(function (_orderObjectsByDateFilter_) {
orderObjectsByDateFilter = _orderObjectsByDateFilter_;
}));
var olderDate = new Date('Wed, 14 Jun 2017 00:00:00 PDT').toISOString();
var newerDate = new Date('Thu, 15 Jun 2017 00:00:00 PDT').toISOString();
var evenNewerDate = new Date('Fri, 16 Jun 2017 00:00:00 PDT').toISOString();
var mockObjectWithDate = function(dateString) {
return {
metadata: {
name: _.uniqueId('object-'),
creationTimestamp: dateString
}
};
};
var older = mockObjectWithDate(olderDate);
var newer = mockObjectWithDate(newerDate);
var evenNewer = mockObjectWithDate(evenNewerDate);
it('should order the objects by date', function() {
var objects = [ newer, older, evenNewer ];
var orderObjectsByDate = orderObjectsByDateFilter(objects);
expect(orderObjectsByDate).toEqual([ older, newer, evenNewer ]);
});
it('should reverse the ordering', function() {
var objects = [ newer, older, evenNewer ];
var orderObjectsByDate = orderObjectsByDateFilter(objects, true);
expect(orderObjectsByDate).toEqual([ evenNewer, newer, older ]);
});
});
describe("Filter: parseJSON", function() {
'use strict';
var parseJSONFilter;
var dummyObject = {
foo: 'bar',
baz: {
qux: 1,
hello: false
},
items: ['one', 'two', 'three']
};
var dummyArray = dummyObject.items;
beforeEach(inject(function (_parseJSONFilter_) {
parseJSONFilter = _parseJSONFilter_;
}));
it('should parse a valid JSON object', function() {
var json = JSON.stringify(dummyObject);
var parsedObject = parseJSONFilter(json);
expect(parsedObject).toEqual(dummyObject);
});
it('should parse a valid JSON array', function() {
var json = JSON.stringify(dummyArray);
var parsedArray = parseJSONFilter(json);
expect(parsedArray).toEqual(dummyArray);
});
it('should return null if not a JSON object or array', function() {
var parsedObject = parseJSONFilter('1');
expect(parsedObject).toBeNull();
parsedObject = parseJSONFilter('"foo"');
expect(parsedObject).toBeNull();
parsedObject = parseJSONFilter('true');
expect(parsedObject).toBeNull();
});
it('should return null for on null, undefined, or empty input', function() {
var parsedObject = parseJSONFilter(null);
expect(parsedObject).toBeNull();
parsedObject = parseJSONFilter(undefined);
expect(parsedObject).toBeNull();
parsedObject = parseJSONFilter('');
expect(parsedObject).toBeNull();
});
it('should return null for invalid JSON', function() {
var json = JSON.stringify(dummyObject) + 'invalid';
var parsedObject = parseJSONFilter(json);
expect(parsedObject).toBeNull();
});
});
describe("Filter: prettifyJSON", function() {
'use strict';
var prettifyJSONFilter;
var dummyObject = {
foo: 'bar',
baz: {
qux: 1,
hello: false
},
items: ['one', 'two', 'three']
};
beforeEach(inject(function (_prettifyJSONFilter_) {
prettifyJSONFilter = _prettifyJSONFilter_;
}));
it('should parse a valid JSON object', function() {
var json = JSON.stringify(dummyObject);
var result = prettifyJSONFilter(json);
expect(result).toEqual(JSON.stringify(dummyObject, null, 4));
});
it('should return the original object if not a JSON string', function() {
var result = prettifyJSONFilter(null);
expect(result).toBeNull();
result = prettifyJSONFilter();
expect(result).toBeUndefined();
result = prettifyJSONFilter('');
expect(result).toBe('');
});
it('should return the original value for invalid JSON', function() {
var json = JSON.stringify(dummyObject) + 'invalid';
var parsedObject = prettifyJSONFilter(json);
expect(parsedObject).toBe(json);
});
});
describe("Filter: upperFirst", function() {
'use strict';
var upperFirstFilter;
beforeEach(inject(function (_upperFirstFilter_) {
upperFirstFilter = _upperFirstFilter_;
}));
var tc = [
['foo', 'Foo'],
['foo bar', 'Foo bar'],
['fooBar', 'FooBar'],
['', ''],
[null, ''],
[undefined, '']
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = upperFirstFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: serviceClassDisplayName", function() {
'use strict';
var serviceClassDisplayNameFilter;
var mockServiceClass = {
kind: "ClusterServiceClass",
apiVersion: "servicecatalog.k8s.io/v1beta1",
metadata: {
name: "470d854c-aec9-11e7-8d0c-b6c718ff6445"
},
spec: {
externalName: "jenkins-ephemeral",
externalMetadata: {
displayName: "Jenkins (Ephemeral)",
}
},
status: {}
};
beforeEach(inject(function (_serviceClassDisplayNameFilter_) {
serviceClassDisplayNameFilter = _serviceClassDisplayNameFilter_;
}));
it('should return the external metadata display name when set', function() {
var result = serviceClassDisplayNameFilter(mockServiceClass);
expect(result).toEqual("Jenkins (Ephemeral)");
});
it('should fall back to external name when no external metadata display name', function() {
var serviceClass = angular.copy(mockServiceClass);
delete serviceClass.spec.externalMetadata.displayName;
var result = serviceClassDisplayNameFilter(serviceClass);
expect(result).toEqual("jenkins-ephemeral");
});
it('should return undefined for null input', function() {
var result = serviceClassDisplayNameFilter(null);
expect(result).toBeUndefined();
});
it('should return undefined for undefined input', function() {
var result = serviceClassDisplayNameFilter(undefined);
expect(result).toBeUndefined();
});
it('should return undefined for an empty object', function() {
var result = serviceClassDisplayNameFilter({});
expect(result).toBeUndefined();
});
});
describe("Filter: serviceInstanceDisplayName", function() {
'use strict';
var serviceInstanceDisplayNameFilter;
var mockServiceClass = {
kind: "ClusterServiceClass",
apiVersion: "servicecatalog.k8s.io/v1beta1",
metadata: {
name: "470d854c-aec9-11e7-8d0c-b6c718ff6445"
},
spec: {
externalName: "jenkins-ephemeral",
externalMetadata: {
displayName: "Jenkins (Ephemeral)",
}
},
status: {}
};
var mockServiceInstance = {
metadata: {
name: 'jenkins-ephemeral-2jk9x'
},
spec: {
externalClusterServiceClassName: 'jenkins-ephemeral'
}
};
beforeEach(inject(function (_serviceInstanceDisplayNameFilter_) {
serviceInstanceDisplayNameFilter = _serviceInstanceDisplayNameFilter_;
}));
it('should return the service class external metadata display name when set', function() {
var result = serviceInstanceDisplayNameFilter(mockServiceInstance, mockServiceClass);
expect(result).toEqual("Jenkins (Ephemeral)");
});
it('should fall back to service class external name when no external metadata display name', function() {
var serviceClass = angular.copy(mockServiceClass);
delete serviceClass.spec.externalMetadata.displayName;
var result = serviceInstanceDisplayNameFilter(mockServiceInstance, serviceClass);
expect(result).toEqual("jenkins-ephemeral");
});
it('should fall back to spec.externalClusterServiceClassName when no service class', function() {
var result = serviceInstanceDisplayNameFilter(mockServiceInstance);
expect(result).toEqual("jenkins-ephemeral");
});
it('should return undefined for null or undefined input', function() {
var result = serviceInstanceDisplayNameFilter(null);
expect(result).toBeUndefined();
result = serviceInstanceDisplayNameFilter(undefined);
expect(result).toBeUndefined();
result = serviceInstanceDisplayNameFilter({});
expect(result).toBeUndefined();
});
});
describe("Filter: serviceInstanceFailedMessage", function() {
'use strict';
var serviceInstanceFailedMessageFilter;
var mockServiceInstance = {
"apiVersion": "servicecatalog.k8s.io/v1beta1",
"kind": "ServceInstance",
"metadata": {
"name": "mariadb-persistent-6q4zn",
"namespace": "test",
"uid": "6a31b3ce-aec9-11e7-bae6-0242ac110002",
},
"spec": {
"externalClusterServiceClassName": "mariadb-persistent",
"externalClusterServicePlanName": "default",
"clusterServiceClassRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "581f692a-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "20"
},
"clusterServicePlanRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "5704c949-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "8"
},
"parametersFrom": [
{
"secretKeyRef": {
"name": "mariadb-persistent-parameters-s6zzf",
"key": "parameters"
}
}
],
"externalID": "8066697b-530b-486d-a6e2-5ff2b8d8febb",
"updateRequests": 0
},
"status": {
"conditions": []
}
};
var failedCondition = {
"type": "Failed",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionCallFailed",
"message": 'Provision call failed: ServiceInstance "test/mariadb-persistent-6q4zn": Error provisioning: "secrets \"mariadb\" already exists\nservices \"mariadb\" already exists\npersistentvolumeclaims \"mariadb\" already exists\ndeploymentconfigs \"mariadb\" already exists"'
};
beforeEach(inject(function (_serviceInstanceFailedMessageFilter_) {
serviceInstanceFailedMessageFilter = _serviceInstanceFailedMessageFilter_;
}));
it('should return the message when the instance is failed', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(failedCondition);
var result = serviceInstanceFailedMessageFilter(serviceInstance);
expect(result).toBe(failedCondition.message);
});
it('should return undefined when there are no status conditions', function() {
var result = serviceInstanceFailedMessageFilter(mockServiceInstance);
expect(result).toBeUndefined();
});
it('should return undefined when a different status condition is set', function() {
var serviceInstance = angular.copy(mockServiceInstance);
var condition = angular.copy(failedCondition);
condition.type = "AnotherCondition";
serviceInstance.status.conditions.push(condition);
var result = serviceInstanceFailedMessageFilter(serviceInstance);
expect(result).toBeUndefined();
});
});
describe("Filter: serviceInstanceReadyMessage", function() {
'use strict';
var serviceInstanceReadyMessageFilter;
var mockServiceInstance = {
"apiVersion": "servicecatalog.k8s.io/v1beta1",
"kind": "ServceInstance",
"metadata": {
"name": "mariadb-persistent-6q4zn",
"namespace": "test",
"uid": "6a31b3ce-aec9-11e7-bae6-0242ac110002",
},
"spec": {
"externalClusterServiceClassName": "mariadb-persistent",
"externalClusterServicePlanName": "default",
"clusterServiceClassRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "581f692a-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "20"
},
"clusterServicePlanRef": {
"name": "475554bf-aec9-11e7-8d0c-b6c718ff6445",
"uid": "5704c949-aec9-11e7-bae6-0242ac110002",
"resourceVersion": "8"
},
"parametersFrom": [
{
"secretKeyRef": {
"name": "mariadb-persistent-parameters-s6zzf",
"key": "parameters"
}
}
],
"externalID": "8066697b-530b-486d-a6e2-5ff2b8d8febb",
"updateRequests": 0
},
"status": {
"conditions": []
}
};
var readyCondition = {
"type": "Ready",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionedSuccessfully",
"message": "The instance was provisioned successfully"
};
var pendingCondition = {
"type": "Ready",
"status": "False",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "Provisioning",
"message": "The instance is being provisioned asynchronously"
};
beforeEach(inject(function (_serviceInstanceReadyMessageFilter_) {
serviceInstanceReadyMessageFilter = _serviceInstanceReadyMessageFilter_;
}));
it('should return the message when the instance is ready', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(readyCondition);
var result = serviceInstanceReadyMessageFilter(serviceInstance);
expect(result).toBe("The instance was provisioned successfully");
});
it('should return the message when the instance is not ready', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push(pendingCondition);
var result = serviceInstanceReadyMessageFilter(serviceInstance);
expect(result).toBe("The instance is being provisioned asynchronously");
});
it('should return undefined when there are no status conditions', function() {
var result = serviceInstanceReadyMessageFilter(mockServiceInstance);
expect(result).toBeUndefined();
});
it('should return undefined when a different status condition is set', function() {
var serviceInstance = angular.copy(mockServiceInstance);
var condition = angular.copy(readyCondition);
condition.type = "AnotherCondition";
serviceInstance.status.conditions.push(condition);
var result = serviceInstanceReadyMessageFilter(serviceInstance);
expect(result).toBeUndefined();
});
});
describe("Filter: startCase", function() {
'use strict';
var startCaseFilter;
beforeEach(inject(function (_startCaseFilter_) {
startCaseFilter = _startCaseFilter_;
}));
var tc = [
['FooBar', 'Foo Bar'],
['fooBar', 'Foo Bar'],
['Foo', 'Foo'],
['foo-bar', 'Foo Bar'],
['FooBarBaz', 'Foo Bar Baz'],
['', ''],
[null, ''],
[undefined, '']
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = startCaseFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe("Filter: statusCondition", function() {
'use strict';
var statusConditionFilter;
var mockAPIObject = {
metadata: {},
spec: {},
status: {
conditions: []
}
};
var readyCondition = {
"type": "Ready",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionedSuccessfully",
"message": "The instance was provisioned successfully"
};
var failedCondition = {
"type": "Failed",
"status": "True",
"lastTransitionTime": "2017-10-11T21:17:16Z",
"reason": "ProvisionCallFailed",
"message": 'Provision call failed: ServiceInstance "test/mariadb-persistent-6q4zn": Error provisioning: "secrets \"mariadb\" already exists\nservices \"mariadb\" already exists\npersistentvolumeclaims \"mariadb\" already exists\ndeploymentconfigs \"mariadb\" already exists"'
};
beforeEach(inject(function (_statusConditionFilter_) {
statusConditionFilter = _statusConditionFilter_;
}));
it('should return the condition when it exists', function() {
var apiObject = angular.copy(mockAPIObject);
apiObject.status.conditions.push(readyCondition);
var result = statusConditionFilter(apiObject, 'Ready');
expect(result).toEqual(readyCondition);
});
it('should return the correct condition when there is more than one', function() {
var apiObject = angular.copy(mockAPIObject);
apiObject.status.conditions.push(readyCondition);
apiObject.status.conditions.push(failedCondition);
var result = statusConditionFilter(apiObject, 'Failed');
expect(result).toEqual(failedCondition);
});
it('should return undefined when there are no status conditions', function() {
var result = statusConditionFilter(mockAPIObject);
expect(result).toBeUndefined();
});
it('should return undefined when a different status condition is set', function() {
var apiObject = angular.copy(mockAPIObject);
var condition = angular.copy(readyCondition);
condition.type = "AnotherCondition";
apiObject.status.conditions.push(condition);
var result = statusConditionFilter(apiObject);
expect(result).toBeUndefined();
});
it('should return null for null or undefined input', function() {
var result = statusConditionFilter(null);
expect(result).toBeNull();
result = statusConditionFilter(undefined);
expect(result).toBeNull();
});
});
describe("TruncateFilter", function() {
describe("Filter: truncate", function() {
'use strict';
var $scope;
var $filter;
beforeEach(inject(function (_$rootScope_, _$filter_) {
$scope = _$rootScope_;
$filter = _$filter_;
}));
beforeEach(function () {
$scope.params = {
str: 'Operation cannot be fulfilled on namespaces\n"ups-broker": The system is ensuring all content is removed\nfrom this namespace. Upon completion, this\nnamespace will automatically be purged by the system.\n',
charLimit: 200,
......
describe("Filter: uid", function() {
'use strict';
var uidFilter;
beforeEach(inject(function (_uidFilter_) {
uidFilter = _uidFilter_;
}));
it('should return the uid for an API object', function() {
var testUID = 'ea1e8dcf-aecb-11e7-8d0c-b6c718ff6445';
var result = uidFilter({
metadata: {
uid: testUID
}
});
expect(result).toEqual(testUID);
});
it('should return the object itself if it has no UID', function() {
var object = {
metadata: {
name: 'my-new-object'
}
};
var result = uidFilter(object);
expect(result).toEqual(object);
});
it('should return the original value if null or undefined', function() {
var result = uidFilter(null);
expect(result).toBeNull();
result = uidFilter();
expect(result).toBeUndefined();
});
});
describe("Filter: sentenceCase", function() {
'use strict';
var sentenceCaseFilter;
beforeEach(inject(function (_sentenceCaseFilter_) {
sentenceCaseFilter = _sentenceCaseFilter_;
}));
var tc = [
['FooBar', 'Foo bar'],
['fooBar', 'Foo bar'],
['Foo', 'Foo'],
['foo-bar', 'Foo bar'],
['FooBarBaz', 'Foo bar baz'],
['', ''],
[null, ''],
[undefined, '']
];
_.each(tc, _.spread(function(input, expected) {
it('should result in ' + expected + ' when called with ' + input, function() {
var actual = sentenceCaseFilter(input);
expect(actual).toEqual(expected);
});
}));
});
describe('BindingService', function() {
'use strict';
var BindingService, DNS1123_SUBDOMAIN_VALIDATION;
beforeEach(function() {
inject(function(_BindingService_, _DNS1123_SUBDOMAIN_VALIDATION_) {
BindingService = _BindingService_;
DNS1123_SUBDOMAIN_VALIDATION = _DNS1123_SUBDOMAIN_VALIDATION_;
});
});
describe('#generateSecretName', function() {
it('should generate a unique name for a secret given a prefix', function() {
var prefix = 'mongodb-';
var name1 = BindingService.generateSecretName(prefix);
var name2 = BindingService.generateSecretName(prefix);
expect(name1).not.toEqual(name2);
});
it('should generate a name that starts with a prefix', function() {
var prefix = 'mongodb-';
var name = BindingService.generateSecretName(prefix);
expect(name.lastIndexOf(prefix)).toEqual(0);
});
it('should not generate a name that is too long', function() {
var prefix = _.repeat('a', DNS1123_SUBDOMAIN_VALIDATION.maxlength);
var name = BindingService.generateSecretName(prefix);
expect(name.length).not.toBeGreaterThan(DNS1123_SUBDOMAIN_VALIDATION.maxlength);
});
it('should not generate duplicates for long names', function() {
var prefix = _.repeat('a', DNS1123_SUBDOMAIN_VALIDATION.maxlength);
var name1 = BindingService.generateSecretName(prefix);
var name2 = BindingService.generateSecretName(prefix);
expect(name1).not.toEqual(name2);
});
});
describe('#makeParametersSecret', function() {
var parameters = {
parameter1: 'value1',
parameter2: 'value2',
parameter3: ['one', 'two', 'three'],
parameter4: true,
parameter5: {
value: 1
}
};
var owner = {
apiVersion: "servicecatalog.k8s.io/v1beta1",
kind: "ServceInstance",
metadata: {
name: "mariadb-persistent-6q4zn",
namespace: "test",
uid: "6a31b3ce-aec9-11e7-bae6-0242ac110002",
},
spec: {},
status: {}
};
it('should create a secret with service catalog parameters JSON', function() {
var secret = BindingService.makeParametersSecret('instance-params', parameters, owner);
expect(secret.type).toEqual('Opaque');
var json = secret.stringData.parameters;
var actualParameters = JSON.parse(json);
expect(actualParameters).toEqual(parameters);
});
it('should set an owner reference', function() {
var secret = BindingService.makeParametersSecret('instance-params', parameters, owner);
var ownerReferences = secret.metadata.ownerReferences;
expect(ownerReferences.length).toEqual(1);
var ownerRef = ownerReferences[0];
expect(ownerRef.apiVersion).toEqual(owner.apiVersion);
expect(ownerRef.kind).toEqual(owner.kind);
expect(ownerRef.name).toEqual(owner.metadata.name);
expect(ownerRef.uid).toEqual(owner.metadata.uid);
expect(ownerRef.controller).toEqual(false);
expect(ownerRef.blockOwnerDeletion).toEqual(false);
});
});
describe('#isServiceBindable', function() {
var mockServiceInstance = {
metadata: {},
spec: {},
status: {
conditions: []
}
};
var mockServiceClass = {
metadata: {},
spec: {
bindable: true
}
};
var mockServicePlan = {
metadata: {},
spec: {
bindable: true
}
};
it('should allow binding a bindable service class', function() {
var bindable = BindingService.isServiceBindable(mockServiceInstance, mockServiceClass, mockServicePlan);
expect(bindable).toEqual(true);
});
it('should return false if service instance is undefined', function() {
var bindable = BindingService.isServiceBindable(undefined, mockServiceClass, mockServicePlan);
expect(bindable).toEqual(false);
});
it('should return false if service class is undefined', function() {
var bindable = BindingService.isServiceBindable(mockServiceInstance, undefined, mockServicePlan);
expect(bindable).toEqual(false);
});
it('should return false if service plan is undefined', function() {
var bindable = BindingService.isServiceBindable(mockServiceInstance, mockServiceClass);
expect(bindable).toEqual(false);
});
it('should return false if the instance is marked for deletion', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.metadata.deletionTimestamp = "2017-10-11T21:17:16Z";
var bindable = BindingService.isServiceBindable(serviceInstance, mockServiceClass, mockServicePlan);
expect(bindable).toEqual(false);
});
it('should return false if the instance has failed', function() {
var serviceInstance = angular.copy(mockServiceInstance);
serviceInstance.status.conditions.push({
type: 'Failed',
status: 'True'
});
var bindable = BindingService.isServiceBindable(serviceInstance, mockServiceClass, mockServicePlan);
expect(bindable).toEqual(false);
});
it('should return false if the plan is not bindable', function() {
var plan = angular.copy(mockServicePlan);
plan.spec.bindable = false;
var bindable = BindingService.isServiceBindable(mockServiceInstance, mockServiceClass, plan);
expect(bindable).toEqual(false);
});
it('should return true if the plan bindable is missing', function() {
var plan = angular.copy(mockServicePlan);
delete plan.spec.bindable;
var bindable = BindingService.isServiceBindable(mockServiceInstance, mockServiceClass, plan);
expect(bindable).toEqual(true);
});
it('should return true if the service class it not bindable, but plan is bindable', function() {
var serviceClass = angular.copy(mockServiceClass);
serviceClass.spec.bindable = false;
var bindable = BindingService.isServiceBindable(mockServiceInstance, serviceClass, mockServicePlan);
expect(bindable).toEqual(true);
});
});
});
describe('KeywordService', function() {
'use strict';
var KeywordService;
beforeEach(function() {
inject(function(_KeywordService_) {
KeywordService = _KeywordService_;
});
});
describe('#generateKeywords', function() {
it('should return an empty array if filter text is undefined', function() {
var result = KeywordService.generateKeywords();
return expect(result).toEqual([]);
});
it('should return an empty array if filter text is null', function() {
var result = KeywordService.generateKeywords(null);
return expect(result).toEqual([]);
});
it('should return an empty array if filter text is the empty string', function() {
var result = KeywordService.generateKeywords('');
return expect(result).toEqual([]);
});
it('should return an empty array if filter text has only whitespace', function() {
var result = KeywordService.generateKeywords(' \n\t');
return expect(result).toEqual([]);
});
it('should tokenize by whitespace', function() {
var result = KeywordService.generateKeywords(' foo bar\nbaz\tqux');
return expect(result.length).toEqual(4);
});
it('should remove duplicate keywords', function() {
var result = KeywordService.generateKeywords('foo foo');
return expect(result.length).toEqual(1);
});
});
describe('#filterForKeywords', function() {
var mockData = [{
metadata: {
name: 'project1',
annotations: {
'openshift.io/display-name': 'My Project',
'openshift.io/requester': 'developer'
}
}
}, {
metadata: {
name: 'project2',
annotations: {
'openshift.io/display-name': 'Another Project',
'openshift.io/description': 'Lorem ipsum...'
}
}
}];
var filterFields = [
'metadata.name',
'metadata.annotations["openshift.io/display-name"]',
'metadata.annotations["openshift.io/description"]',
'metadata.annotations["openshift.io/requester"]'
];
it('should find matches with a single keyword', function() {
var keywords = KeywordService.generateKeywords('my');
var result = KeywordService.filterForKeywords(mockData, filterFields, keywords);
expect(result.length).toBe(1);
expect(result[0]).toEqual(mockData[0]);
});
it('should find matches with multiple keywords', function() {
var keywords = KeywordService.generateKeywords('lorem ipsum');
var result = KeywordService.filterForKeywords(mockData, filterFields, keywords);
expect(result.length).toBe(1);
expect(result[0]).toEqual(mockData[1]);
});
it('should find matches across different fields', function() {
var keywords = KeywordService.generateKeywords('another lorem');
var result = KeywordService.filterForKeywords(mockData, filterFields, keywords);
expect(result.length).toBe(1);
expect(result[0]).toEqual(mockData[1]);
});
it('should match all keywords', function() {
var keywords = KeywordService.generateKeywords('my notfound');
var result = KeywordService.filterForKeywords(mockData, filterFields, keywords);
expect(result.length).toBe(0);
});
it('should handle maps', function() {
var keywords = KeywordService.generateKeywords('my');
// Convert items from an array to a map.
var projectsByName = _.keyBy(mockData, 'metadata.name');
var result = KeywordService.filterForKeywords(projectsByName, filterFields, keywords);
expect(result.length).toBe(1);
expect(result[0]).toEqual(mockData[0]);
});
it('should return the original collection if keywords are null', function() {
var result = KeywordService.filterForKeywords(mockData, filterFields);
expect(result).toEqual(mockData);
});
});
});
describe('NotificationsService', function() {
'use strict';
var NotificationsService, $rootScope;
beforeEach(function() {
inject(function(_NotificationsService_, _$rootScope_) {
NotificationsService = _NotificationsService_;
$rootScope = _$rootScope_;
});
});
var mockNotification = {
id: "deprovision-service-error",
type: "error",
message: "An error occurred while deleting provisioned service mongodb.",
details: "Deprovision call failed: could not connect to broker."
};
describe('#addNotification', function() {
it('should add a notification', function() {
var notification = angular.copy(mockNotification);
NotificationsService.addNotification(notification);
var notifications = NotificationsService.getNotifications();
expect(notifications.length).toBe(1);
expect(notifications[0].id).toBe(mockNotification.id);
});
});
describe('#hideNotification', function() {
it('should hide a notification', function() {
var notification = angular.copy(mockNotification);
NotificationsService.addNotification(notification);
NotificationsService.hideNotification(notification.id);
var notifications = NotificationsService.getNotifications();
expect(notifications.length).toBe(1);
expect(notifications[0].hidden).toBe(true);
});
});
describe('#clearNotifications', function() {
it('should clear notifications', function() {
var notification1 = angular.copy(mockNotification);
NotificationsService.addNotification(notification1);
var notification2 = angular.copy(mockNotification);
notification2.id = 'another';
NotificationsService.addNotification(notification2);
var notifications = NotificationsService.getNotifications();
expect(notifications.length).toBe(2);
NotificationsService.clearNotifications();
notifications = NotificationsService.getNotifications();
expect(notifications.length).toBe(0);
});
});
describe('$rootScope events', function() {
it('should listen for NotificationsService.addNotification events', function() {
var notification = angular.copy(mockNotification);
$rootScope.$emit('NotificationsService.addNotification', notification);
var notifications = NotificationsService.getNotifications();
expect(notifications.length).toBe(1);
expect(notifications[0].id).toBe(mockNotification.id);
});
});
});
"use strict";
//load the module
// Load the modules.
beforeEach(module('openshiftCommonServices', 'openshiftCommonUI'));
beforeEach(module(function ($provide) {
$provide.provider("HawtioNavBuilder", function() {
function Mocked() {}
this.create = function() {return this;};
this.id = function() {return this;};
this.title = function() {return this;};
this.template = function() {return this;};
this.isSelected = function() {return this;};
this.href = function() {return this;};
this.page = function() {return this;};
this.subPath = function() {return this;};
this.build = function() {return this;};
this.join = function() {return "";};
this.$get = function() {return new Mocked();};
});
$provide.factory("HawtioNav", function(){
return {add: function() {}};
});
$provide.factory("HawtioExtension", function() {
return {
add: function() {}
};
});
// Make sure a base location exists in the generated test html
beforeEach(module(function() {
// Make sure a base location exists in the generated test html.
if (!$('head base').length) {
$('head').append($('<base href="/">'));
}
......@@ -40,11 +15,9 @@ beforeEach(module(function ($provide) {
.constant("API_CFG", _.get(window.OPENSHIFT_CONFIG, "api", {}))
.constant("APIS_CFG", _.get(window.OPENSHIFT_CONFIG, "apis", {}))
.constant("AUTH_CFG", _.get(window.OPENSHIFT_CONFIG, "auth", {}))
.config(function($httpProvider, AuthServiceProvider, AUTH_CFG, API_CFG) {
.config(function($httpProvider, AuthServiceProvider) {
AuthServiceProvider.LoginService('RedirectLoginService');
AuthServiceProvider.LogoutService('DeleteTokenLogoutService');
AuthServiceProvider.UserStore('LocalStorageUserStore');
});
hawtioPluginLoader.addModule('openshiftCommonServices');
}));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment