Added JavaScript Style Linting
This patch adds eslint, a permissively licensed (as opposed to jshint or jslint) javascript style linter. It also enables the use of 'npm run lint', which may be used in OpenStack's gate to cause build failures when improperly formed javascript is committed. Existing javascript was updated to pass linting rules. Note that most of these changes were formatting and file length concerns. The noted stylistic change that we should probably discuss is the use of singlequote vs. doublequote. Single is the pep8 standard used in python, and thus enforcing that seems to make the most sense. Change-Id: I52768fe6e7ee1f76f0d67f44273fdc48b159489a
This commit is contained in:
parent
0d51cad50f
commit
6fffbca938
1
refstack-ui/.eslintignore
Normal file
1
refstack-ui/.eslintignore
Normal file
@ -0,0 +1 @@
|
||||
app/assets/lib
|
58
refstack-ui/.eslintrc
Normal file
58
refstack-ui/.eslintrc
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
// For a detailed list of all options, please see here:
|
||||
// http://eslint.org/docs/configuring/
|
||||
"ecmaFeatures": {
|
||||
"arrowFunctions": false,
|
||||
"binaryLiterals": false,
|
||||
"blockBindings": false,
|
||||
"defaultParams": false,
|
||||
"forOf": false,
|
||||
"generators": false,
|
||||
"objectLiteralComputedProperties": false,
|
||||
"objectLiteralDuplicateProperties": false,
|
||||
"objectLiteralShorthandProperties": false,
|
||||
"octalLiterals": false,
|
||||
"regexUFlag": false,
|
||||
"superInFunctions": false,
|
||||
"templateStrings": false,
|
||||
"unicodeCodePointEscapes": false,
|
||||
"globalReturn": false,
|
||||
"jsx": false
|
||||
},
|
||||
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": false,
|
||||
"amd": false,
|
||||
"mocha": false,
|
||||
"jasmine": true,
|
||||
"phantomjs": false,
|
||||
"jquery": false,
|
||||
"prototypejs": false,
|
||||
"shelljs": false
|
||||
},
|
||||
|
||||
"globals": {
|
||||
"require": false,
|
||||
"exports": false,
|
||||
"angular": false, // AngularJS
|
||||
"module": false,
|
||||
"inject": false,
|
||||
"element": false,
|
||||
"by": false,
|
||||
"browser": false
|
||||
},
|
||||
|
||||
"rules": {
|
||||
"quotes": [2, "single"],
|
||||
"eol-last": 2,
|
||||
"no-trailing-spaces": 2,
|
||||
"camelcase": 0,
|
||||
"no-extra-boolean-cast": 0,
|
||||
|
||||
// Stylistic
|
||||
"indent": [2, 4],
|
||||
"max-len": [2, 80],
|
||||
"no-undefined": 2
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
/* App Module */
|
||||
|
||||
var refstackApp = angular.module('refstackApp', [
|
||||
@ -8,8 +6,11 @@ var refstackApp = angular.module('refstackApp', [
|
||||
/*
|
||||
* Handle application routing.
|
||||
*/
|
||||
refstackApp.config(['$stateProvider', '$urlRouterProvider',
|
||||
refstackApp.config([
|
||||
'$stateProvider', '$urlRouterProvider',
|
||||
function ($stateProvider, $urlRouterProvider) {
|
||||
'use strict';
|
||||
|
||||
$urlRouterProvider.otherwise('/');
|
||||
$stateProvider.
|
||||
state('home', {
|
||||
@ -34,7 +35,7 @@ refstackApp.config(['$stateProvider', '$urlRouterProvider',
|
||||
url: '/results/:testID',
|
||||
templateUrl: '/components/results-report/resultsReport.html',
|
||||
controller: 'resultsReportController'
|
||||
})
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
@ -42,7 +43,10 @@ refstackApp.config(['$stateProvider', '$urlRouterProvider',
|
||||
* Load Config and start up the angular application.
|
||||
*/
|
||||
angular.element(document).ready(function () {
|
||||
'use strict';
|
||||
|
||||
var $http = angular.injector(['ng']).get('$http');
|
||||
|
||||
function startApp(config) {
|
||||
// Add config options as constants.
|
||||
for (var key in config) {
|
||||
@ -53,7 +57,7 @@ angular.element(document).ready(function () {
|
||||
|
||||
$http.get('config.json').success(function (data) {
|
||||
startApp(data);
|
||||
}).error(function(error) {
|
||||
}).error(function () {
|
||||
startApp({});
|
||||
});
|
||||
});
|
||||
|
@ -1,3 +1 @@
|
||||
'use strict';
|
||||
|
||||
/* Miscellaneous Refstack JavaScript */
|
||||
|
@ -1,10 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
/* Refstack Capabilities Controller */
|
||||
|
||||
var refstackApp = angular.module('refstackApp');
|
||||
|
||||
refstackApp.controller('capabilitiesController', ['$scope', '$http', 'refstackApiUrl', function($scope, $http, refstackApiUrl) {
|
||||
refstackApp.controller('capabilitiesController',
|
||||
['$scope', '$http', 'refstackApiUrl',
|
||||
function ($scope, $http, refstackApiUrl) {
|
||||
'use strict';
|
||||
|
||||
$scope.hideAchievements = true;
|
||||
$scope.hideTests = true;
|
||||
$scope.target = 'platform';
|
||||
@ -17,24 +19,29 @@ refstackApp.controller('capabilitiesController', ['$scope', '$http', 'refstackAp
|
||||
|
||||
$scope.getVersionList = function () {
|
||||
var content_url = refstackApiUrl + '/capabilities';
|
||||
$scope.versionsRequest = $http.get(content_url).success(function(data) {
|
||||
$scope.versionsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.versionList = data.sort().reverse();
|
||||
$scope.version = $scope.versionList[0];
|
||||
$scope.update();
|
||||
}).error(function (error) {
|
||||
$scope.showError = true;
|
||||
$scope.error = 'Error retrieving version list: ' + JSON.stringify(error);
|
||||
$scope.error = 'Error retrieving version list: ' +
|
||||
JSON.stringify(error);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.update = function () {
|
||||
var content_url = refstackApiUrl + '/capabilities/' + $scope.version;
|
||||
$scope.capsRequest = $http.get(content_url).success(function(data) {
|
||||
var content_url = refstackApiUrl + '/capabilities/' +
|
||||
$scope.version;
|
||||
$scope.capsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.capabilities = data;
|
||||
}).error(function (error) {
|
||||
$scope.showError = true;
|
||||
$scope.capabilities = null;
|
||||
$scope.error = 'Error retrieving capabilities: ' + JSON.stringify(error);
|
||||
$scope.error = 'Error retrieving capabilities: ' +
|
||||
JSON.stringify(error);
|
||||
});
|
||||
};
|
||||
|
||||
@ -42,25 +49,27 @@ refstackApp.controller('capabilitiesController', ['$scope', '$http', 'refstackAp
|
||||
|
||||
$scope.filterProgram = function (capability) {
|
||||
var components = $scope.capabilities.components;
|
||||
if ($scope.target === 'platform') {
|
||||
var platform_components = $scope.capabilities.platform.required;
|
||||
var cap_array = [];
|
||||
|
||||
if ($scope.target === 'platform') {
|
||||
var platform_components =
|
||||
$scope.capabilities.platform.required;
|
||||
// For each component required for the platform program.
|
||||
angular.forEach(platform_components, function (component) {
|
||||
// Get each capability belonging to each status.
|
||||
angular.forEach(components[component], function(capabilities) {
|
||||
angular.forEach(components[component],
|
||||
function (capabilities) {
|
||||
cap_array = cap_array.concat(capabilities);
|
||||
});
|
||||
});
|
||||
return (cap_array.indexOf(capability.id) > -1);
|
||||
}
|
||||
else {
|
||||
var cap_array = [];
|
||||
angular.forEach(components[$scope.target], function(capabilities) {
|
||||
angular.forEach(components[$scope.target],
|
||||
function (capabilities) {
|
||||
cap_array = cap_array.concat(capabilities);
|
||||
});
|
||||
return (cap_array.indexOf(capability.id) > -1);
|
||||
}
|
||||
return (cap_array.indexOf(capability.id) > -1);
|
||||
};
|
||||
|
||||
$scope.filterStatus = function (capability) {
|
||||
|
@ -1,12 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/* Refstack Results Report Controller */
|
||||
|
||||
var refstackApp = angular.module('refstackApp');
|
||||
|
||||
refstackApp.controller('resultsReportController', ['$scope', '$http', '$stateParams', 'refstackApiUrl',
|
||||
refstackApp.controller('resultsReportController',
|
||||
['$scope', '$http', '$stateParams', 'refstackApiUrl',
|
||||
function ($scope, $http, $stateParams, refstackApiUrl) {
|
||||
$scope.testId = $stateParams.testID
|
||||
'use strict';
|
||||
|
||||
$scope.testId = $stateParams.testID;
|
||||
$scope.hideTests = true;
|
||||
$scope.target = 'platform';
|
||||
$scope.requiredOpen = true;
|
||||
@ -15,77 +16,91 @@ refstackApp.controller('resultsReportController', ['$scope', '$http', '$statePar
|
||||
'platform': 'Openstack Powered Platform',
|
||||
'compute': 'OpenStack Powered Compute',
|
||||
'object': 'OpenStack Powered Object Storage'
|
||||
}
|
||||
|
||||
var getResults = function() {
|
||||
var content_url = refstackApiUrl +'/results/' + $scope.testId;
|
||||
$scope.resultsRequest = $http.get(content_url).success(function(data) {
|
||||
$scope.resultsData = data;
|
||||
getVersionList();
|
||||
}).error(function(error) {
|
||||
$scope.showError = true;
|
||||
$scope.resultsData = null;
|
||||
$scope.error = "Error retrieving results from server: " + JSON.stringify(error);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
var getVersionList = function () {
|
||||
var content_url = refstackApiUrl + '/capabilities';
|
||||
$scope.versionsRequest = $http.get(content_url).success(function(data) {
|
||||
$scope.versionsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.versionList = data.sort().reverse();
|
||||
$scope.version = $scope.versionList[0];
|
||||
$scope.updateCapabilities();
|
||||
}).error(function (error) {
|
||||
$scope.showError = true;
|
||||
$scope.resultsData = null;
|
||||
$scope.error = "Error retrieving version list: " + JSON.stringify(error);;
|
||||
$scope.error = 'Error retrieving version list: ' +
|
||||
JSON.stringify(error);
|
||||
});
|
||||
};
|
||||
|
||||
var getResults = function () {
|
||||
var content_url = refstackApiUrl + '/results/' + $scope.testId;
|
||||
$scope.resultsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.resultsData = data;
|
||||
getVersionList();
|
||||
}).error(function (error) {
|
||||
$scope.showError = true;
|
||||
$scope.resultsData = null;
|
||||
$scope.error = 'Error retrieving results from server: ' +
|
||||
JSON.stringify(error);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
$scope.updateCapabilities = function () {
|
||||
$scope.showError = false;
|
||||
var content_url = refstackApiUrl + '/capabilities/' + $scope.version;
|
||||
$scope.capsRequest = $http.get(content_url).success(function(data) {
|
||||
var content_url = refstackApiUrl + '/capabilities/' +
|
||||
$scope.version;
|
||||
$scope.capsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.capabilityData = data;
|
||||
$scope.buildCapabilityObject();
|
||||
}).error(function (error) {
|
||||
$scope.showError = true;
|
||||
$scope.capabilityData = null;
|
||||
$scope.error = 'Error retrieving capabilities: ' + JSON.stringify(error);
|
||||
$scope.error = 'Error retrieving capabilities: ' +
|
||||
JSON.stringify(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.buildCapabilityObject = function () {
|
||||
var capabilities = $scope.capabilityData.capabilities;
|
||||
var caps = {'required': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
var caps = {
|
||||
'required': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
'advisory': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
'deprecated': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
'removed': {'caps': [], 'count': 0, 'passedCount': 0}};
|
||||
'removed': {'caps': [], 'count': 0, 'passedCount': 0}
|
||||
};
|
||||
var components = $scope.capabilityData.components;
|
||||
var cap_array = [];
|
||||
// First determine which capabilities are relevant to the target.
|
||||
if ($scope.target === 'platform') {
|
||||
var platform_components = $scope.capabilityData.platform.required;
|
||||
var platform_components =
|
||||
$scope.capabilityData.platform.required;
|
||||
// For each component required for the platform program.
|
||||
angular.forEach(platform_components, function (component) {
|
||||
// Get each capability belonging to each status.
|
||||
angular.forEach(components[component], function(capabilities) {
|
||||
cap_array = cap_array.concat(capabilities);
|
||||
angular.forEach(components[component],
|
||||
function (compCapabilities) {
|
||||
cap_array = cap_array.concat(compCapabilities);
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
angular.forEach(components[$scope.target], function(capabilities) {
|
||||
cap_array = cap_array.concat(capabilities);
|
||||
angular.forEach(components[$scope.target],
|
||||
function (compCapabilities) {
|
||||
cap_array = cap_array.concat(compCapabilities);
|
||||
});
|
||||
}
|
||||
|
||||
angular.forEach(capabilities, function (value, key) {
|
||||
if (cap_array.indexOf(key) > -1) {
|
||||
var cap = { "id": key,
|
||||
"passedTests": [],
|
||||
"notPassedTests": []};
|
||||
var cap = {
|
||||
'id': key,
|
||||
'passedTests': [],
|
||||
'notPassedTests': []
|
||||
};
|
||||
caps[value.status].count += value.tests.length;
|
||||
angular.forEach(value.tests, function (test_id) {
|
||||
if ($scope.resultsData.results.indexOf(test_id) > -1) {
|
||||
@ -100,7 +115,7 @@ refstackApp.controller('resultsReportController', ['$scope', '$http', '$statePar
|
||||
}
|
||||
});
|
||||
$scope.caps = caps;
|
||||
}
|
||||
};
|
||||
|
||||
getResults();
|
||||
}
|
||||
|
@ -1,38 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
/* Refstack Results Controller */
|
||||
|
||||
var refstackApp = angular.module('refstackApp');
|
||||
|
||||
refstackApp.controller('resultsController', ['$scope', '$http', '$filter', 'refstackApiUrl', function($scope, $http, $filter, refstackApiUrl) {
|
||||
refstackApp.controller('resultsController',
|
||||
['$scope', '$http', '$filter', 'refstackApiUrl',
|
||||
function ($scope, $http, $filter, refstackApiUrl) {
|
||||
'use strict';
|
||||
|
||||
$scope.currentPage = 1;
|
||||
$scope.itemsPerPage = 20;
|
||||
$scope.maxSize = 5;
|
||||
$scope.startDate = "";
|
||||
$scope.endDate = "";
|
||||
$scope.startDate = '';
|
||||
$scope.endDate = '';
|
||||
$scope.update = function () {
|
||||
$scope.showError = false;
|
||||
var content_url = refstackApiUrl + '/results?page=' + $scope.currentPage;
|
||||
var start = $filter('date')($scope.startDate, "yyyy-MM-dd");
|
||||
var content_url = refstackApiUrl + '/results?page=' +
|
||||
$scope.currentPage;
|
||||
var start = $filter('date')($scope.startDate, 'yyyy-MM-dd');
|
||||
if (start) {
|
||||
content_url = content_url + "&start_date=" + start + " 00:00:00";
|
||||
content_url =
|
||||
content_url + '&start_date=' + start + ' 00:00:00';
|
||||
}
|
||||
var end = $filter('date')($scope.endDate, "yyyy-MM-dd");
|
||||
var end = $filter('date')($scope.endDate, 'yyyy-MM-dd');
|
||||
if (end) {
|
||||
content_url = content_url + "&end_date=" + end + " 23:59:59";
|
||||
content_url = content_url + '&end_date=' + end + ' 23:59:59';
|
||||
}
|
||||
|
||||
$scope.resultsRequest = $http.get(content_url).success(function(data) {
|
||||
$scope.resultsRequest =
|
||||
$http.get(content_url).success(function (data) {
|
||||
$scope.data = data;
|
||||
$scope.totalItems = $scope.data.pagination.total_pages * $scope.itemsPerPage;
|
||||
$scope.totalItems = $scope.data.pagination.total_pages *
|
||||
$scope.itemsPerPage;
|
||||
$scope.currentPage = $scope.data.pagination.current_page;
|
||||
}).error(function (error) {
|
||||
$scope.data = null;
|
||||
$scope.totalItems = 0
|
||||
$scope.showError = true
|
||||
$scope.error = "Error retrieving results listing from server: " + JSON.stringify(error);
|
||||
$scope.totalItems = 0;
|
||||
$scope.showError = true;
|
||||
$scope.error =
|
||||
'Error retrieving results listing from server: ' +
|
||||
JSON.stringify(error);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$scope.update();
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
/* Refstack Filters */
|
||||
|
||||
var refstackApp = angular.module('refstackApp');
|
||||
@ -7,10 +5,12 @@ var refstackApp = angular.module('refstackApp');
|
||||
// Convert an object of objects to an array of objects to use with ng-repeat
|
||||
// filters.
|
||||
refstackApp.filter('arrayConverter', function () {
|
||||
'use strict';
|
||||
|
||||
return function (objects) {
|
||||
var array = [];
|
||||
angular.forEach(objects, function (object, key) {
|
||||
object['id'] = key;
|
||||
object.id = key;
|
||||
array.push(object);
|
||||
});
|
||||
return array;
|
||||
|
@ -1,15 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
/* Refstack Header Controller */
|
||||
|
||||
var refstackApp = angular.module('refstackApp')
|
||||
refstackApp.controller('headerController', ['$scope', '$location', function($scope, $location) {
|
||||
var refstackApp = angular.module('refstackApp');
|
||||
refstackApp.controller('headerController',
|
||||
['$scope', '$location', function ($scope, $location) {
|
||||
'use strict';
|
||||
|
||||
$scope.navbarCollapsed = true;
|
||||
$scope.isActive = function (viewLocation) {
|
||||
var path = $location.path().substr(0, viewLocation.length);
|
||||
if (path === viewLocation) {
|
||||
// Make sure "/" only matches when viewLocation is "/".
|
||||
if (!($location.path().substr(0).length > 1 && viewLocation.length === 1 )) {
|
||||
if (!($location.path().substr(0).length > 1 &&
|
||||
viewLocation.length === 1 )) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
"license": "Apache2",
|
||||
"devDependencies": {
|
||||
"bower": "1.3.12",
|
||||
"eslint": "^0.21.2",
|
||||
"http-server": "^0.6.1",
|
||||
"karma": "^0.12.23",
|
||||
"karma-chrome-launcher": "^0.1.5",
|
||||
@ -22,6 +23,7 @@
|
||||
"start": "http-server ./app -a 0.0.0.0 -p 8080",
|
||||
"pretest": "npm install",
|
||||
"test": "karma start tests/karma.conf.js",
|
||||
"test-single-run": "karma start tests/karma.conf.js --single-run"
|
||||
"test-single-run": "karma start tests/karma.conf.js --single-run",
|
||||
"lint": "eslint --no-color ./"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
module.exports = function (config) {
|
||||
'use strict';
|
||||
|
||||
config.set({
|
||||
|
||||
basePath: '../',
|
||||
@ -32,7 +34,7 @@ module.exports = function(config){
|
||||
plugins: [
|
||||
'karma-chrome-launcher',
|
||||
'karma-firefox-launcher',
|
||||
'karma-jasmine',
|
||||
'karma-jasmine'
|
||||
],
|
||||
|
||||
junitReporter: {
|
||||
|
@ -1,23 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
/* Jasmine specs for Refstack controllers */
|
||||
describe('Refstack controllers', function () {
|
||||
'use strict';
|
||||
|
||||
describe('headerController', function () {
|
||||
var scope, ctrl, $location;
|
||||
var scope, $location;
|
||||
beforeEach(module('refstackApp'));
|
||||
|
||||
beforeEach(inject(function ($rootScope, $controller, _$location_) {
|
||||
scope = $rootScope.$new();
|
||||
$location = _$location_;
|
||||
ctrl = $controller('headerController', {$scope: scope});
|
||||
$controller('headerController', {$scope: scope});
|
||||
}));
|
||||
|
||||
it('should set "navbarCollapsed" to true', function () {
|
||||
expect(scope.navbarCollapsed).toBe(true);
|
||||
});
|
||||
|
||||
it('should have a function to check if the URL path is active', function() {
|
||||
it('should have a function to check if the URL path is active',
|
||||
function () {
|
||||
$location.path('/');
|
||||
expect($location.path()).toBe('/');
|
||||
expect(scope.isActive('/')).toBe(true);
|
||||
@ -30,8 +30,8 @@ describe('Refstack controllers', function() {
|
||||
});
|
||||
|
||||
describe('capabilitiesController', function () {
|
||||
var scope, ctrl, $httpBackend, refstackApiUrl;
|
||||
var fakeApiUrl = "http://foo.bar/v1";
|
||||
var scope, $httpBackend;
|
||||
var fakeApiUrl = 'http://foo.bar/v1';
|
||||
beforeEach(function () {
|
||||
module('refstackApp');
|
||||
module(function ($provide) {
|
||||
@ -42,32 +42,41 @@ describe('Refstack controllers', function() {
|
||||
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
scope = $rootScope.$new();
|
||||
ctrl = $controller('capabilitiesController', {$scope: scope});
|
||||
$controller('capabilitiesController', {$scope: scope});
|
||||
}));
|
||||
|
||||
it('should set default states', function () {
|
||||
expect(scope.hideAchievements).toBe(true);
|
||||
expect(scope.hideTests).toBe(true);
|
||||
expect(scope.target).toBe('platform');
|
||||
expect(scope.status).toEqual({required: 'required', advisory: '',
|
||||
deprecated: '', removed: ''});
|
||||
expect(scope.status).toEqual({
|
||||
required: 'required', advisory: '',
|
||||
deprecated: '', removed: ''
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch the selected capabilities version', function () {
|
||||
$httpBackend.expectGET(fakeApiUrl+'/capabilities').respond(['2015.03.json', '2015.04.json']);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/capabilities').respond(['2015.03.json', '2015.04.json']);
|
||||
// Should call request with latest version.
|
||||
$httpBackend.expectGET(fakeApiUrl+'/capabilities/2015.04.json').respond({'foo': 'bar'});
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/capabilities/2015.04.json').respond({'foo': 'bar'});
|
||||
$httpBackend.flush();
|
||||
// The version list should be sorted latest first.
|
||||
expect(scope.versionList).toEqual(['2015.04.json', '2015.03.json']);
|
||||
expect(scope.capabilities).toEqual({'foo': 'bar'});
|
||||
});
|
||||
|
||||
it('should have a function to check if a status filter is selected', function() {
|
||||
expect(scope.filterStatus({'status': 'required'})).toBe(true);
|
||||
expect(scope.filterStatus({'status': 'advisory'})).toBe(false);
|
||||
expect(scope.filterStatus({'status': 'deprecated'})).toBe(false);
|
||||
expect(scope.filterStatus({'status': 'removed'})).toBe(false);
|
||||
it('should have a function to check if a status filter is selected',
|
||||
function () {
|
||||
expect(scope.filterStatus({'status': 'required'}))
|
||||
.toBe(true);
|
||||
expect(scope.filterStatus({'status': 'advisory'}))
|
||||
.toBe(false);
|
||||
expect(scope.filterStatus({'status': 'deprecated'}))
|
||||
.toBe(false);
|
||||
expect(scope.filterStatus({'status': 'removed'}))
|
||||
.toBe(false);
|
||||
|
||||
scope.status = {
|
||||
required: 'required',
|
||||
@ -82,8 +91,11 @@ describe('Refstack controllers', function() {
|
||||
expect(scope.filterStatus({'status': 'removed'})).toBe(true);
|
||||
});
|
||||
|
||||
it('should have a function to check if a capability belongs to a program', function() {
|
||||
scope.capabilities = {'platform': {'required': ['compute']},
|
||||
it('should have a function to check if a capability belongs' +
|
||||
' to a program',
|
||||
function () {
|
||||
scope.capabilities = {
|
||||
'platform': {'required': ['compute']},
|
||||
'components': {
|
||||
'compute': {
|
||||
'required': ['cap_id_1'],
|
||||
@ -91,7 +103,8 @@ describe('Refstack controllers', function() {
|
||||
'deprecated': ['cap_id_3'],
|
||||
'removed': ['cap_id_4']
|
||||
}
|
||||
}};
|
||||
}
|
||||
};
|
||||
expect(scope.filterProgram({'id': 'cap_id_1'})).toBe(true);
|
||||
expect(scope.filterProgram({'id': 'cap_id_2'})).toBe(true);
|
||||
expect(scope.filterProgram({'id': 'cap_id_3'})).toBe(true);
|
||||
@ -101,12 +114,16 @@ describe('Refstack controllers', function() {
|
||||
});
|
||||
|
||||
describe('resultsController', function () {
|
||||
var scope, ctrl, $httpBackend, refstackApiUrl;
|
||||
var fakeApiUrl = "http://foo.bar/v1";
|
||||
var fakeResponse = {'pagination': {'current_page': 1, 'total_pages': 2},
|
||||
'results': [{'created_at': '2015-03-09 01:23:45',
|
||||
var scope, $httpBackend;
|
||||
var fakeApiUrl = 'http://foo.bar/v1';
|
||||
var fakeResponse = {
|
||||
'pagination': {'current_page': 1, 'total_pages': 2},
|
||||
'results': [{
|
||||
'created_at': '2015-03-09 01:23:45',
|
||||
'test_id': 'some-id',
|
||||
'cpid': 'some-cpid'}]};
|
||||
'cpid': 'some-cpid'
|
||||
}]
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
module('refstackApp');
|
||||
@ -118,12 +135,14 @@ describe('Refstack controllers', function() {
|
||||
beforeEach(inject(function (_$httpBackend_, $rootScope, $controller) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
scope = $rootScope.$new();
|
||||
ctrl = $controller('resultsController', {$scope: scope});
|
||||
$controller('resultsController', {$scope: scope});
|
||||
}));
|
||||
|
||||
it('should fetch the first page of results with proper URL args', function() {
|
||||
it('should fetch the first page of results with proper URL args',
|
||||
function () {
|
||||
// Initial results should be page 1 of all results.
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/results?page=1').respond(fakeResponse);
|
||||
$httpBackend.flush();
|
||||
expect(scope.data).toEqual(fakeResponse);
|
||||
expect(scope.currentPage).toBe(1);
|
||||
@ -132,39 +151,49 @@ describe('Refstack controllers', function() {
|
||||
scope.startDate = new Date('2015-03-10T11:51:00');
|
||||
scope.endDate = new Date('2015-04-10T11:51:00');
|
||||
scope.update();
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results?page=1&start_date=2015-03-10 00:00:00&end_date=2015-04-10 23:59:59').respond(fakeResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/results?page=1' +
|
||||
'&start_date=2015-03-10 00:00:00' +
|
||||
'&end_date=2015-04-10 23:59:59')
|
||||
.respond(fakeResponse);
|
||||
$httpBackend.flush();
|
||||
expect(scope.data).toEqual(fakeResponse);
|
||||
expect(scope.currentPage).toBe(1);
|
||||
});
|
||||
|
||||
it('should set an error when results cannot be retrieved', function () {
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(404, {'detail': 'Not Found'});
|
||||
$httpBackend.expectGET(fakeApiUrl + '/results?page=1').respond(404,
|
||||
{'detail': 'Not Found'});
|
||||
$httpBackend.flush();
|
||||
expect(scope.data).toBe(null);
|
||||
expect(scope.error).toEqual('Error retrieving results listing from server: {"detail":"Not Found"}');
|
||||
expect(scope.error).toEqual('Error retrieving results listing ' +
|
||||
'from server: {"detail":"Not Found"}');
|
||||
expect(scope.totalItems).toBe(0);
|
||||
expect(scope.showError).toBe(true);
|
||||
});
|
||||
|
||||
it('should have an function to clear filters and update the view', function() {
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
|
||||
scope.startDate = "some date";
|
||||
scope.endDate = "some other date";
|
||||
it('should have an function to clear filters and update the view',
|
||||
function () {
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/results?page=1').respond(fakeResponse);
|
||||
scope.startDate = 'some date';
|
||||
scope.endDate = 'some other date';
|
||||
scope.clearFilters();
|
||||
expect(scope.startDate).toBe(null);
|
||||
expect(scope.endDate).toBe(null);
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results?page=1').respond(fakeResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/results?page=1').respond(fakeResponse);
|
||||
$httpBackend.flush();
|
||||
expect(scope.data).toEqual(fakeResponse);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resultsReportController', function () {
|
||||
var scope, ctrl, $httpBackend, refstackApiUrl, stateparams;
|
||||
var fakeApiUrl = "http://foo.bar/v1";
|
||||
var fakeResultResponse = {'results': ['test_id_1']}
|
||||
var fakeCapabilityResponse = {'platform': {'required': ['compute']},
|
||||
var scope, $httpBackend, stateparams;
|
||||
var fakeApiUrl = 'http://foo.bar/v1';
|
||||
var fakeResultResponse = {'results': ['test_id_1']};
|
||||
var fakeCapabilityResponse = {
|
||||
'platform': {'required': ['compute']},
|
||||
'components': {
|
||||
'compute': {
|
||||
'required': ['cap_id_1'],
|
||||
@ -193,32 +222,46 @@ describe('Refstack controllers', function() {
|
||||
$httpBackend = _$httpBackend_;
|
||||
stateparams = {testID: 1234};
|
||||
scope = $rootScope.$new();
|
||||
ctrl = $controller('resultsReportController', {$scope: scope, $stateParams: stateparams});
|
||||
$controller('resultsReportController',
|
||||
{$scope: scope, $stateParams: stateparams});
|
||||
}));
|
||||
|
||||
it('should make all necessary API requests to get results and capabilities', function() {
|
||||
$httpBackend.expectGET(fakeApiUrl+'/results/1234').respond(fakeResultResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl+'/capabilities').respond(['2015.03.json', '2015.04.json']);
|
||||
it('should make all necessary API requests to get results ' +
|
||||
'and capabilities',
|
||||
function () {
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/results/1234').respond(fakeResultResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/capabilities').respond(['2015.03.json', '2015.04.json']);
|
||||
// Should call request with latest version.
|
||||
$httpBackend.expectGET(fakeApiUrl+'/capabilities/2015.04.json').respond(fakeCapabilityResponse);
|
||||
$httpBackend.expectGET(fakeApiUrl +
|
||||
'/capabilities/2015.04.json').respond(fakeCapabilityResponse);
|
||||
$httpBackend.flush();
|
||||
expect(scope.resultsData).toEqual(fakeResultResponse);
|
||||
// The version list should be sorted latest first.
|
||||
expect(scope.versionList).toEqual(['2015.04.json', '2015.03.json']);
|
||||
expect(scope.versionList).toEqual(['2015.04.json',
|
||||
'2015.03.json']);
|
||||
expect(scope.capabilityData).toEqual(fakeCapabilityResponse);
|
||||
});
|
||||
|
||||
it('should be able to sort the results into a capability object', function() {
|
||||
it('should be able to sort the results into a capability object',
|
||||
function () {
|
||||
scope.resultsData = fakeResultResponse;
|
||||
scope.capabilityData = fakeCapabilityResponse;
|
||||
scope.buildCapabilityObject();
|
||||
var expectedCapsObject = {'required': {'caps': [{'id': 'cap_id_1',
|
||||
var expectedCapsObject = {
|
||||
'required': {
|
||||
'caps': [{
|
||||
'id': 'cap_id_1',
|
||||
'passedTests': ['test_id_1'],
|
||||
'notPassedTests': ['test_id_2']}],
|
||||
'count': 2, 'passedCount': 1},
|
||||
'notPassedTests': ['test_id_2']
|
||||
}],
|
||||
'count': 2, 'passedCount': 1
|
||||
},
|
||||
'advisory': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
'deprecated': {'caps': [], 'count': 0, 'passedCount': 0},
|
||||
'removed': {'caps': [], 'count': 0, 'passedCount': 0}};
|
||||
'removed': {'caps': [], 'count': 0, 'passedCount': 0}
|
||||
};
|
||||
expect(scope.caps).toEqual(expectedCapsObject);
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/* Jasmine specs for Refstack filters */
|
||||
describe('Refstack filters', function () {
|
||||
'use strict';
|
||||
|
||||
describe('Filter: arrayConverter', function () {
|
||||
var $filter;
|
||||
|
Loading…
Reference in New Issue
Block a user