Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Navneet Agarwal authored and ci-build committed May 2, 2024
1 parent d4f5cdd commit 2700fbf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
1 change: 0 additions & 1 deletion bundles/af-core/pom.xml
Expand Up @@ -459,7 +459,6 @@
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>aem-forms-sdk-api</artifactId>
<version>2024.04.18.00-240300</version>
</dependency>


Expand Down
Expand Up @@ -36,7 +36,7 @@
jcr:primaryType="nt:unstructured"
jcr:title="HCAPTCHA"
sling:resourceType="forms-core-components-it/form/hcaptcha"
cloudServicePath="alwayschallenge1"
cloudServicePath="alwayschallenge"
enabled="{Boolean}true"
fieldType="captcha"
hideTitle="false"
Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Expand Up @@ -1128,7 +1128,7 @@
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>aem-forms-sdk-api</artifactId>
<version>2023.10.09.00-230901</version>
<version>2024.04.18.00-240300</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -22,14 +22,17 @@ Adaptive Form hCaptcha field component written in HTL.
* Provides the following type of input:
* hCaptcha
* Allows various flavours of hCaptcha
* Always Challenge
* 99.9% Passive
* Only visible mode is supported as of now
* Styles
* Custom constraint messages for the above types

### Use Object
The Form Text component uses the `com.adobe.cq.forms.core.components.models.form.HCaptcha` Sling Model for its Use-object.
The hCaptcha component uses the `com.adobe.cq.forms.core.components.models.form.HCaptcha` Sling Model for its Use-object.

### Edit Dialog Properties
The following properties are written to JCR for this Form Recaptcha component and are expected to be available as `Resource` properties:
The following properties are written to JCR for this Form hCaptcha component and are expected to be available as `Resource` properties:

1. `./jcr:title` - defines the label to use for this field
2. `./hideTitle` - if set to `true`, the label of this field will be hidden
Expand All @@ -39,8 +42,8 @@ The following properties are written to JCR for this Form Recaptcha component an
6. `./required` - if set to `true`, this field will be marked as required, not allowing the form to be submitted until the field has a value
7. `./requiredMessage` - defines the message displayed as tooltip when submitting the form if the value is left empty
8. `./readOnly` - if set to `true`, the filed will be read only
9. `./cloudServicePath` - defines the path of cloud configuration resource for reCAPTCHA
10. `./size` - defines the size attribute of Google reCAPTCHA
9. `./cloudServicePath` - defines the path of cloud configuration resource for hCaptcha
10. `./size` - defines the size attribute of hCaptcha

## Client Libraries
The component provides a `core.forms.components.hcaptcha.v1.runtime` client library category that contains the Javascript runtime for the component.
Expand Down
Expand Up @@ -24,6 +24,7 @@ if (typeof window.HCaptchaWidget === 'undefined') {
#model = null // passed by reference
#options = null
#lang = 'en'
static FD_CAPTCHA = "fd:captcha";

constructor(view, model, widget) {
// initialize the widget and model
Expand All @@ -42,43 +43,43 @@ if (typeof window.HCaptchaWidget === 'undefined') {

#renderHCaptcha(element) {

var self = this;
var hCaptchaConfigData = this.#options;
const self = this;
const hCaptchaConfigData = this.#options;
element.innerHTML = '<div class="h-captcha"></div>';
var hcontainer = document.getElementsByClassName("h-captcha")[0];
var widgetId;
var url = hCaptchaConfigData.properties["fd:captcha"].config.uri;
const hcontainer = document.getElementsByClassName("h-captcha")[0];
let widgetId;
const url = hCaptchaConfigData.properties[HCaptchaWidget.FD_CAPTCHA].config.uri;

var successCallback = function(response) {
const successCallback = function(response) {
self.setCaptchaModel(response);
};

var expiredCallback = function() {
const expiredCallback = function() {
hcaptcha.reset(widgetId);
self.setCaptchaModel("");
};

var onloadCallbackInternal = function() {
const onloadCallbackInternal = function() {
widgetId = hcaptcha.render(
hcontainer,
hparameters
);
return widgetId;
};

var hparameters = {
'sitekey': hCaptchaConfigData.properties["fd:captcha"].config.siteKey,
'size': hCaptchaConfigData.properties["fd:captcha"].config.size,
'theme': hCaptchaConfigData.properties["fd:captcha"].config.theme || 'light',
const hparameters = {
'sitekey': hCaptchaConfigData.properties[HCaptchaWidget.FD_CAPTCHA].config.siteKey,
'size': hCaptchaConfigData.properties[HCaptchaWidget.FD_CAPTCHA].config.size,
'theme': hCaptchaConfigData.properties[HCaptchaWidget.FD_CAPTCHA].config.theme || 'light',
'callback': successCallback,
'expired-callback': expiredCallback
};

window.onloadHCaptchaCallback = onloadCallbackInternal;

var runtimeLocale = this.#lang;
const runtimeLocale = this.#lang;

var scr = document.createElement('script');
const scr = document.createElement('script');
scr.src = url + "?onload=onloadHCaptchaCallback&render=explicit&hl=" + runtimeLocale;
scr.async = true;
element.appendChild(scr);
Expand Down
22 changes: 18 additions & 4 deletions ui.tests/test-module/specs/hcaptcha/hcaptcha.runtime.spec.js
Expand Up @@ -38,7 +38,7 @@ describe("Form Runtime with hCaptcha Input", () => {

// render the form with captcha, we have whitelisted the "Missing required parameters: sitekey" error
beforeEach(() => {
if (cy.af.isLatestAddon()) {
if (cy.af.isLatestAddon() && toggle_array.includes(FT_HCAPTCHA)) {
cy.previewForm(pagePath).then((p) => {
formContainer = p;
});
Expand Down Expand Up @@ -123,17 +123,31 @@ describe("Form Runtime with hCaptcha Input", () => {

it("submission should pass for mandatory captcha", () => {
if (cy.af.isLatestAddon() && toggle_array.includes(FT_HCAPTCHA)) {
const secretKey="0x0000000000000000000000000000000000000000"
cy.visit("mnt/overlay/fd/af/cloudservices/hcaptcha/properties.html?item=%2Fconf%2Fcore-components-it%2Fsettings%2Fcloudconfigs%2Fhcaptcha%2Falwayschallenge").then(x => {
cy.get('#captcha-cloudconfiguration-secret-key').clear().type(secretKey).then(x => {
cy.get("#shell-propertiespage-doneactivator").click();
});
});
cy.previewForm(pagePath).then((p) => {
formContainer = p;
});
expect(formContainer, "formcontainer is initialized").to.not.be.null;
cy.get(`div.h-captcha iframe`).should('be.visible').then($iframe => {
cy.wrap($iframe).then($iframe => {
cy.window().should('have.property', 'hcaptcha').and('not.be.undefined')
.then((hcaptcha) => {
hcaptcha.execute();
cy.wait(2000);
return new Cypress.Promise(resolve => {
setTimeout(() => {
resolve();
}, 3000);
});
}).then(() => {
cy.get(`.cmp-adaptiveform-button__widget`).click().then(x => {
cy.get('body').should('contain', "Thank you for submitting the form.\n")
});
})
});
})
});
});
}
Expand Down

0 comments on commit 2700fbf

Please sign in to comment.