Skip to content

Commit

Permalink
[SITES-22335] Fix smart crop test (adobe#2790)
Browse files Browse the repository at this point in the history
* [SITES-22335] Fix smart crop test

* refactor

---------

Co-authored-by: Alexandru Marian Stancioiu <[email protected]>
  • Loading branch information
alexandru-stancioiu and Alexandru Marian Stancioiu authored Jun 27, 2024
1 parent 90a8cfa commit b5e6a56
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,18 @@
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector: altInputSelector,
validate: function() {
var seededValue = $(altInputSelector).attr("data-seeded-value");
var isAltCheckboxChecked = document.querySelector('coral-checkbox[name="./altValueFromDAM"]').checked;
var seededValue = document.querySelector(altInputSelector).getAttribute("data-seeded-value");
var isImageFromPageImageChecked = document.querySelector('coral-checkbox[name="./imageFromPageImage"]').checked;
var altFromDAM = document.querySelector('coral-checkbox[name="./altValueFromDAM"]');
var isAltFromDAMChecked = altFromDAM.checked;
var isAltFromDAMDisabled = altFromDAM.disabled;
var isAltFromPageImageChecked = document.querySelector('coral-checkbox[name="./altValueFromPageImage"]').checked;
var isDecorativeChecked = document.querySelector("coral-checkbox[name='./isDecorative']").checked;
var assetWithoutDescriptionErrorMessage = "Error: Please provide an asset which has a description that can be used as alt text.";
if (isAltCheckboxChecked && !seededValue && !isDecorativeChecked) {

if (!isDecorativeChecked && !seededValue &&
((isImageFromPageImageChecked && isAltFromPageImageChecked) ||
(!isImageFromPageImageChecked && isAltFromDAMChecked && !isAltFromDAMDisabled))) {
return Granite.I18n.get(assetWithoutDescriptionErrorMessage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,18 @@
$(window).adaptTo("foundation-registry").register("foundation.validation.validator", {
selector: altInputSelector,
validate: function() {
var seededValue = $(altInputSelector).attr("data-seeded-value");
var isAltCheckboxChecked = document.querySelector('coral-checkbox[name="./altValueFromDAM"]').checked;
var seededValue = document.querySelector(altInputSelector).getAttribute("data-seeded-value");
var isImageFromPageImageChecked = document.querySelector('coral-checkbox[name="./imageFromPageImage"]').checked;
var altFromDAM = document.querySelector('coral-checkbox[name="./altValueFromDAM"]');
var isAltFromDAMChecked = altFromDAM.checked;
var isAltFromDAMDisabled = altFromDAM.disabled;
var isAltFromPageImageChecked = document.querySelector('coral-checkbox[name="./altValueFromPageImage"]').checked;
var isDecorativeChecked = document.querySelector("coral-checkbox[name='./isDecorative']").checked;
var assetWithoutDescriptionErrorMessage = "Error: Please provide an asset which has a description that can be used as alt text.";
if (isAltCheckboxChecked && !seededValue && !isDecorativeChecked) {

if (!isDecorativeChecked && !seededValue &&
((isImageFromPageImageChecked && isAltFromPageImageChecked) ||
(!isImageFromPageImageChecked && isAltFromDAMChecked && !isAltFromDAMDisabled))) {
return Granite.I18n.get(assetWithoutDescriptionErrorMessage);
}
}
Expand Down Expand Up @@ -307,12 +314,12 @@
} else {
$altGroup.show();
altTuple.hideTextfield(false);
altTuple.hideCheckbox(fromPageCheckbox.checked);
altTuple.hideCheckbox(fromPageCheckbox.checked || isRemoteFileReference(remoteFileReference));
altFromPageTuple.hideCheckbox(!fromPageCheckbox.checked);
if (fromPageCheckbox.checked) {
altFromPageTuple.seedTextValue(altTextFromPage);
altFromPageTuple.update();
} else {
} else if (!isRemoteFileReference(remoteFileReference)) {
altTuple.seedTextValue(altTextFromDAM);
altTuple.update();
}
Expand Down Expand Up @@ -344,6 +351,10 @@
toggleAlternativeFields(fromPageCheckbox, isDecorativeCheckbox);
}

function isRemoteFileReference(fileReference) {
return fileReference && fileReference !== "" && fileReference.includes("urn:aaid:aem");
}

function retrieveDAMInfo(fileReference) {
if (fileReference.startsWith("/urn:aaid:aem")) {
return new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class BaseImage extends BaseComponent {
".'][sizes='%s']";
public static String imageWithAltText = ".cmp-image__image[src*='%s/_jcr_content/root/responsivegrid/image.coreimg.'][alt='%s']";
public static String imageWithFileName = ".cmp-image__image[src*='/%s']";
public static String imageWithSmartCrop = ".cmp-image__image[src*='/smartcrop=%s']";
public static String imageWithSmartCrop = ".cmp-image__image[src*='smartcrop=%s']";
private static final String ngdmSmartCropButton = "button.cq-editable-action[data-action='ngdm-smartcrop']";
private static final String ngdmSmartCropDialog = ".smartcropdialog";
private static final String ngdmSmartCropAspectRatioSelector = ".image-v3-dialog-smartcrop-select button";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public boolean isPopUpTitle() {
public void selectSmartCrop(String cropName) {
CoralSelectList coralSelectList = new CoralSelectList($(smartCropField));
if (!coralSelectList.isVisible()) {
CoralSelect selectList = new CoralSelect(smartCropField);
CoralSelect selectList = new CoralSelect($(smartCropField));
coralSelectList = selectList.openSelectList();
}
coralSelectList.selectByValue(cropName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,11 @@ public void testSmartCropOnNGDMImageV3(String cropName) throws TimeoutException,
setUpNGDMImage();
Commons.openEditDialog(editorPage, compPath);
ImageEditDialog editDialog = image.getEditDialog();
editDialog.checkImageFromPageImage();
editDialog.selectSmartCrop(cropName);
Commons.saveConfigureDialog();
editorPage.enterPreviewMode();
Commons.switchContext("ContentFrame");
assertTrue(image.isImagePresentWithSmartCrop(cropName),"NGDM image should be rendered with a smartcrop");
}
public void testClearAssetInputGetDamInfoCheckboxesNotVisibleV3(String aemVersion) throws InterruptedException, TimeoutException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ public void testSmartCropDialogOnNGDMImageV3_flipAspectRatio() throws TimeoutExc

@Tag("IgnoreOnSDK")
@Test
@DisplayName("Test : NextGen DM image smart crop : large crop.")
@DisplayName("Test : NextGen DM image smart crop : small crop.")
public void testSmartCropOnNGDMImageV3_SmallCrop() throws TimeoutException, InterruptedException, ClientException {
addPathtoComponentPolicy(responsiveGridPath, Commons.RT_IMAGE_V3);
createComponentPolicy(Commons.RT_IMAGE_V3.substring(Commons.RT_IMAGE_V3.lastIndexOf("/")), new ArrayList<NameValuePair>() {{
createComponentPolicy(Commons.RT_IMAGE_V3.substring(Commons.RT_IMAGE_V3.lastIndexOf("/")), new ArrayList<>() {{
add(new BasicNameValuePair("enableDmFeatures", "true"));
}});
imageTests.testSmartCropOnNGDMImageV3("Small");
Expand Down

0 comments on commit b5e6a56

Please sign in to comment.