policy.js revision a093731116a8c24d49b903df7602cf586e499b45
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2014 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, conf, router, loginHelper, uiUtils, policyDelegate, editAppView, editPolView, resListView, selectPatternsView, manageAppsView, managePolView, actionsView, responseAttrsStaticView, responseAttrsUserView, reviewInfoView) {
return {
executeAll: function (server) {
module('Applications page');
// Step 1
QUnit.ok(editAppView.$el.find('#appDescription').val() === (entity.description ? entity.description : ''), "Description is set");
// Step 2
selectPatternsView.render([], function () {
values = [];
});
// check number of rendered patterns = options.resourcePatterns.length
// check options.resourcePatterns and avalible patterns are the same
QUnit.ok( _.difference(values, options.resourcePatterns).length === 0, "All avaliable patterns are displayed correctly");
// clicking on a pattern reloads the resource creation tool
resListView.render([], function () {
values = [],
valid = true,
NEW_RESOURCE = 'newResource';
valid = false;
}
});
valid = valid && $(item).text() === item.dataset.resource && _.contains(entity.resources, item.dataset.resource);
});
// Testing a new resource can be added.
// Testing duplication by trying to re-add entity.resources[0] the the entity.resources array.
QUnit.ok( _.uniq(entity.resources).length === entity.resources.length, "Duplicate resource not added");
// Adding a NEW_RESOURCE.
// Testing last input enter key trigger
valid = (entity.resources.length === (resourceLength + 1) && _.contains(entity.resources, NEW_RESOURCE) );
// Delete the NEW_RESOURCE
});
QUnit.ok( entity.resources.length === resourceLength - 1 && !_.contains(entity.resources, NEW_RESOURCE), 'New resource deleted');
// Step 3
$('#reviewInfo', editAppView.$el).html(uiUtils.fillTemplateWithData('templates/policy/ReviewApplicationStepTemplate.html', editAppView.data, function () {
var resources = [];
QUnit.ok(editAppView.$el.find('#reviewName').html() === entity.name, "Correct name is 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");
}
// Resources
});
QUnit.ok(_.isEqual(resources, entity.resources), "Correct resources are displayed in the review step");
}
}));
});
});
});
});
editAppView.render([], function () {
// Step 1
// Step 2
resListView.render([], function () {
});
});
});
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('#manageApps_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 page');
// Step 1
QUnit.ok(editPolView.$el.find('#description').val() === (entity.description ? entity.description : ''), "Description is set");
// Step 2
resListView.render([], function () {
valid = true;
valid = valid && $(item).text() === item.dataset.resource &&_.contains(entity.resources, item.dataset.resource);
});
QUnit.ok(listItems.length === entity.resources.length, "Correct number of resources are displayed");
});
selectPatternsView.render([], function () {
values = [];
});
// check number of rendered patterns = options.resourcePatterns.length
// check options.resourcePatterns and avalible patterns are the same
QUnit.ok( _.difference(values, options.resourcePatterns).length === 0, "All avaliable patterns are displayed correctly");
// clicking on a pattern reloads the resource creation tool
resListView.render([], function () {
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.
QUnit.ok( _.contains(entity.resources, 'http://www.hello.com/'+ NEW_STR +'/world/'+ NEW_STR), "Unique resource added");
// Testing duplication by trying to re-add the previous resource
QUnit.ok( _.uniq(entity.resources).length === 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');
});
});
responseAttrsStaticView.render([], function(){
// add new static attribute
QUnit.ok(attrsLengthOld + 1 === responseAttrsStaticView.data.staticAttributes.length, "Static attribute can be added");
QUnit.ok(attrsLengthOld + 1 === responseAttrsStaticView.data.staticAttributes.length, "Can't add duplicate static attribute");
// delete static attribute
deleteBtn = _.first(responseAttrsStaticView.$el.find('#attrTypeStatic ul li:first').find('.icon-close'));
QUnit.ok(attrsLengthOld === responseAttrsStaticView.data.staticAttributes.length, "Static attribute can be deleted");
QUnit.ok(!_.find(responseAttrsStaticView.data.staticAttributes, { propertyName: "incompleteVal" }), "Static attributes with no key can't be added");
QUnit.ok(!_.find(responseAttrsStaticView.data.staticAttributes, { propertyName: "incompleteKey" }), "Static attributes with no value can't be added");
});
// Step 3
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 = true;
});
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
});
allChecked = true;
});
QUnit.ok(allChecked, "All actions are marked as selected in a JS object after selecting corresponding checkboxes");
// Reload review step
$('#reviewPolicyInfo', editPolView.$el).html(uiUtils.fillTemplateWithData('templates/policy/ReviewPolicyStepTemplate.html', editPolView.data));
});
$('#reviewPolicyInfo', editPolView.$el).html(uiUtils.fillTemplateWithData('templates/policy/ReviewPolicyStepTemplate.html', editPolView.data, function () {
QUnit.ok(editPolView.$el.find('#reviewName').html() === entity.name, "Correct name is displayed in the review step");
// both are undefined.
} else {
QUnit.ok(editPolView.$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");
}
// 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");
}
/* TODO
// Subject Conditions
if (pol.subjects.length) {
var subjects = [];
_.each(editPolView.$el.find('ul#reviewSubjects').find('li'), function (value, key) {
subjects[key] = value.innerHTML;
});
QUnit.ok(_.isEqual(subjects, pol.subjects), "Correct subject conditions are displayed in the review step");
}
// Environment Conditions
if (pol.conditions.length) {
var envConditions = [];
_.each(editPolView.$el.find('ul#reviewEnvConditions').find('li'), function (value, key) {
envConditions[key] = value.innerHTML;
});
QUnit.ok(_.isEqual(envConditions, pol.conditions), "Correct environment conditions are displayed in the review step");
}
*/
}));
});
});
// Step 1
// Step 2
resListView.render([], function () {
});
// Step 3
actionsView.render([], function () {
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)");
});
});
});
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(managePolView.$el.find('#managePolicies_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');
}
});
});
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");
});
}
}
});