Skip to content

Commit

Permalink
Merge branch 'main' into issues/SITES-22935
Browse files Browse the repository at this point in the history
  • Loading branch information
mohiaror committed Jul 1, 2024
2 parents 763f357 + b5e6a56 commit 36d7f2d
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ private Page getLocalizedPage(Page page, Page languageRoot) {
Page localizedPage;
String path = languageRoot.getPath();
String relativePath = page.getPath();
if (relativePath.startsWith(path)) {
int indexOfStart = 0;
if (path.length() < relativePath.length()) {
indexOfStart = path.length();
}
if (relativePath.startsWith(path) &&
relativePath.charAt(indexOfStart) == '/') {
localizedPage = page;
} else {
String separator = "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public class LanguageNavigationImplTest {
"/content/languagenavigation/LOCALE-4/LOCALE-9.html"},
};

private static final Object[][] EXPECTED_COUNTRY_LIST = {
{"/content/countrytest/languagenavigation/ch", "ch", false, 0, "", "ch",
"/ch-3-vanity"},
{"/content/countrytest/languagenavigation/ch_zn", "ch_zn", true, 0, "", "ch",
"/ch_zn-3-vanity"},
{"/content/countrytest/languagenavigation/en", "en", false, 0, "", "en", "/en-3-vanity"},
};

protected final AemContext context = CoreComponentTestContext.newAemContext();

protected String testBase;
Expand Down Expand Up @@ -152,6 +160,15 @@ protected void testLanguageNavigationItemsOnTemplate() {

}

@Test
protected void testLanguageNavigationItemsWithExtendedCountryCode() {
context.load().json(testBase + "/test-content-country.json", "/content/countrytest");
LanguageNavigation languageNavigation = getLanguageNavigationUnderTest(
"/content/countrytest/languagenavigation/ch_zn/jcr:content/root/languagenavigation-component-1");
List<NavigationItem> items = getLanguageNavigationItems(languageNavigation);
verifyLanguageNavigationItems(EXPECTED_COUNTRY_LIST, items);
}

protected LanguageNavigation getLanguageNavigationUnderTest(String resourcePath) {
Utils.enableDataLayer(context, true);
context.currentResource(resourcePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"languagenavigation": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Language Structure",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200"
},
"ch": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "ch",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch-3-vanity",
"jcr:language": "ch"
}
},
"ch_zn": {
"jcr:primaryType": "cq:Page",
"jcr:content" : {
"jcr:primaryType": "cq:PageContent",
"jcr:title" : "ch_zn",
"jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch_zn-3-vanity",
"jcr:language" : "ch",
"root" : {
"jcr:primaryType": "nt:unstructured",
"languagenavigation-component-1": {
"jcr:primaryType" : "nt:unstructured",
"sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation",
"navigationRoot" : "/content/countrytest/languagenavigation",
"structureDepth" : 1
}
}
}
},
"en": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "en",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/en-3-vanity",
"jcr:language": "en"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"languagenavigation": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Language Structure",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200"
},
"ch": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "ch",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch-3-vanity",
"jcr:language": "ch"
}
},
"ch_zn": {
"jcr:primaryType": "cq:Page",
"jcr:content" : {
"jcr:primaryType": "cq:PageContent",
"jcr:title" : "ch_zn",
"jcr:created" : "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/ch_zn-3-vanity",
"jcr:language" : "ch",
"root" : {
"jcr:primaryType": "nt:unstructured",
"languagenavigation-component-1": {
"jcr:primaryType" : "nt:unstructured",
"sling:resourceType": "core/wcm/components/languagenavigation/v1/languagenavigation",
"navigationRoot" : "/content/countrytest/languagenavigation",
"structureDepth" : 1
}
}
}
},
"en": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "en",
"jcr:created": "Mon Jul 10 2017 20:21:55 GMT+0200",
"sling:vanityPath": "/en-3-vanity",
"jcr:language": "en"
}
}
}
}
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 @@ -183,11 +183,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 @@ -314,12 +321,12 @@
} else {
$altGroup.show();
altTuple.hideTextfield(false);
altTuple.hideCheckbox(fromPageCheckbox.checked);
altTuple.hideCheckbox(fromPageCheckbox.checked || isRemoteFileReference(remoteFileReference));

Check failure on line 324 in content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js

View workflow job for this annotation

GitHub Actions / build-js (14)

'remoteFileReference' is not defined

Check failure on line 324 in content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js

View workflow job for this annotation

GitHub Actions / build-js (14)

'remoteFileReference' is not defined
altFromPageTuple.hideCheckbox(!fromPageCheckbox.checked);
if (fromPageCheckbox.checked) {
altFromPageTuple.seedTextValue(altTextFromPage);
altFromPageTuple.update();
} else {
} else if (!isRemoteFileReference(remoteFileReference)) {

Check failure on line 329 in content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js

View workflow job for this annotation

GitHub Actions / build-js (14)

'remoteFileReference' is not defined

Check failure on line 329 in content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js

View workflow job for this annotation

GitHub Actions / build-js (14)

'remoteFileReference' is not defined
altTuple.seedTextValue(altTextFromDAM);
altTuple.update();
}
Expand Down Expand Up @@ -351,6 +358,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 36d7f2d

Please sign in to comment.