Update node packages and styling

With the update of some linting packages, several style fixes
were needed to conform with the updated style guidelines.

Change-Id: If73036a6d4a3a2f6e93b15d1fa6ed3d253fdc7b1
This commit is contained in:
Paul Van Eck 2017-12-18 13:53:06 -08:00
parent 33eb6586cf
commit 6d473eed7d
14 changed files with 264 additions and 299 deletions

View File

@ -57,6 +57,8 @@
"no-extra-boolean-cast": 0,
"operator-linebreak": 0,
"require-jsdoc": 2,
"quote-props": 0,
"valid-jsdoc": 0,
// Stylistic
"indent": [2, 4, {SwitchCase: 1}],

View File

@ -5,24 +5,22 @@
"description": "A user interface for RefStack",
"license": "Apache2",
"devDependencies": {
"bower": "1.3.12",
"eslint": "1.5.1",
"eslint-config-openstack": "1.2.1",
"eslint-plugin-angular": "0.12.0",
"http-server": "^0.6.1",
"karma": "^0.12.23",
"karma-chrome-launcher": "^0.1.5",
"karma-cli": "0.0.4",
"karma-jasmine": "^0.2.2",
"protractor": "~1.0.0"
"bower": "1.7.5",
"eslint": "^3.0.0",
"eslint-config-openstack": "4.0.1",
"eslint-plugin-angular": "1.4.0",
"jasmine-core": "2.8.0",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "^1.1.0"
},
"scripts": {
"postinstall": "bower install --config.interactive=false",
"prestart": "npm install",
"start": "http-server ./refstack-ui/app -a 0.0.0.0 -p 8080",
"pretest": "npm install",
"test": "karma start ./refstack-ui/tests/karma.conf.js --single-run",
"test-auto-watch": "karma start ./refstack-ui/tests/karma.conf.js --auto-watch",
"test": "if [ -z $CHROME_BIN ];then export CHROME_BIN=/usr/bin/chromium-browser;fi && karma start ./refstack-ui/tests/karma.conf.js --single-run",
"test-auto-watch": "if [ -z $CHROME_BIN ];then export CHROME_BIN=/usr/bin/chromium-browser;fi && karma start ./refstack-ui/tests/karma.conf.js --auto-watch",
"lint": "eslint -c ./.eslintrc --no-color ./refstack-ui"
}
}

View File

@ -74,8 +74,7 @@
var hash = $location.hash();
if (hash && hash in ctrl.options) {
ctrl.selectOption(hash);
}
else {
} else {
ctrl.selectOption('about');
}
}

View File

@ -94,8 +94,7 @@
data.metadata.os_trademark_approval.releases;
ctrl.guidelineStatus =
data.metadata.os_trademark_approval.status;
}
else {
} else {
ctrl.schema = data.schema;
ctrl.criteria = data.criteria;
ctrl.releases = data.releases;
@ -121,6 +120,7 @@
ctrl.targetCapabilities = {};
var components = ctrl.guidelines.components;
var targetCaps = ctrl.targetCapabilities;
var targetComponents = null;
// The 'platform' target is comprised of multiple components, so
// we need to get the capabilities belonging to each of its
@ -133,15 +133,14 @@
'object': 'OpenStack Powered Storage'
};
var targetComponents = ctrl.guidelines.platforms[
targetComponents = ctrl.guidelines.platforms[
platformsMap[ctrl.target]].components.map(
function(c) {
return c.name;
}
);
}
else {
var targetComponents = ctrl.guidelines.platform.required;
} else {
targetComponents = ctrl.guidelines.platform.required;
}
// This will contain status priority values, where lower
@ -173,15 +172,13 @@
statusMap[targetCaps[cap]]) {
targetCaps[cap] = status;
}
}
else {
} else {
targetCaps[cap] = status;
}
});
});
});
}
else {
} else {
angular.forEach(components[ctrl.target],
function (caps, status) {
angular.forEach(caps, function(cap) {
@ -200,14 +197,14 @@
*/
function filterStatus(capability) {
var caps = ctrl.targetCapabilities;
return (ctrl.status.required &&
caps[capability.id] === 'required') ||
(ctrl.status.advisory &&
caps[capability.id] === 'advisory') ||
(ctrl.status.deprecated &&
caps[capability.id] === 'deprecated') ||
(ctrl.status.removed &&
caps[capability.id] === 'removed');
return ctrl.status.required &&
caps[capability.id] === 'required' ||
ctrl.status.advisory &&
caps[capability.id] === 'advisory' ||
ctrl.status.deprecated &&
caps[capability.id] === 'deprecated' ||
ctrl.status.removed &&
caps[capability.id] === 'removed';
}
/**
@ -282,8 +279,7 @@
// Check if the API URL is absolute or relative.
if (refstackApiUrl.indexOf('http') > -1) {
ctrl.url = refstackApiUrl;
}
else {
} else {
ctrl.url = location.protocol + '//' + location.host +
refstackApiUrl;
}
@ -333,8 +329,7 @@
ctrl.testListString = response.data;
if (!ctrl.testListString) {
ctrl.testListCount = 0;
}
else {
} else {
ctrl.testListCount =
ctrl.testListString.split('\n').length;
}
@ -345,8 +340,7 @@
response.data.message) {
ctrl.error = 'Error retrieving test list: ' +
response.data.message;
}
else {
} else {
ctrl.error = 'Unknown error retrieving test list.';
}
});

View File

@ -232,8 +232,7 @@
}).error(function (error) {
raiseAlert('danger', error.title, error.detail);
});
}
else {
} else {
ctrl.unassociateRequest = $http.delete(metaUrl)
.success(function () {
ctrl.testsData[index][editFlag] = false;
@ -446,8 +445,8 @@
var url = [refstackApiUrl, '/products/', ctrl.product.id].join('');
var properties = propertiesToJson();
var content = {'description': ctrl.product.description,
'properties': properties};
if (ctrl.productName != ctrl.product.name) {
'properties': properties};
if (ctrl.productName !== ctrl.product.name) {
content.name = ctrl.product.name;
}
@ -468,8 +467,7 @@
ctrl.showError = true;
ctrl.error = error.detail;
});
}
else {
} else {
ctrl.showSuccess = true;
$state.reload();
}

View File

@ -20,15 +20,14 @@
.controller('ProductsController', ProductsController);
ProductsController.$inject = [
'$rootScope', '$scope', '$http', '$state',
'refstackApiUrl','raiseAlert'
'$rootScope', '$scope', '$http', '$state', 'refstackApiUrl'
];
/**
* RefStack Products Controller
*/
function ProductsController($rootScope, $scope, $http, $state,
refstackApiUrl, raiseAlert) {
refstackApiUrl) {
var ctrl = this;
ctrl.update = update;
@ -82,7 +81,7 @@
ctrl.showError = false;
// Construct the API URL based on user-specified filters.
var contentUrl = refstackApiUrl + '/products';
if (typeof ctrl.rawData == 'undefined'
if (typeof ctrl.rawData === 'undefined'
|| ctrl.rawData === null) {
ctrl.productsRequest =
$http.get(contentUrl).success(function (data) {
@ -106,7 +105,8 @@
function updateData() {
ctrl.data = {};
ctrl.data.products = ctrl.rawData.products.filter(function(s) {
return ctrl._filterProduct(s); });
return ctrl._filterProduct(s);
});
ctrl.data.products.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
@ -165,7 +165,7 @@
ctrl.vendors.sort(function(a, b) {
return a.name.localeCompare(b.name);
});
if (ctrl.vendors.length == 0) {
if (ctrl.vendors.length === 0) {
ctrl.vendors.push({name: 'Create New...', id: ''});
}
ctrl.organizationId = ctrl.vendors[0].id;
@ -189,9 +189,9 @@
name: ctrl.name,
description: ctrl.description,
organization_id: ctrl.organizationId,
product_type: parseInt(ctrl.productType)
product_type: parseInt(ctrl.productType, 10)
};
$http.post(url, data).success(function (data) {
$http.post(url, data).success(function () {
ctrl.rawData = null;
ctrl.showSuccess = true;
ctrl.name = '';

View File

@ -234,8 +234,7 @@
data.metadata.os_trademark_approval.status;
ctrl.releases =
data.metadata.os_trademark_approval.releases;
}
else {
} else {
ctrl.schemaVersion = data.schema;
ctrl.guidelineStatus = data.status;
ctrl.releases = data.releases;
@ -257,6 +256,7 @@
function getTargetCapabilities() {
var components = ctrl.guidelineData.components;
var targetCaps = {};
var targetComponents = null;
// The 'platform' target is comprised of multiple components, so
// we need to get the capabilities belonging to each of its
@ -269,15 +269,14 @@
'object': 'OpenStack Powered Storage'
};
var targetComponents = ctrl.guidelineData.platforms[
targetComponents = ctrl.guidelineData.platforms[
platformsMap[ctrl.target]].components.map(
function(c) {
return c.name;
}
);
}
else {
var targetComponents = ctrl.guidelineData.platform.required;
} else {
targetComponents = ctrl.guidelineData.platform.required;
}
// This will contain status priority values, where lower
@ -309,15 +308,13 @@
statusMap[targetCaps[cap]]) {
targetCaps[cap] = status;
}
}
else {
} else {
targetCaps[cap] = status;
}
});
});
});
}
else {
} else {
angular.forEach(components[ctrl.target],
function (caps, status) {
angular.forEach(caps, function(cap) {
@ -353,8 +350,7 @@
if (capDetails.flagged.indexOf(testId) > -1) {
cap.passedFlagged.push(testId);
}
}
else {
} else {
cap.notPassedTests.push(testId);
if (capDetails.flagged.indexOf(testId) > -1) {
cap.notPassedFlagged.push(testId);
@ -393,8 +389,7 @@
// If the test ID is in the results' test list.
if (ctrl.resultsData.results.indexOf(testId) > -1) {
passed = true;
}
else if ('aliases' in details) {
} else if ('aliases' in details) {
var len = details.aliases.length;
for (var i = 0; i < len; i++) {
var alias = details.aliases[i];
@ -412,8 +407,7 @@
if ('flagged' in details) {
cap.passedFlagged.push(testId);
}
}
else {
} else {
cap.notPassedTests.push(testId);
if ('flagged' in details) {
cap.notPassedFlagged.push(testId);
@ -435,18 +429,19 @@
// objects with details regarding each capability.
ctrl.caps = {
'required': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'advisory': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'deprecated': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'removed': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0}
'flagFailCount': 0, 'flagPassCount': 0}
};
var capMethod = null;
switch (ctrl.schemaVersion) {
case '1.2':
var capMethod = 'buildCapabilityV1_2';
capMethod = 'buildCapabilityV1_2';
break;
case '1.3':
case '1.4':
@ -478,8 +473,8 @@
ctrl.caps[status].caps.push(cap);
});
ctrl.requiredPassPercent = (ctrl.caps.required.passedCount *
100 / ctrl.caps.required.count);
ctrl.requiredPassPercent = ctrl.caps.required.passedCount *
100 / ctrl.caps.required.count;
ctrl.totalRequiredFailCount = ctrl.caps.required.count -
ctrl.caps.required.passedCount;
@ -492,8 +487,8 @@
(ctrl.totalRequiredFailCount -
ctrl.caps.required.flagFailCount);
ctrl.nonFlagRequiredPassPercent = (ctrl.nonFlagPassCount *
100 / ctrl.totalNonFlagCount);
ctrl.nonFlagRequiredPassPercent = ctrl.nonFlagPassCount *
100 / ctrl.totalNonFlagCount;
}
/**
@ -506,10 +501,10 @@
if (!capObj) {
return false;
}
return (((ctrl.schemaVersion === '1.2') &&
(capObj.flagged.indexOf(test) > -1)) ||
((ctrl.schemaVersion >= '1.3') &&
(capObj.tests[test].flagged)));
return ctrl.schemaVersion === '1.2' &&
capObj.flagged.indexOf(test) > -1 ||
ctrl.schemaVersion >= '1.3' &&
capObj.tests[test].flagged;
}
/**
@ -520,19 +515,17 @@
* @returns {String} reason
*/
function getFlaggedReason(test, capObj) {
if ((ctrl.schemaVersion === '1.2') &&
(ctrl.isTestFlagged(test, capObj))) {
if (ctrl.schemaVersion === '1.2' &&
ctrl.isTestFlagged(test, capObj)) {
// Return a generic message since schema 1.2 does not
// provide flag reasons.
return 'Interop Working Group has flagged this test.';
}
else if ((ctrl.schemaVersion >= '1.3') &&
(ctrl.isTestFlagged(test, capObj))) {
} else if (ctrl.schemaVersion >= '1.3' &&
ctrl.isTestFlagged(test, capObj)) {
return capObj.tests[test].flagged.reason;
}
else {
} else {
return '';
}
}
@ -545,14 +538,14 @@
* @returns {Boolean} true if capability should be shown
*/
function isCapabilityShown(capability) {
return ((ctrl.testStatus === 'total') ||
(ctrl.testStatus === 'passed' &&
capability.passedTests.length > 0) ||
(ctrl.testStatus === 'not passed' &&
capability.notPassedTests.length > 0) ||
(ctrl.testStatus === 'flagged' &&
(capability.passedFlagged.length +
capability.notPassedFlagged.length > 0)));
return ctrl.testStatus === 'total' ||
ctrl.testStatus === 'passed' &&
capability.passedTests.length > 0 ||
ctrl.testStatus === 'not passed' &&
capability.notPassedTests.length > 0 ||
ctrl.testStatus === 'flagged' &&
capability.passedFlagged.length +
capability.notPassedFlagged.length > 0;
}
/**
@ -563,14 +556,14 @@
* @return {Boolean} true if test should be shown
*/
function isTestShown(test, capability) {
return ((ctrl.testStatus === 'total') ||
(ctrl.testStatus === 'passed' &&
capability.passedTests.indexOf(test) > -1) ||
(ctrl.testStatus === 'not passed' &&
capability.notPassedTests.indexOf(test) > -1) ||
(ctrl.testStatus === 'flagged' &&
return ctrl.testStatus === 'total' ||
ctrl.testStatus === 'passed' &&
capability.passedTests.indexOf(test) > -1 ||
ctrl.testStatus === 'not passed' &&
capability.notPassedTests.indexOf(test) > -1 ||
ctrl.testStatus === 'flagged' &&
(capability.passedFlagged.indexOf(test) > -1 ||
capability.notPassedFlagged.indexOf(test) > -1)));
capability.notPassedFlagged.indexOf(test) > -1);
}
/**
@ -583,18 +576,14 @@
if (ctrl.testStatus === 'total') {
return capability.passedTests.length +
capability.notPassedTests.length;
}
else if (ctrl.testStatus === 'passed') {
} else if (ctrl.testStatus === 'passed') {
return capability.passedTests.length;
}
else if (ctrl.testStatus === 'not passed') {
} else if (ctrl.testStatus === 'not passed') {
return capability.notPassedTests.length;
}
else if (ctrl.testStatus === 'flagged') {
} else if (ctrl.testStatus === 'flagged') {
return capability.passedFlagged.length +
capability.notPassedFlagged.length;
}
else {
} else {
return 0;
}
}
@ -608,22 +597,17 @@
function getStatusTestCount(status) {
if (!ctrl.caps) {
return -1;
}
else if (ctrl.testStatus === 'total') {
} else if (ctrl.testStatus === 'total') {
return ctrl.caps[status].count;
}
else if (ctrl.testStatus === 'passed') {
} else if (ctrl.testStatus === 'passed') {
return ctrl.caps[status].passedCount;
}
else if (ctrl.testStatus === 'not passed') {
} else if (ctrl.testStatus === 'not passed') {
return ctrl.caps[status].count -
ctrl.caps[status].passedCount;
}
else if (ctrl.testStatus === 'flagged') {
} else if (ctrl.testStatus === 'flagged') {
return ctrl.caps[status].flagFailCount +
ctrl.caps[status].flagPassCount;
}
else {
} else {
return -1;
}
}
@ -791,8 +775,8 @@
* a test result.
*/
function associateProductVersion() {
var verId = (ctrl.selectedVersion ?
ctrl.selectedVersion.id : null);
var verId = ctrl.selectedVersion ?
ctrl.selectedVersion.id : null;
var testId = resultsData.id;
var url = refstackApiUrl + '/results/' + testId;
ctrl.associateRequest = $http.put(url, {'product_version_id':
@ -822,11 +806,10 @@
.success(function (data) {
ctrl.productVersions = data;
if (ctrl.prodVersionCopy &&
ctrl.prodVersionCopy.product_info.id ==
ctrl.prodVersionCopy.product_info.id ===
ctrl.selectedProduct.id) {
ctrl.selectedVersion = ctrl.prodVersionCopy;
}
else {
} else {
angular.forEach(data, function(ver) {
if (!ver.version) {
ctrl.selectedVersion = ver;
@ -850,13 +833,13 @@
var metaFields = ['target', 'guideline', 'shared'];
var meta = ctrl.metaCopy;
angular.forEach(metaFields, function(field) {
var oldMetaValue = (field in ctrl.resultsData.meta) ?
var oldMetaValue = field in ctrl.resultsData.meta ?
ctrl.resultsData.meta[field] : '';
if (field in meta && oldMetaValue != meta[field]) {
if (field in meta && oldMetaValue !== meta[field]) {
var metaUrl = metaBaseUrl + field;
if (meta[field]) {
ctrl.assocRequest = $http.post(metaUrl, meta[field])
.success(function(data) {
.success(function() {
ctrl.resultsData.meta[field] = meta[field];
})
.error(function (error) {
@ -866,10 +849,9 @@
'Error associating metadata with ' +
'test run: ' + angular.toJson(error);
});
}
else {
} else {
ctrl.unassocRequest = $http.delete(metaUrl)
.success(function (data) {
.success(function () {
delete ctrl.resultsData.meta[field];
delete meta[field];
})

View File

@ -183,18 +183,16 @@
}).error(function (error) {
raiseAlert('danger', error.title, error.detail);
});
}
else {
} else {
ctrl.unassociateRequest = $http.delete(metaUrl)
.success(function () {
ctrl.data.results[index][editFlag] = false;
}).error(function (error) {
if (error.code == 404) {
if (error.code === 404) {
// Key doesn't exist, so count it as a success,
// and don't raise an alert.
ctrl.data.results[index][editFlag] = false;
}
else {
} else {
raiseAlert('danger', error.title, error.detail);
}
});
@ -273,13 +271,13 @@
* a test result.
*/
function associateProductVersion(result) {
var verId = (result.selectedVersion ?
result.selectedVersion.id : null);
var verId = result.selectedVersion ?
result.selectedVersion.id : null;
var testId = result.id;
var url = refstackApiUrl + '/results/' + testId;
ctrl.associateRequest = $http.put(url, {'product_version_id':
verId})
.success(function (data) {
.success(function () {
result.product_version = result.selectedVersion;
if (result.selectedVersion) {
result.product_version.product_info =

View File

@ -70,10 +70,10 @@
ctrl.vendor = data;
var isAdmin = $rootScope.auth.currentUser.is_admin;
ctrl.vendor.canDelete = ctrl.vendor.canEdit =
ctrl.vendor.type != 0
ctrl.vendor.type !== 0
&& (ctrl.vendor.can_manage || isAdmin);
ctrl.vendor.canRegister =
ctrl.vendor.type == 1;
ctrl.vendor.type === 1;
ctrl.vendor.canApprove = isAdmin;
ctrl.vendorProperties = angular.fromJson(data.properties);
}).error(function(error) {
@ -89,7 +89,7 @@
*/
function registerVendor() {
var url = [refstackApiUrl, '/vendors/', ctrl.vendorId,
'/action'].join('');
'/action'].join('');
$http.post(url, {register: null}).success(function() {
ctrl.getVendor();
}).error(function(error) {
@ -102,7 +102,7 @@
*/
function approveVendor() {
var url = [refstackApiUrl, '/vendors/', ctrl.vendorId,
'/action'].join('');
'/action'].join('');
$http.post(url, {approve: null}).success(function() {
ctrl.getVendor();
}).error(function(error) {
@ -116,7 +116,7 @@
function declineVendor() {
confirmModal('Please input decline reason', function(reason) {
var url = [refstackApiUrl, '/vendors/', ctrl.vendorId,
'/action'].join('');
'/action'].join('');
var content = {deny: null, registration_decline_reason: reason};
$http.post(url, content).success(
function() {
@ -198,7 +198,7 @@
*/
function removeUserFromVendor(openid) {
var url = [refstackApiUrl, '/vendors/', ctrl.vendorId,
'/users/', btoa(openid)].join('');
'/users/', btoa(openid)].join('');
$http.delete(url).success(function () {
ctrl.getVendorUsers();
}).error(function (error) {
@ -212,7 +212,7 @@
*/
function addUserToVendor(openid) {
var url = [refstackApiUrl, '/vendors/', ctrl.vendorId,
'/users/', btoa(openid)].join('');
'/users/', btoa(openid)].join('');
$http.put(url).success(function() {
ctrl.userToAdd = '';
ctrl.getVendorUsers();
@ -298,8 +298,8 @@
var url = [refstackApiUrl, '/vendors/', ctrl.vendor.id].join('');
var properties = propertiesToJson();
var content = {'description': ctrl.vendor.description,
'properties': properties};
if (ctrl.vendorName != ctrl.vendor.name) {
'properties': properties};
if (ctrl.vendorName !== ctrl.vendor.name) {
content.name = ctrl.vendor.name;
}
$http.put(url, content).success(function() {

View File

@ -20,9 +20,7 @@
.controller('VendorsController', VendorsController);
VendorsController.$inject = [
'$rootScope', '$scope', '$http', '$state',
'refstackApiUrl','raiseAlert'
];
'$rootScope', '$scope', '$http', '$state', 'refstackApiUrl'];
/**
* RefStack Vendors Controller
@ -30,7 +28,7 @@
* where a user can browse a listing of his/her vendors or public vendors.
*/
function VendorsController($rootScope, $scope, $http, $state,
refstackApiUrl, raiseAlert) {
refstackApiUrl) {
var ctrl = this;
ctrl.update = update;
@ -81,7 +79,7 @@
ctrl.data = null;
// Construct the API URL based on user-specified filters.
var contentUrl = refstackApiUrl + '/vendors';
if (typeof ctrl.rawData == 'undefined'
if (typeof ctrl.rawData === 'undefined'
|| ctrl.rawData === null) {
ctrl.vendorsRequest =
$http.get(contentUrl).success(function (data) {
@ -123,7 +121,7 @@
*/
function _filterVendor(vendor) {
if (!ctrl.isUserVendors) {
return (vendor.type == 0 || vendor.type == 3);
return vendor.type === 0 || vendor.type === 3;
}
if (!$rootScope.auth || !$rootScope.auth.currentUser) {
@ -131,7 +129,7 @@
}
if ($rootScope.auth.currentUser.is_admin) {
return vendor.type != 1 || ctrl.withPrivate;
return vendor.type !== 1 || ctrl.withPrivate;
}
return vendor.can_manage;
@ -148,7 +146,7 @@
name: ctrl.name,
description: ctrl.description
};
$http.post(url, data).success(function (data) {
$http.post(url, data).success(function () {
ctrl.showSuccess = true;
ctrl.name = '';
ctrl.description = '';

View File

@ -44,7 +44,7 @@
if (path === viewLocation) {
// Make sure "/" only matches when viewLocation is "/".
if (!($location.path().substr(0).length > 1 &&
viewLocation.length === 1 )) {
viewLocation.length === 1)) {
return true;
}
}

View File

@ -19,7 +19,6 @@ module.exports = function (config) {
'app/components/**/*.js',
'app/shared/*.js',
'app/shared/**/*.js',
'app/assets/js/*.js',
// Test Specs.
'tests/unit/*.js'

View File

@ -20,8 +20,8 @@ describe('Auth', function () {
it('should show signin url for signed user', function () {
$httpBackend.expectGET(fakeApiUrl +
'/profile').respond({'openid': 'foo@bar.com',
'email': 'foo@bar.com',
'fullname': 'foo' });
'email': 'foo@bar.com',
'fullname': 'foo' });
$httpBackend.flush();
$rootScope.auth.doSignIn();
expect($window.location.href).toBe(fakeApiUrl + '/auth/signin');

View File

@ -135,15 +135,15 @@ describe('Refstack controllers', function () {
$httpBackend.expectGET(fakeApiUrl +
'/guidelines').respond(['next.json', '2015.03.json',
'2015.04.json']);
'2015.04.json']);
// Should call request with latest version.
$httpBackend.expectGET(fakeApiUrl +
'/guidelines/2015.04.json').respond(fakeCaps);
$httpBackend.flush();
// The version list should be sorted latest first.
expect(ctrl.versionList).toEqual(['next.json',
'2015.04.json',
'2015.03.json']);
'2015.04.json',
'2015.03.json']);
expect(ctrl.guidelines).toEqual(fakeCaps);
// The guideline status should be approved.
expect(ctrl.guidelineStatus).toEqual('approved');
@ -201,7 +201,7 @@ describe('Refstack controllers', function () {
$httpBackend.expectGET(fakeApiUrl +
'/guidelines').respond(['next.json', '2015.03.json',
'2017.08.json']);
'2017.08.json']);
// Should call request with latest version.
$httpBackend.expectGET(fakeApiUrl +
'/guidelines/2017.08.json').respond(fakeCaps);
@ -280,18 +280,17 @@ describe('Refstack controllers', function () {
});
describe('TestListModalController', function () {
var modalInstance, ctrl, $window;
var modalInstance, ctrl;
beforeEach(inject(function ($controller, _$window_) {
beforeEach(inject(function ($controller) {
modalInstance = {
dismiss: jasmine.createSpy('modalInstance.dismiss')
};
$window = _$window_;
ctrl = $controller('TestListModalController',
{$uibModalInstance: modalInstance,
target: 'platform',
version: '2016.01',
status: {required: true, advisory: false}}
target: 'platform',
version: '2016.01',
status: {required: true, advisory: false}}
);
}));
@ -418,15 +417,14 @@ describe('Refstack controllers', function () {
$httpBackend.flush();
// Expect the list to have the latest guideline first.
expect(ctrl.versionList).toEqual(['2015.04.json',
'2015.03.json']);
'2015.03.json']);
});
it('should have a function to get products manageable by a user',
function () {
var prodResp = {'products': [{'id': 'abc',
'can_manage': true},
{'id': 'foo',
'can_manage': false}]};
var prodResp = {'products': [
{'id': 'abc', 'can_manage': true},
{'id': 'foo', 'can_manage': false}]};
ctrl.products = null;
$httpBackend.expectGET(fakeApiUrl + '/products')
.respond(200, prodResp);
@ -449,8 +447,8 @@ describe('Refstack controllers', function () {
it('should have a function to associate a product version to a test',
function () {
var result = {'id': 'bar',
'selectedVersion': {'id': 'foo'},
'selectedProduct': {'id': 'prod'}};
'selectedVersion': {'id': 'foo'},
'selectedProduct': {'id': 'prod'}};
ctrl.products = null;
$httpBackend.expectPUT(fakeApiUrl + '/results/bar')
.respond(201);
@ -463,7 +461,7 @@ describe('Refstack controllers', function () {
it('should have a function to get product versions',
function () {
var result = {'id': 'bar',
'selectedProduct': {'id': 'prod'}};
'selectedProduct': {'id': 'prod'}};
var verResp = [{'id': 'ver1', 'version': '1.0'},
{'id': 'ver2', 'version': null}];
ctrl.products = null;
@ -530,7 +528,7 @@ describe('Refstack controllers', function () {
expect(ctrl.resultsData).toEqual(fakeResultResponse);
// The version list should be sorted latest first.
expect(ctrl.versionList).toEqual(['2015.04.json',
'2015.03.json']);
'2015.03.json']);
expect(ctrl.guidelineData).toEqual(fakeCapabilityResponse);
// The guideline status should be approved.
expect(ctrl.guidelineData.status).toEqual('approved');
@ -643,11 +641,11 @@ describe('Refstack controllers', function () {
'flagFailCount': 0, 'flagPassCount': 1
},
'advisory': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'deprecated': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'removed': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0}
'flagFailCount': 0, 'flagPassCount': 0}
};
expect(ctrl.caps).toEqual(expectedCapsObject);
expect(ctrl.requiredPassPercent).toEqual(50);
@ -658,9 +656,9 @@ describe('Refstack controllers', function () {
'schema version 1.3 and above',
function () {
ctrl.resultsData = {'results': ['test_id_1',
'old_test_id_3',
'test_id_4']
};
'old_test_id_3',
'test_id_4']
};
ctrl.guidelineData = {
'platform': {'required': ['compute']},
'schema': '1.4',
@ -704,8 +702,8 @@ describe('Refstack controllers', function () {
'caps': [{
'id': 'cap_id_1',
'passedTests': ['test_id_1',
'test_id_3',
'test_id_4'],
'test_id_3',
'test_id_4'],
'notPassedTests': ['test_id_2'],
'passedFlagged': ['test_id_1'],
'notPassedFlagged': []
@ -714,11 +712,11 @@ describe('Refstack controllers', function () {
'flagFailCount': 0, 'flagPassCount': 1
},
'advisory': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'deprecated': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0},
'flagFailCount': 0, 'flagPassCount': 0},
'removed': {'caps': [], 'count': 0, 'passedCount': 0,
'flagFailCount': 0, 'flagPassCount': 0}
'flagFailCount': 0, 'flagPassCount': 0}
};
expect(ctrl.caps).toEqual(expectedCapsObject);
expect(ctrl.requiredPassPercent).toEqual(75);
@ -741,7 +739,7 @@ describe('Refstack controllers', function () {
it('should have a method to determine if a test is flagged',
function () {
var capObj = {'flagged': [ 'test1'],
'tests': ['test1', 'test2']};
'tests': ['test1', 'test2']};
ctrl.schemaVersion = '1.2';
expect(ctrl.isTestFlagged('test1', capObj)).toEqual(true);
@ -773,7 +771,7 @@ describe('Refstack controllers', function () {
it('should have a method to get the reason a flagged test is flagged',
function () {
var capObj = {'flagged': [ 'test1'],
'tests': ['test1', 'test2']};
'tests': ['test1', 'test2']};
ctrl.schemaVersion = '1.2';
expect(ctrl.getFlaggedReason('test1', capObj)).toEqual(
@ -803,17 +801,17 @@ describe('Refstack controllers', function () {
'be shown',
function () {
var caps = [{'id': 'cap_id_1',
'passedTests': ['test_id_1'],
'notPassedTests': [],
'passedFlagged': ['test_id_1'],
'notPassedFlagged': []
},
{'id': 'cap_id_2',
'passedTests': [],
'notPassedTests': ['test_id_4'],
'passedFlagged': [],
'notPassedFlagged': []
}];
'passedTests': ['test_id_1'],
'notPassedTests': [],
'passedFlagged': ['test_id_1'],
'notPassedFlagged': []
},
{'id': 'cap_id_2',
'passedTests': [],
'notPassedTests': ['test_id_4'],
'passedFlagged': [],
'notPassedFlagged': []
}];
// Check that all capabilities are shown by default.
expect(ctrl.isCapabilityShown(caps[0])).toEqual(true);
@ -838,11 +836,11 @@ describe('Refstack controllers', function () {
it('should have a method to determine whether a test should be shown',
function () {
var cap = {'id': 'cap_id_1',
'passedTests': ['test_id_1'],
'notPassedTests': [],
'passedFlagged': ['test_id_1'],
'notPassedFlagged': []
};
'passedTests': ['test_id_1'],
'notPassedTests': [],
'passedFlagged': ['test_id_1'],
'notPassedFlagged': []
};
expect(ctrl.isTestShown('test_id_1', cap)).toEqual(true);
ctrl.testStatus = 'passed';
@ -857,11 +855,11 @@ describe('Refstack controllers', function () {
'capability belong under the current test filter',
function () {
var cap = {'id': 'cap_id_1',
'passedTests': ['t1', 't2', 't3'],
'notPassedTests': ['t4', 't5', 't6', 't7'],
'passedFlagged': ['t1'],
'notPassedFlagged': ['t3', 't4']
};
'passedTests': ['t1', 't2', 't3'],
'notPassedTests': ['t4', 't5', 't6', 't7'],
'passedFlagged': ['t1'],
'notPassedFlagged': ['t3', 't4']
};
// Should return the count of all tests.
expect(ctrl.getCapabilityTestCount(cap)).toEqual(7);
@ -883,8 +881,8 @@ describe('Refstack controllers', function () {
'belong under the current test filter',
function () {
ctrl.caps = {'required': {'caps': [], 'count': 10,
'passedCount': 6, 'flagFailCount': 3,
'flagPassCount': 2}};
'passedCount': 6, 'flagFailCount': 3,
'flagPassCount': 2}};
// Should return the count of all tests (count).
expect(ctrl.getStatusTestCount('required')).toEqual(10);
@ -984,7 +982,6 @@ describe('Refstack controllers', function () {
'target': 'object'
}
};
var fakeProdResp = {'products': [{'id': 1234}]};
var fakeVersionResp = [{'id': 'ver1', 'version': '1.0'},
{'id': 'ver2', 'version': null}];
@ -997,7 +994,7 @@ describe('Refstack controllers', function () {
};
ctrl = $controller('EditTestModalController',
{$uibModalInstance: modalInstance, $state: state,
resultsData: fakeResultsData}
resultsData: fakeResultsData}
);
$httpBackend.when('GET', fakeApiUrl +
'/guidelines').respond(['2015.03.json', '2015.04.json']);
@ -1121,7 +1118,7 @@ describe('Refstack controllers', function () {
var rootScope, scope, stateParams, ctrl;
var confirmModal = jasmine.createSpy('confirmModal');
var fakeResp = {'id': 'fake-id', 'type': 1,
'can_manage': true, 'properties' : {}};
'can_manage': true, 'properties' : {}};
var fakeUsersResp = [{'openid': 'foo'}];
var fakeProdResp = {'products': [{'id': 123}]};
var fakeWindow = {
@ -1134,13 +1131,13 @@ describe('Refstack controllers', function () {
scope = $rootScope.$new();
rootScope = $rootScope.$new();
rootScope.auth = {'currentUser' : {'is_admin': false,
'openid': 'foo'}
};
'openid': 'foo'}
};
stateParams = {vendorID: 1234};
ctrl = $controller('VendorController',
{$rootScope: rootScope, $scope: scope,
$stateParams: stateParams, $window: fakeWindow,
confirmModal: confirmModal}
$stateParams: stateParams, $window: fakeWindow,
confirmModal: confirmModal}
);
$httpBackend.when('GET', fakeApiUrl +
@ -1237,7 +1234,7 @@ describe('Refstack controllers', function () {
describe('VendorEditModalController', function() {
var rootScope, ctrl, modalInstance, state;
var fakeVendor = {'name': 'Foo', 'description': 'Bar', 'id': '1234',
'properties': {'key1': 'value1', 'key2': 'value2'}};
'properties': {'key1': 'value1', 'key2': 'value2'}};
beforeEach(inject(function ($controller, $rootScope) {
modalInstance = {
@ -1248,12 +1245,12 @@ describe('Refstack controllers', function () {
};
rootScope = $rootScope.$new();
rootScope.auth = {'currentUser' : {'is_admin': true,
'openid': 'foo'}
};
'openid': 'foo'}
};
ctrl = $controller('VendorEditModalController',
{$rootScope: rootScope,
$uibModalInstance: modalInstance, $state: state,
vendor: fakeVendor}
$uibModalInstance: modalInstance, $state: state,
vendor: fakeVendor}
);
}));
@ -1296,17 +1293,17 @@ describe('Refstack controllers', function () {
describe('VendorsController', function () {
var rootScope, scope, ctrl;
var fakeResp = {'vendors': [{'can_manage': true,
'type': 3,
'name': 'Foo'},
{'can_manage': true,
'type': 3,
'name': 'Bar'}]};
'type': 3,
'name': 'Foo'},
{'can_manage': true,
'type': 3,
'name': 'Bar'}]};
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
rootScope = $rootScope.$new();
rootScope.auth = {'currentUser' : {'is_admin': false,
'openid': 'foo'}
};
'openid': 'foo'}
};
ctrl = $controller('VendorsController',
{$rootScope: rootScope, $scope: scope}
);
@ -1328,11 +1325,11 @@ describe('Refstack controllers', function () {
ctrl.rawData = fakeResp;
ctrl.updateData();
var expectedResponse = {'vendors': [{'can_manage': true,
'type': 3,
'name' : 'Bar'},
{'can_manage': true,
'type': 3,
'name': 'Foo'}]};
'type': 3,
'name' : 'Bar'},
{'can_manage': true,
'type': 3,
'name': 'Foo'}]};
expect(ctrl.data).toEqual(expectedResponse);
});
@ -1363,21 +1360,21 @@ describe('Refstack controllers', function () {
describe('ProductsController', function() {
var rootScope, scope, ctrl;
var vendResp = {'vendors': [{'can_manage': true,
'type': 3,
'name': 'Foo',
'id': '123'}]};
'type': 3,
'name': 'Foo',
'id': '123'}]};
var prodResp = {'products': [{'id': 'abc',
'product_type': 1,
'public': 1,
'name': 'Foo Product',
'organization_id': '123'}]};
'product_type': 1,
'public': 1,
'name': 'Foo Product',
'organization_id': '123'}]};
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
rootScope = $rootScope.$new();
rootScope.auth = {'currentUser' : {'is_admin': false,
'openid': 'foo'}
};
'openid': 'foo'}
};
ctrl = $controller('ProductsController',
{$rootScope: rootScope, $scope: scope}
);
@ -1391,24 +1388,24 @@ describe('Refstack controllers', function () {
function () {
$httpBackend.flush();
var newVendResp = {'vendors': [{'name': 'Foo',
'id': '123',
'can_manage': true},
{'name': 'Bar',
'id': '345',
'can_manage': false}]};
'id': '123',
'can_manage': true},
{'name': 'Bar',
'id': '345',
'can_manage': false}]};
$httpBackend.expectGET(fakeApiUrl + '/vendors')
.respond(200, newVendResp);
ctrl.updateVendors();
$httpBackend.flush();
expect(ctrl.allVendors).toEqual({'123': {'name': 'Foo',
'id': '123',
'can_manage': true},
'345': {'name': 'Bar',
'id': '345',
'can_manage': false}});
'id': '123',
'can_manage': true},
'345': {'name': 'Bar',
'id': '345',
'can_manage': false}});
expect(ctrl.vendors).toEqual([{'name': 'Foo',
'id': '123',
'can_manage': true}]);
'id': '123',
'can_manage': true}]);
});
it('should have a function to get products',
@ -1424,14 +1421,14 @@ describe('Refstack controllers', function () {
function () {
$httpBackend.flush();
ctrl.allVendors = {'123': {'name': 'Foo',
'id': '123',
'can_manage': true}};
'id': '123',
'can_manage': true}};
ctrl.updateData();
var expectedData = {'products': [{'id': 'abc',
'product_type': 1,
'public': 1,
'name': 'Foo Product',
'organization_id': '123'}]};
'product_type': 1,
'public': 1,
'name': 'Foo Product',
'organization_id': '123'}]};
expect(ctrl.data).toEqual(expectedData);
});
@ -1449,31 +1446,31 @@ describe('Refstack controllers', function () {
describe('ProductController', function() {
var rootScope, scope, stateParams, ctrl;
var fakeProdResp = {'product_type': 1,
'product_ref_id': null,
'name': 'Good Stuff',
'created_at': '2016-01-01 01:02:03',
'updated_at': '2016-06-15 01:02:04',
'properties': null,
'organization_id': 'fake-org-id',
'public': true,
'can_manage': true,
'created_by_user': 'fake-open-id',
'type': 0,
'id': '1234',
'description': 'some description'};
'product_ref_id': null,
'name': 'Good Stuff',
'created_at': '2016-01-01 01:02:03',
'updated_at': '2016-06-15 01:02:04',
'properties': null,
'organization_id': 'fake-org-id',
'public': true,
'can_manage': true,
'created_by_user': 'fake-open-id',
'type': 0,
'id': '1234',
'description': 'some description'};
var fakeVersionResp = [{'id': 'asdf',
'cpid': null,
'version': '1.0',
'product_id': '1234'}];
'cpid': null,
'version': '1.0',
'product_id': '1234'}];
var fakeTestsResp = {'pagination': {'current_page': 1,
'total_pages': 1},
'results':[{'id': 'foo-test'}]};
'total_pages': 1},
'results':[{'id': 'foo-test'}]};
var fakeVendorResp = {'id': 'fake-org-id',
'type': 3,
'can_manage': true,
'properties' : {},
'name': 'Foo Vendor',
'description': 'foo bar'};
'type': 3,
'can_manage': true,
'properties' : {},
'name': 'Foo Vendor',
'description': 'foo bar'};
var fakeWindow = {
location: {
href: ''
@ -1485,11 +1482,11 @@ describe('Refstack controllers', function () {
rootScope = $rootScope.$new();
stateParams = {id: 1234};
rootScope.auth = {'currentUser' : {'is_admin': false,
'openid': 'foo'}
};
'openid': 'foo'}
};
ctrl = $controller('ProductController',
{$rootScope: rootScope, $scope: scope,
$stateParams: stateParams, $window: fakeWindow}
$stateParams: stateParams, $window: fakeWindow}
);
$httpBackend.when('GET', fakeApiUrl +
'/products/1234').respond(fakeProdResp);
@ -1609,7 +1606,7 @@ describe('Refstack controllers', function () {
var ctrl, modalInstance, state, parent;
var fakeVersion = {'id': 'asdf', 'cpid': null,
'version': '1.0','product_id': '1234'};
'version': '1.0','product_id': '1234'};
beforeEach(inject(function ($controller) {
modalInstance = {
@ -1620,7 +1617,7 @@ describe('Refstack controllers', function () {
};
ctrl = $controller('ProductVersionModalController',
{$uibModalInstance: modalInstance, $state: state,
version: fakeVersion, parent: parent}
version: fakeVersion, parent: parent}
);
}));
@ -1647,9 +1644,9 @@ describe('Refstack controllers', function () {
describe('ProductEditModalController', function() {
var ctrl, modalInstance, state;
var fakeProduct = {'name': 'Foo', 'description': 'Bar', 'id': '1234',
'properties': {'key1': 'value1'}};
'properties': {'key1': 'value1'}};
var fakeVersion = {'version': null, 'product_id': '1234',
'cpid': null, 'id': 'asdf'};
'cpid': null, 'id': 'asdf'};
beforeEach(inject(function ($controller) {
modalInstance = {
@ -1660,8 +1657,8 @@ describe('Refstack controllers', function () {
};
ctrl = $controller('ProductEditModalController',
{$uibModalInstance: modalInstance, $state: state,
product: fakeProduct,
version: fakeVersion}
product: fakeProduct,
version: fakeVersion}
);
}));