e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne/**
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 * License.
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne *
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.
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne *
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]".
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne *
90929d4c6b284dd318f4a78c2aa407afb7423747oliver.bradley * Copyright 2015 ForgeRock AS.
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne */
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne/*global require, define, QUnit, $, module */
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Brownedefine([
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne "org/forgerock/commons/ui/common/util/Constants",
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne "org/forgerock/commons/ui/common/main/Router",
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne "org/forgerock/commons/ui/common/main/EventManager",
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne "org/forgerock/openidm/ui/admin/mapping/MappingBaseView",
352c411653c48af103d64372adc7832043da4257Elizabeth Browne "org/forgerock/openidm/ui/admin/mapping/properties/LinkQualifiersView",
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne "../mocks/mapping/linkQualifierProperties"
352c411653c48af103d64372adc7832043da4257Elizabeth Browne], function (constants,
352c411653c48af103d64372adc7832043da4257Elizabeth Browne router,
352c411653c48af103d64372adc7832043da4257Elizabeth Browne eventManager,
352c411653c48af103d64372adc7832043da4257Elizabeth Browne MappingBaseView,
352c411653c48af103d64372adc7832043da4257Elizabeth Browne PropertiesLinkQualifier,
352c411653c48af103d64372adc7832043da4257Elizabeth Browne linkQualifierProperties) {
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne return {
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne executeAll: function (server) {
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne var syncDetails = {"sync":{"mappings":[{"name":"systemXmlfileAccounts_managedUser","source":"system/xmlfile/account","target":"managed/user","correlationQuery":{"type":"text/javascript","source":"var query = {'_queryId' : 'for-userName', 'uid' : source.name};query;"},"properties":[{"source":"email","target":"mail"},{"source":"firstname","target":"givenName"},{"source":"lastname","target":"sn"},{"source":"description","target":"description"},{"source":"_id","target":"_id"},{"source":"name","target":"userName"},{"source":"password","target":"password"},{"source":"mobileTelephoneNumber","target":"telephoneNumber"},{"source":"roles","transform":{"type":"text/javascript","source":"source.split(',')"},"target":"roles"}],"policies":[{"situation":"CONFIRMED","action":"UPDATE"},{"situation":"FOUND","action":"IGNORE"},{"situation":"ABSENT","action":"CREATE"},{"situation":"AMBIGUOUS","action":"IGNORE"},{"situation":"MISSING","action":"IGNORE"},{"situation":"SOURCE_MISSING","action":"IGNORE"},{"situation":"UNQUALIFIED","action":"IGNORE"},{"situation":"UNASSIGNED","action":"IGNORE"}]}]},"mapping":{"name":"systemXmlfileAccounts_managedUser","source":"system/xmlfile/account","target":"managed/user","correlationQuery":{"type":"text/javascript","source":"var query = {'_queryId' : 'for-userName', 'uid' : source.name};query;"},"properties":[{"source":"email","target":"mail"},{"source":"firstname","target":"givenName"},{"source":"lastname","target":"sn"},{"source":"description","target":"description"},{"source":"_id","target":"_id"},{"source":"name","target":"userName"},{"source":"password","target":"password"},{"source":"mobileTelephoneNumber","target":"telephoneNumber"},{"source":"roles","transform":{"type":"text/javascript","source":"source.split(',')"},"target":"roles"}],"policies":[{"situation":"CONFIRMED","action":"UPDATE"},{"situation":"FOUND","action":"IGNORE"},{"situation":"ABSENT","action":"CREATE"},{"situation":"AMBIGUOUS","action":"IGNORE"},{"situation":"MISSING","action":"IGNORE"},{"situation":"SOURCE_MISSING","action":"IGNORE"},{"situation":"UNQUALIFIED","action":"IGNORE"},{"situation":"UNASSIGNED","action":"IGNORE"}]},"mappingName":"systemXmlfileAccounts_managedUser"};
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne module('Link Qualifier Properties UI Functions');
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.asyncTest("Link Qualifier Properties View", function () {
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne var editor,
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne errorMessageStub;
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PropertiesLinkQualifier.setCurrentMapping(syncDetails.sync.mappings[0]);
42be21a8d046897a4a36b1cb023e686131046985Elizabeth Browne PropertiesLinkQualifier.setSyncConfig(syncDetails);
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne linkQualifierProperties(server);
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne $("#qunit-fixture").append("<div id='mappingLinkQualifiers'></div>");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.render("systemXmlfileAccounts_managedUser", _.bind(function(){
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#linkQualifierTabs a").length === 2, "Both dynamic and declarative link qualifier methods are available");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#staticLinkQualifierList .linkQualifier").html() === "default", "Correctly loaded default declarative link qualifiers");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#staticLinkQualifierList button:enabled").length === 0, "Declarative link qualifier not deletable");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne //newLinkQualifier
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find(".newLinkQualifier").val("test");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find(".addLinkQualifier").trigger("click");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#staticLinkQualifierList button:nth-child(2) .linkQualifier").html() === "test", "Added a declarative link qualifier");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#staticLinkQualifierList button:enabled").length === 2, "Both declarative link qualifiers are deletable");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find(".removeLinkQualifier:nth-child(2)").trigger("click");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#staticLinkQualifierList button").length === 1, "Removed declarative link qualifier");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find("#scriptQualifierTab").trigger("click");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#scriptLinkQualifier").hasClass("active"), "Successfully changed to Dynamic tab");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find(".CodeMirror").length === 1, "Code mirror loaded for dynamic tab");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find(".inline-code input").trigger("click");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne editor = PropertiesLinkQualifier.linkQualifierScript.getInlineEditor();
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne editor.setValue("test");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.$el.find(".linkQualifierSave").trigger("click");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne errorMessageStub = sinon.stub(PropertiesLinkQualifier, "showErrorMessage", function(message){
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne errorMessageStub.restore();
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne PropertiesLinkQualifier.showErrorMessage(message);
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.ok(PropertiesLinkQualifier.$el.find("#badLinkQualifierScript:visible").length === 1, "Error message successfully displayed");
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne QUnit.start();
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne });
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne }, this));
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne });
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne }
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne };
e3cca5e1f9f9a55839d4bd7d34f51145f835a7b8Jason Browne});