Skip to content

Commit

Permalink
[eds adding source property in sling model of image component to get …
Browse files Browse the repository at this point in the history
…the path in crx of the image.......]
  • Loading branch information
Deep Prakash Dewanji authored and ci-build committed May 2, 2024
1 parent 33ddc31 commit f950658
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
Expand Up @@ -62,6 +62,10 @@ public class StaticImageImpl extends AbstractFormComponentImpl implements Static
@org.jetbrains.annotations.Nullable
protected String description; // long description as per current spec

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileReference")
@Nullable
protected String fileReference;

/**
* Returns the source where the image is present.
*
Expand Down Expand Up @@ -120,4 +124,9 @@ public String getLinkUrl() {
return null;
}
}

@Override
public String getSource() {
return fileReference;
}
}
Expand Up @@ -49,6 +49,16 @@ default String getValue() {
return null;
}

/**
* Retrieves the parsed img value to be displayed.
*
* @return the parsed img value to be displayed, or {@code null} if no value can be returned
* @since com.adobe.cq.forms.core.components.models.form 0.0.1;
*/
default String getSource() {
return null;

Check warning on line 59 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/StaticImage.java

View check run for this annotation

Codecov / codecov/patch

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/StaticImage.java#L59

Added line #L59 was not covered by tests
}

/**
* Returns the alternate text in place of image.
*
Expand Down
Expand Up @@ -48,6 +48,8 @@ public class StaticImageImplTest {
private static final String BASE = "/form/image";
private static final String CONTENT_ROOT = "/content";
private static final String PATH_IMAGE_CUSTOMIZED = CONTENT_ROOT + "/image-customized";

private static final String PATH_IMAGE_PARSED = CONTENT_ROOT + "/image-parsedSrc";
private static final String PATH_IMAGE = CONTENT_ROOT + "/image";
private static final String PATH_IMAGE_DATALAYER = CONTENT_ROOT + "/image-datalayer";

Expand All @@ -67,6 +69,15 @@ void testExportedType() {
assertEquals("", staticImageMock.getExportedType());
}

@Test
void testExportedTypeForParsedImage() {
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_PARSED, StaticImage.class, context);
assertEquals(FormConstants.RT_FD_FORM_IMAGE_V1, staticImage.getExportedType());
StaticImage staticImageMock = Mockito.mock(StaticImage.class);
Mockito.when(staticImageMock.getExportedType()).thenCallRealMethod();
assertEquals("", staticImageMock.getExportedType());
}

@Test
void testFieldType() {
StaticImage staticImage = Utils.getComponentUnderTest(PATH_IMAGE_CUSTOMIZED, StaticImage.class, context);
Expand Down
@@ -0,0 +1,18 @@
{
"id": "image-7cfd7f1fe4",
"fieldType": "image",
"name": "abcd",
"visible": false,
"altText": "abc",
"value": "/content/image-customized.img.png",
"source": "/content/image-customized.img.png",
"events": {
"custom:setProperty": [
"$event.payload"
]
},
"properties": {
"fd:path": "/content/image"
},
":type": "core/fd/components/form/image/v1/image"
}
12 changes: 12 additions & 0 deletions bundles/af-core/src/test/resources/form/image/test-content.json
@@ -1,4 +1,16 @@
{
"image-parsedSrc" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/image/v1/image",
"name" : "abcd",
"jcr:title" : "def",
"hideTitle" : false,
"visible" : false,
"altText": "abc",
"filereference": "/content/dam/formsanddocuments/abc.jpeg",
"excludeFromDor": false,
"fieldType": "image"
},
"image-customized" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "core/fd/components/form/image/v1/image",
Expand Down

0 comments on commit f950658

Please sign in to comment.