Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/af password component #1407

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7fba95
Initial commit for the AF password box core component
kum-sushil Feb 23, 2024
eeb34ac
AF Password Component| Updated license year and few code comments blo…
kum-sushil Feb 23, 2024
670b2a6
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
a5e10c0
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
0c16826
AF Password| Test case updates
kum-sushil Mar 4, 2024
903601f
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
d33e8ec
AF Password| Cypress test cases for editor and runtime JS
kum-sushil Mar 18, 2024
ed2567d
AF-Password|PR Comments| Removed Constants from FormConstants to dire…
kum-sushil Apr 27, 2024
6bbb81b
Merge branch 'dev' into feature/AF-Password-Component
kum-sushil Jun 5, 2024
9d1e6e2
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
d29456f
Merge branch 'dev' into feature/AF-Password-Component
devgurjar Jul 10, 2024
df83dc8
Fixing flaky test (#1312)
rismehta Jul 11, 2024
c2854ae
AF Password Component| Updated license year and few code comments blo…
kum-sushil Feb 23, 2024
642c630
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
ba32ad0
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
f3741ed
AF Password| Test case updates
kum-sushil Mar 4, 2024
eac2e41
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
e64a6eb
AF-Password|PR Comments| Removed Constants from FormConstants to dire…
kum-sushil Apr 27, 2024
4cd5d24
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
bff5e52
Fixing flaky test (#1312)
rismehta Jul 11, 2024
6204e39
AF Password Component| Updated license year and few code comments blo…
kum-sushil Feb 23, 2024
fdd90f3
AF Password Field| Updated Javascript code, updated apps pom.xml.
kum-sushil Feb 27, 2024
62b3c5e
AF Password|Test Cases and html updates supporting responsiveness
kum-sushil Mar 4, 2024
2f206f2
AF Password| Test case updates
kum-sushil Mar 4, 2024
1d52343
AF Password | PR review comments Updates
kum-sushil Mar 11, 2024
58319b9
AF-Password|PR Comments| Removed Constants from FormConstants to dire…
kum-sushil Apr 27, 2024
42c6f77
AF-password||Resolved test cases and password java for exclusive max …
kum-sushil Jun 5, 2024
b7dcf21
Merge branch 'password-comp' into feature/AF-Password-Component
kum-sushil Jul 14, 2024
1286d24
Validation pattern fix
kum-sushil Aug 1, 2024
f1ffc1e
Merge branch 'feature/AF-Password-Component' of https://github.com/ku…
kum-sushil Sep 16, 2024
9883894
Password Component feature addition for eye open and close icons and …
kum-sushil Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@ private FormConstants() {
public static final String REQ_ATTR_REFERENCED_PATH = "referencedPage";

public static final String PROP_FRAGMENT_PATH = "fragmentPath";

public static final String RT_FD_FORM_PASSWORD_V1 = RT_FD_FORM_PREFIX + "password/v1/password";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.cq.forms.core.components.internal.models.v1.form;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.models.form.Password;
import com.adobe.cq.forms.core.components.util.AbstractFieldImpl;
import com.adobe.cq.forms.core.components.util.ComponentUtils;

@Model(
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = { Password.class, ComponentExporter.class },
resourceType = { FormConstants.RT_FD_FORM_PASSWORD_V1 })
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class PasswordImpl extends AbstractFieldImpl implements Password {

private Object exclusiveMinimumVaue;
private Object exclusiveMaximumValue;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL)
@Nullable
private String pattern;

@Override
public String getFieldType() {
return super.getFieldType();
}

@Override
public Integer getMinLength() {
return minLength;
}

@Override
public Integer getMaxLength() {
return maxLength;
}

@Override
public Long getMinimum() {
return minimum;
}

@Override
public Long getMaximum() {
return maximum;
}

@Override
public String getFormat() {
return displayFormat;
}

@Override
public String getPattern() {
return pattern;
}

@Override
public Long getExclusiveMaximum() {
return (Long) exclusiveMaximumValue;
}

@Override
public Long getExclusiveMinimum() {
return (Long) exclusiveMinimumVaue;
}

@PostConstruct
private void initTextInput() {
exclusiveMaximumValue = ComponentUtils.getExclusiveValue(exclusiveMaximum, maximum, null);
exclusiveMinimumVaue = ComponentUtils.getExclusiveValue(exclusiveMinimum, minimum, null);
// in json either, exclusiveMaximum or maximum should be present
if (exclusiveMaximumValue != null) {
maximum = null;
}
if (exclusiveMinimumVaue != null) {
minimum = null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public enum FieldType {
PANEL("panel"),
FORM("form"),
CHECKBOX_GROUP("checkbox-group"),
IMAGE("image");
IMAGE("image"),
PASSWORD("password");

private String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.ConsumerType;

/**
* Interface for {@code Password} Sling Model used for the {@code /apps/core/fd/components/form/password/v1/password} component.
*
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
*/
@ConsumerType
public interface Password extends Field, StringConstraint, NumberConstraint {

/**
* Returns the validation pattern (regex) for the password field.
*
* @return the validation pattern
* @since com.adobe.cq.forms.core.components.models.form 2.0.0
*/
String getPattern();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2024 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

package com.adobe.cq.forms.core.components.internal.models.v1.form;

import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.datalayer.FormComponentData;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.Password;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import io.wcm.testing.mock.aem.junit5.AemContext;
import io.wcm.testing.mock.aem.junit5.AemContextExtension;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

@ExtendWith(AemContextExtension.class)
public class PasswordImplTest {

private static final String BASE = "/form/password";
private static final String CONTENT_ROOT = "/content";
private static final String PATH_PASSWORD_DATALAYER = CONTENT_ROOT + "/password-datalayer";
private static final String PATH_PASSWORD_CUSTOMIZED = CONTENT_ROOT + "/password-customized";
private static final String PATH_NUMBER_PASSWORD_EXCLUSIVE = CONTENT_ROOT + "/number-password-exclusive";
private static final String PATH_NUMBER_PASSWORD_INPUT = CONTENT_ROOT + "/number-password";

private final AemContext context = FormsCoreComponentTestContext.newAemContext();

@BeforeEach
void setUp() {
context.load().json(BASE + FormsCoreComponentTestContext.TEST_CONTENT_JSON, CONTENT_ROOT);
}

@Test
void testFieldType() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(FieldType.PASSWORD.getValue(), password.getFieldType());
}

@Test
void testGetLabel() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("pwd", password.getLabel().getValue());
}

@Test
void testPlaceholder() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("Enter valid password", password.getPlaceHolder());
}

@Test
void testGetName() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password", password.getName());

}

@Test
void testDorProperties() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.getDorProperties().get("dorExclusion"));
assertEquals("4", password.getDorProperties().get("dorColspan"));
assertEquals("Text1", password.getDorProperties().get("dorBindRef"));

}

@Test
void testGetDescription() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password field", password.getDescription());
}

@Test
void testGetRequired() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isRequired());
}

@Test
void testGetPattern() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/", password.getPattern());

}

@Test
void testIsEnabled() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isEnabled());
}

@Test
void testIsEnabledForCustomized() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(true, password.isEnabled());
}

@Test
void testIsReadOnly() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(false, password.isReadOnly());
}

@Test
void testIsReadOnlyForCustomized() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(false, password.isReadOnly());
}

@Test
void testMinLength() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(5, password.getMinLength().intValue());
}

@Test
void testMaxLength() {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals(10, password.getMaxLength().intValue());
}

@Test
void testGetExclusiveMinimum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_EXCLUSIVE, Password.class, context);
assertNull(password.getMinimum());
assertEquals(8L, password.getExclusiveMinimum().longValue());
}

@Test
void testGetExclusiveMaximum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_EXCLUSIVE, Password.class, context);
assertNull(password.getMaximum());
assertEquals(16L, password.getExclusiveMaximum().longValue());
}

@Test
void testGetMinimum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context);
assertEquals(8, password.getMinimum().intValue());
}

@Test
void testGetMaximum() {
Password password = Utils.getComponentUnderTest(PATH_NUMBER_PASSWORD_INPUT, Password.class, context);
assertEquals(16, password.getMaximum().intValue());
}

@Test
void testGetDisplayFormat() throws Exception {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_CUSTOMIZED, Password.class, context);
assertEquals("password", password.getFormat());
}

@Test
void testDataLayerProperties() throws IllegalAccessException {
Password password = Utils.getComponentUnderTest(PATH_PASSWORD_DATALAYER, Password.class, context);
FieldUtils.writeField(password, "dataLayerEnabled", true, true);
FormComponentData dataObject = (FormComponentData) password.getData();
assert (dataObject != null);
assert (dataObject.getId()).equals("password-1c7bc238a6");
assert (dataObject.getType()).equals("core/fd/components/form/password/v1/password");
assert (dataObject.getTitle()).equals("Full Name");
assert (dataObject.getFieldType()).equals("password");
assert (dataObject.getDescription()).equals("Enter Full Name");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "password-477c777f4e",
"fieldType": "password",
"name": "password1708629052628",
"visible": true,
"description": "<p>long desc</p>\r\n",
"tooltip": "<p>short desc</p>\r\n",
"type": "string",
"required": true,
"enabled": true,
"constraintMessages": {
"required": "Password is required",
"minLength": "min chars",
"maxLength": "max chars",
"pattern": "Invalid pwd"
},
"readOnly": false,
"minLength": 5,
"maxLength": 10,
"maximum" : 16,
"minimum" : 1,
"exclusiveMinimum" : 8,
"exclusiveMaximum" : 16,
"pattern": "/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/",
"label": {
"value": "Password",
"visible": true
},
"properties": {
"afs:layout": {
"tooltipVisible": false
},
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/password-customized"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"placeholder": "Enter valid password",
":type": "core/fd/components/form/password/v1/password"
}
Loading