90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * The contents of this file are subject to the terms of the Common Development and
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Distribution License (the License). You may not use this file except in compliance with the
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * specific language governing permission and limitations under the License.
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * When distributing Covered Software, include this CDDL Header Notice in each file and include
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Header, with the fields enclosed by brackets [] replaced by your own identifying
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * information: "Portions copyright [year] [name of copyright owner]".
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Copyright 2015 ForgeRock AS.
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne/*global require, define, QUnit, $, module */
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne "org/forgerock/commons/ui/common/main/EventManager",
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne "org/forgerock/openidm/ui/admin/mapping/behaviors/PoliciesView"
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne], function (sinon, eventManager, PoliciesView) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne $("body").append("<div id='policyPattern'></div>");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne module("Admin Mapping tab, Recon sub-tab tests");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.asyncTest("Situational Policy Renders", function () {
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(PoliciesView.$el.children().length, 0, "There are no children in the container before render.");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.ok(PoliciesView.$el.children().length > 0, "After rendering there are now child elements");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne // -1 because of the source row used to create the others is still on the page but hidden
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(PoliciesView.$el.find("#situationalPolicies table tbody tr.event-hook").length,
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne _.size(PoliciesView.model.allPatterns["Default Actions"].policies),
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel "All default situations are present");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(_.size(PoliciesView.model.allPatterns),
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PoliciesView.$el.find("#policyPatterns option").length,
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne "Patterns rendered are the same as the stored patterns");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne _.each(PoliciesView.model.allPatterns["Default Actions"].policies, function(situation, index) {
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne if ($.t(situation.note) !== PoliciesView.$el.find("#situationalPolicies table tbody tr.event-hook:eq("+index+") td:eq(1) [data-title]").attr("data-title")) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.ok(messages, "The help tooltips have been set");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(PoliciesView.$el.find("#situationalPolicies table tbody .failure-display").length, 7, "There are 7 situations with error classes");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(PoliciesView.$el.find("#situationalPolicies table tbody .warning-display").length, 3, "There are 3 situations with warning classes");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne QUnit.equal(PoliciesView.$el.find("#situationalPolicies table tbody .success-display").length, 3, "There are 3 situations with success classes");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne var readOnly = true, defaultActions = true;
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PoliciesView.$el.find("#policyPatterns").val("Read-only").change();
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne _.each(PoliciesView.$el.find(".situationRow"), function(row, index) {
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne if ($(row).find(".action").val() !== "ASYNC" && index < PoliciesView.model.allPatterns["Read-only"].policies.length) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.ok(readOnly, "When the pattern changes to Read-Only all actions are set to Async");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PoliciesView.$el.find("#policyPatterns").val("Default Actions").change();
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne _.each(PoliciesView.$el.find(".situationRow"), function(row, index) {
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne if ($(row).find(".action :selected").text().indexOf("★") < 0 && index < PoliciesView.model.allPatterns["Read-only"].policies.length) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.ok(defaultActions, "When the pattern changes to Default-Actions all actions are set to the starred value");
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PoliciesView.$el.find(".ABSENT .action").val("LINK");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne var callback = sinon.spy(eventManager, "sendEvent"),
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne mappingUpdated = false,
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne deferredRead = $.Deferred(),
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne deferredWrite = $.Deferred(),
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne stubbedRead = sinon.stub(ConfigDelegate, "readEntity", function () {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne return deferredRead.promise();
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne stubbedWrite = sinon.stub(ConfigDelegate, "updateEntity", function (name, data) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne _.each(data.mappings, function(mapping) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne if(mapping.name === mappingName) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne _.each(mapping.policies, function(policy) {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne if (policy.action === "LINK" && policy.situation === "ABSENT") {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne mappingUpdated = true;
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.ok(mappingUpdated, "The policy mapping was updated properly.");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne return deferredWrite.promise();
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne deferredRead.done(function() {
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne deferredWrite.resolve();
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PoliciesView.$el.find(".savePolicy").click();
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne deferredRead.resolve({mappings: sync});
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne QUnit.ok(callback.called, "The policy successfully saves");
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne stubbedRead.restore();
7ed4684789d023e1d4ede1b0d4468b9724587466Elizabeth Browne stubbedWrite.restore();