policy.js revision feb07dd0f0f4f9f8027a3e94dc08f5d695a0e1a8
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014-2015 ForgeRock AS. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*/
/*global require, define, QUnit, $ */
define([
], function (eventManager, constants, RealmHelper, conf, router, loginHelper, uiUtils, policyDelegate, editAppView, editPolicyView, manageAppsView, policyListView, actionsView, StaticResponseAttributesView, SubjectResponseAttributesView, policyResourcesView, createdResourcesView,
return {
executeAll: function (server) {
module('Applications');
QUnit.ok(editAppView.$el.find('#appDescription').val() === (entity.description ? entity.description : ''), "Description is set");
// Resource Types
selected = _.findByValues(editAppView.data.options.allResourceTypes, 'uuid', editAppView.data.entity.resourceTypeUuids);
title: $.t('policy.resourceTypes.availableResourceTypes'),
filter: true,
}, '<div></div>', function () {
title: $.t('policy.resourceTypes.selectedResourceTypes'),
created: true,
}, '<div></div>', function () {
rightItems = editAppView.resourceTypesListSelectedView.$el.find('.striped-list ul li:not(.invalid)'),
// select and deselect resource types
// add 2
// remove 1
QUnit.equal(entity.resourceTypeUuids.length, initialRight + 1, 'Resource Types can be successfully selected and deselected');
});
});
$('#reviewInfo', editAppView.$el).html(uiUtils.fillTemplateWithData('templates/policy/applications/ReviewApplicationStepTemplate.html', editAppView.data, function () {
QUnit.ok(editAppView.$el.find('#reviewName').html().trim() === entity.name, "Correct name is displayed in the review step");
QUnit.ok(!editAppView.$el.find('#reviewName').parents('.review-row').hasClass('.invalid'), "Validate isn't displayed in the review step");
// both are undefined.
} else {
QUnit.ok(editAppView.$el.find('#reviewDesc').html() === (entity.description ? entity.description : ''), "Correct description is displayed in the review step");
}
QUnit.ok(!editAppView.$el.find('input[name="submitForm"]').is(':disabled'), "Finish button isn't disabled");
}));
});
});
editAppView.render([], function () {
selected = _.findByValues(editAppView.data.options.allResourceTypes, 'uuid', editAppView.data.entity.resourceTypeUuids);
title: $.t('policy.resourceTypes.availableResourceTypes'),
filter: true,
}, '<div></div>', function () {
title: $.t('policy.resourceTypes.selectedResourceTypes'),
created: true,
}, '<div></div>', function () {
rightItems = editAppView.resourceTypesListSelectedView.$el.find('.striped-list ul li:not(.invalid)');
QUnit.equal(editAppView.resourceTypesListSelectedView.$el.find('.striped-list ul li.invalid').length, 1, 'Empty list of Resource Types does not pass validation');
QUnit.equal(editAppView.resourceTypesListSelectedView.$el.find('.striped-list ul li.invalid').length, 0, 'Validation message is not displayed for non-empty list');
QUnit.equal(editAppView.data.entity.resourceTypeUuids.length, 1, 'Resource Types can be successfully selected');
});
});
$('#reviewInfo', editAppView.$el).html(uiUtils.fillTemplateWithData('templates/policy/applications/ReviewApplicationStepTemplate.html', editAppView.data, function () {
QUnit.ok(editAppView.$el.find('input[name="submitForm"]').is(':disabled'), "Finish button is disabled");
}));
});
});
manageAppsView.render([], function () {
QUnit.ok(rowData.length === table.find("tr[id]").length, "Number of rows in grid match number displayed");
QUnit.ok(table.jqGrid('getGridParam', 'colNames').length === table.find("tr[id]")[0].children.length,
'Total number of columns displayed matches number of columns requested');
// sorting
'Sort icon is present for the name column');
QUnit.ok(manageAppsView.$el.find('#apps_name').find('span[sort=desc]').hasClass('ui-state-disabled'),
'Name is sorted in ascending order');
// Pagination
'Total number of records is calculated correctly');
'Number of rows in grid is less than or equal to number of rows requested');
if (recordsTotal > recordsPerPage) {
'Total number of pages is calculated correctly');
} else {
'Total number of pages is calculated correctly');
}
});
});
module('Policies');
var appName = 'iPlanetAMWebAgentService',
policyName = 'test_pol';
QUnit.ok(editPolicyView.validationFields && editPolicyView.validationFields.length > 0, 'Validation is present');
QUnit.equal(editPolicyView.$el.find('[name="submitForm"]').is(':disabled'), false, 'Submit button is enabled');
QUnit.ok(editPolicyView.$el.find('#description').val() === (entity.description ? entity.description : ''), "Description is set");
QUnit.equal(editPolicyView.$el.find('#availableResTypes').val(), entity.resourceTypeUuid, "Resource type is selected");
valid = true;
valid = valid && $(item).text() === item.dataset.resource && _.contains(entity.resources, item.dataset.resource);
});
QUnit.equal(listItems.length, entity.resources.length, "Correct number of resources are displayed");
// Available Patterns
values = [];
});
QUnit.equal(_.difference(values, options.availablePatterns).length, 0, "All available patterns are displayed correctly");
values = [],
valid = true,
NEW_STR = 'newResource',
INVALID_STR = 'invalid/Resource';
valid = false;
}
});
valid = valid && $(item).text() === item.dataset.resource && _.contains(entity.resources, item.dataset.resource);
});
// Testing new resource can be added.
// Testing duplication by trying to re-add the previous resource
QUnit.equal(entity.resources.length, _.uniq(entity.resources).length, "Duplicate resource not added");
// checking for invalid inputs
// Delete the NEW_RESOURCE
QUnit.ok(entity.resources.length === resourceLength - 1 && !_.contains(entity.resources, lastAddedItem.data().resource), 'Resource deleted');
});
});
editPolicyView.staticAttrsView.render(editPolicyView.data.entity, staticAttributes, '#staticAttrs', function () {
// add new static attribute
QUnit.ok(attrsLengthOld + 1 === editPolicyView.staticAttrsView.data.items.length, "Static attribute can be added");
QUnit.ok(attrsLengthOld + 1 === editPolicyView.staticAttrsView.data.items.length, "Can't add duplicate static attribute");
// delete static attribute
deleteBtn = _.first(editPolicyView.staticAttrsView.$el.find('#attrTypeStatic ul li:first').find('.icon-close'));
QUnit.ok(attrsLengthOld === editPolicyView.staticAttrsView.data.items.length, "Static attribute can be deleted");
QUnit.ok(!_.find(editPolicyView.staticAttrsView.data.items, { propertyName: "incompleteVal" }), "Static attributes with no key can't be added");
QUnit.ok(!_.find(editPolicyView.staticAttrsView.data.items, { propertyName: "incompleteKey" }), "Static attributes with no value can't be added");
});
QUnit.equal(SubjectResponseAttributesView.$el.find('.selectize-input').find('.item').length, userAttributes.length, 'User attributes are selected correctly');
});
});
actionsView.render([], function () {
// Correct available actions are displayed
QUnit.ok(availableActions.length === actionsCells.length, "Correct number of actions is displayed");
var actionsPresent = true;
});
});
QUnit.ok(actionsPresent, "Actions are displayed correctly (available for selected application type)");
// Toggle all actions
allChecked = true;
});
QUnit.ok(allChecked, "All actions are marked as selected in a JS object after Toggle All checkbox is selected");
allChecked = false;
});
QUnit.ok(!allChecked, "All actions are marked as deselected in a JS object after Toggle All checkbox is deselected");
// Action permissions
correctPermissions = true;
});
});
// Selecting individual actions
QUnit.ok(_.findWhere(entity.actions, {action: actionName}).selected, "Action is selected after clicking on row");
// Reload review step
$('#reviewInfo', editPolicyView.$el).html(uiUtils.fillTemplateWithData('templates/policy/policies/ReviewPolicyStepTemplate.html', editPolicyView.data), function () {
// Actions
var actions = [],
actions.push({action: actionPair[0].trim(), value: actionPair[1].trim() === 'Allowed', selected: true});
});
QUnit.ok(_.isEqual(actions, polSelectedActions), "Correct actions are displayed in the review step");
}
});
});
$('#reviewInfo', editPolicyView.$el).html(uiUtils.fillTemplateWithData('templates/policy/policies/ReviewPolicyStepTemplate.html', editPolicyView.data, function () {
QUnit.ok(editPolicyView.$el.find('#reviewName').text().trim() === entity.name, "Correct name is displayed in the review step");
// both are undefined.
} else {
QUnit.ok(editPolicyView.$el.find('#reviewDesc').html() === (entity.description ? entity.description : ''), "Correct description is displayed in the review step");
}
// Resources
var resources = [];
});
QUnit.ok(_.isEqual(resources, entity.resources), "Correct resources are displayed in the review step");
}
// Subject Conditions
QUnit.equal(editPolicyView.$el.find('#subjectContainer').find('#addCondition').length, 1, 'Add subject button is present');
QUnit.equal(editPolicyView.$el.find('#subjectContainer').find('#addOperator').length, 1, 'Add operator button is present');
QUnit.ok(editPolicyView.$el.find('#subjectContainer').find('#pickUpItem').empty(), 'Pick up item is empty');
QUnit.ok(editPolicyView.$el.find('#subjectContainer').find('#clear').hasClass('inactive'), 'Clear button is disabled');
QUnit.ok(editPolicyView.$el.find('#subjectContainer').find('#pickUpItem').children().length > 0, 'Pick up item is not empty');
QUnit.ok(!editPolicyView.$el.find('#subjectContainer').find('#clear').hasClass('inactive'), 'Clear button is enabled');
QUnit.ok(_.isEqual(reviewSubj, entity.subject), "Correct environment conditions are displayed in the review step");
}
// Environment Conditions
QUnit.equal(editPolicyView.$el.find('#environmentContainer').find('#addCondition').length, 1, 'Add condition button is present');
QUnit.equal(editPolicyView.$el.find('#environmentContainer').find('#addOperator').length, 1, 'Add operator button is present');
QUnit.ok(editPolicyView.$el.find('#environmentContainer').find('#pickUpItem').empty(), 'Pick up item is empty');
QUnit.ok(editPolicyView.$el.find('#environmentContainer').find('#clear').hasClass('inactive'), 'Clear button is disabled');
QUnit.ok(editPolicyView.$el.find('#environmentContainer').find('#pickUpItem').children().length > 0, 'Pick up item is not empty');
QUnit.ok(!editPolicyView.$el.find('#environmentContainer').find('#clear').hasClass('inactive'), 'Clear button is enabled');
QUnit.ok(_.isEqual(reviewEnv, entity.condition), "Correct environment conditions are displayed in the review step");
}
}));
});
});
});
QUnit.equal(actionsView.$el.find('.striped-list li.invalid').length, 1, 'No actions are available for selection as resource type is not selected');
});
$('#reviewInfo', editPolicyView.$el).html(uiUtils.fillTemplateWithData('templates/policy/policies/ReviewPolicyStepTemplate.html', editPolicyView.data, function () {
QUnit.ok(editPolicyView.$el.find('#reviewName').hasClass('invalid'), 'Name field is marked as invalid');
QUnit.equal(editPolicyView.$el.find('#reviewRes').length, 0, 'Resources field is not displayed in review step as it is invalid');
QUnit.ok(editPolicyView.$el.find('[name="submitForm"]').is(':disabled'), 'Submit button is disabled');
}));
});
});
var appName = 'iPlanetAMWebAgentService';
QUnit.equal(table.find("tr[id]").length, rowData.length, "Number of rows in grid match number displayed");
// assuming application property "editable" is true
QUnit.equal(policyListView.$el.find('#appNameHeader').find('a').text(), appName, 'App name is displayed correctly');
QUnit.equal(policyListView.$el.find('#appNameHeader').find('a').attr('href'), '#app/' + appName, 'App link is correct');
QUnit.ok(policyListView.$el.find('#policies_name').find('span[sort=desc]').hasClass('ui-state-disabled'), 'Name is sorted in ascending order');
QUnit.equal(policyListView.$el.find('#policiesPager_left').find('.ui-icon-add').length, 1, 'Columns icon is present');
QUnit.equal(policyListView.$el.find('#policiesPager_left').find('.ui-icon-search').length, 1, 'Advanced search icon is present');
QUnit.ok(rowData.length + postedData._pagedResultsOffset + remaining === recordsTotal, 'Total number of records is calculated correctly');
QUnit.ok(table.jqGrid('getGridParam', 'rowNum') >= rowData.length, 'Number of rows in grid is less than or equal to number of rows requested');
if (recordsTotal > recordsPerPage) {
QUnit.ok(totalNumberOfPages === recordsTotal % recordsPerPage === 0 ? recordsTotal / recordsPerPage : Math.floor(recordsTotal / recordsPerPage) + 1, 'Total number of pages is calculated correctly');
} else {
}
});
});
module('Resource Types');
var resTypeUUID = '6a90eabe-9638-4333-b688-3223aec7f58a';
actionsList = new resTypeActionsView(),
patternList = new resTypePatternsView();
// Step 1
QUnit.ok(editResourceTypeView.validationFields && editResourceTypeView.validationFields.length > 0, 'Validation is present');
QUnit.equal(editResourceTypeView.$el.find('[name="submitForm"]').is(':disabled'), false, 'Submit button is enabled');
QUnit.ok(editResourceTypeView.$el.find('#resTypeDescription').val() === (entity.description ? entity.description : ''), "Description is set");
// Step 2
valid = true;
});
// last item is 'add new' item
QUnit.equal(listItems.length - 1, editResourceTypeView.data.actions.length, "Correct number of actions are displayed");
});
valid = true;
// last item is 'add new' item
QUnit.equal(listItems.length - 1, entity.patterns.length, "Correct number of patterns are displayed");
});
});
// Step 3
$('#reviewInfo', editResourceTypeView.$el).html(uiUtils.fillTemplateWithData('templates/policy/resourcetypes/ReviewResourceTypeStepTemplate.html', editResourceTypeView.data, function () {
QUnit.ok(editResourceTypeView.$el.find('#reviewName').text().trim() === entity.name, "Correct name is displayed in the review step");
// both are undefined.
} else {
QUnit.ok(editResourceTypeView.$el.find('#reviewDesc').html() === (entity.description ? entity.description : ''), "Correct description is displayed in the review step");
}
// Patterns
var patterns = [];
});
QUnit.ok(_.isEqual(patterns, entity.patterns), "Correct patterns are displayed in the review step");
}
// Actions
QUnit.ok(_.isEqual(editResourceTypeView.$el.find('ul#reviewActions').find('li').lenght, entity.actions.length), "Correct count actions are displayed in the review step");
var valid = true;
});
}
}));
});
});
editResourceTypeView.render([], function () {
actionsList = new resTypeActionsView(),
patternList = new resTypePatternsView();
// Step 1
QUnit.ok(editResourceTypeView.$el.find('#resTypeDescription').val() === '', "Description is empty");
// Step 2
// first element is 'no item', second is 'add new' item
});
// first element is 'no item', second is 'add new' item
});
// Step 3
$('#reviewInfo', editResourceTypeView.$el).html(uiUtils.fillTemplateWithData('templates/policy/resourcetypes/ReviewResourceTypeStepTemplate.html', editResourceTypeView.data, function () {
QUnit.ok(editResourceTypeView.$el.find('#reviewName').hasClass('invalid'), 'Name field is marked as invalid');
QUnit.equal(editResourceTypeView.$el.find('#reviewRes').length,0, 'Resources field is not displayed in review step as it is invalid');
QUnit.ok(editResourceTypeView.$el.find('[name="submitForm"]').is(':disabled'), 'Submit button is disabled');
}));
});
});
manageResTypesView.render([], function () {
QUnit.equal(manageResTypesView.$el.find('.global-actions').length, 1, 'Table actions are rendered');
QUnit.ok(rowData.length === table.find("tr[id]").length, "Number of rows in grid match number displayed");
QUnit.ok(table.jqGrid('getGridParam', 'colNames').length === table.find("tr[id]")[0].children.length,
'Total number of columns displayed matches number of columns requested');
// sorting
'Sort icon is present for the name column');
QUnit.ok(manageResTypesView.$el.find('#resTypes_name').find('span[sort=desc]').hasClass('ui-state-disabled'),
'Name is sorted in ascending order');
// Pagination
'Total number of records is calculated correctly');
'Number of rows in grid is less than or equal to number of rows requested');
if (recordsTotal > recordsPerPage) {
'Total number of pages is calculated correctly');
} else {
'Total number of pages is calculated correctly');
}
});
});
module('Common');
callback: function () {
});
}
});
});
});
});
QUnit.equal(router.getLink(router.configuration.routes.editApp, [null]), "app/", "Add App - no arguments provided");
QUnit.equal(router.getLink(router.configuration.routes.editApp, ["calendar"]), "app/calendar", "Edit App with one argument provided");
QUnit.equal(router.getLink(router.configuration.routes.editApp, ["test spaces"]), "app/test spaces", "Edit App with space in the name");
QUnit.equal(router.getLink(router.configuration.routes.editPolicy, ["calendar", null]), "app/calendar/policy/", "Add policy with one argument provided");
QUnit.equal(router.getLink(router.configuration.routes.editPolicy, ["calendar", "testPolicy"]), "app/calendar/policy/testPolicy", "Edit policy with two arguments provided");
});
}
}
});