Skip to content

Commit 1e7b84f

Browse files
committed
chore: fix code smells.
1 parent 26aa8dd commit 1e7b84f

3 files changed

Lines changed: 68 additions & 67 deletions

File tree

content/src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/editor/js/image.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,6 @@
935935
imageV3EditorTestApiHost.__IMAGE_V3_EDITOR_TEST_API.installRemoteAssetDynamicMediaTestFixture = function(rootElement) {
936936
$dialogContent = $(rootElement);
937937
$dynamicMediaGroup = $dialogContent.find(".cmp-image__editor-dynamicmedia");
938-
areDMFeaturesEnabled = ($dynamicMediaGroup.length === 1);
939938
smartCropRenditionsDropDown = rootElement.querySelector(".cmp-image__editor-dynamicmedia-smartcroprendition");
940939
if (smartCropRenditionsDropDown) {
941940
if (!smartCropRenditionsDropDown.items) {

content/test/clientlibs/authoringutils/imageV3EditorRemoteAssetTest.js

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,70 +17,73 @@
1717
* Image v3 editor remote asset (urn:aaid:aem) Dynamic Media dialog behaviour.
1818
* Depends on {@code imageV3EditorImageTest.js} / {@code image.js} loading first.
1919
*/
20+
function imageV3EditorRemoteAssetIsParentVisible(element) {
21+
return element?.parentElement?.style.display !== "none";
22+
}
23+
24+
function imageV3EditorRemoteAssetIsGroupVisible(root) {
25+
const group = root.querySelector(".cmp-image__editor-dynamicmedia");
26+
return group?.style.display !== "none";
27+
}
28+
29+
function imageV3EditorRemoteAssetCreateDynamicMediaDialogFixture() {
30+
const root = document.createElement("div");
31+
root.className = "cmp-image__editor";
32+
33+
const pageImageCheckbox = document.createElement("coral-checkbox");
34+
pageImageCheckbox.setAttribute("name", "./imageFromPageImage");
35+
pageImageCheckbox.checked = false;
36+
root.appendChild(pageImageCheckbox);
37+
38+
const group = document.createElement("div");
39+
group.className = "cmp-image__editor-dynamicmedia";
40+
group.style.display = "none";
41+
root.appendChild(group);
42+
43+
const presetTypeWrapper = document.createElement("div");
44+
const presetType = document.createElement("div");
45+
presetType.className = "cmp-image__editor-dynamicmedia-presettype";
46+
const imagePresetRadio = document.createElement("input");
47+
imagePresetRadio.type = "radio";
48+
imagePresetRadio.name = "./dmPresetType";
49+
imagePresetRadio.value = "imagePreset";
50+
imagePresetRadio.checked = false;
51+
const smartCropRadio = document.createElement("input");
52+
smartCropRadio.type = "radio";
53+
smartCropRadio.name = "./dmPresetType";
54+
smartCropRadio.value = "smartCrop";
55+
presetType.appendChild(imagePresetRadio);
56+
presetType.appendChild(smartCropRadio);
57+
presetTypeWrapper.appendChild(presetType);
58+
group.appendChild(presetTypeWrapper);
59+
60+
const imagePresetWrapper = document.createElement("div");
61+
const imagePreset = document.createElement("select");
62+
imagePreset.className = "cmp-image__editor-dynamicmedia-imagepreset";
63+
imagePresetWrapper.appendChild(imagePreset);
64+
group.appendChild(imagePresetWrapper);
65+
66+
const smartCropWrapper = document.createElement("div");
67+
const smartCrop = document.createElement("coral-select");
68+
smartCrop.className = "cmp-image__editor-dynamicmedia-smartcroprendition";
69+
smartCropWrapper.appendChild(smartCrop);
70+
group.appendChild(smartCropWrapper);
71+
72+
const modifiersWrapper = document.createElement("div");
73+
const modifiers = document.createElement("input");
74+
modifiers.setAttribute("name", "./imageModifiers");
75+
modifiersWrapper.appendChild(modifiers);
76+
group.appendChild(modifiersWrapper);
77+
78+
return root;
79+
}
80+
2081
describe("Image v3 editor remote asset Dynamic Media", function() {
2182
let api;
2283
let fixtureRoot;
23-
24-
function isParentVisible(element) {
25-
return element && element.parentElement && element.parentElement.style.display !== "none";
26-
}
27-
28-
function isGroupVisible(root) {
29-
const group = root.querySelector(".cmp-image__editor-dynamicmedia");
30-
return group && group.style.display !== "none";
31-
}
32-
33-
function createDynamicMediaDialogFixture() {
34-
const root = document.createElement("div");
35-
root.className = "cmp-image__editor";
36-
37-
const pageImageCheckbox = document.createElement("coral-checkbox");
38-
pageImageCheckbox.setAttribute("name", "./imageFromPageImage");
39-
pageImageCheckbox.checked = false;
40-
root.appendChild(pageImageCheckbox);
41-
42-
const group = document.createElement("div");
43-
group.className = "cmp-image__editor-dynamicmedia";
44-
group.style.display = "none";
45-
root.appendChild(group);
46-
47-
const presetTypeWrapper = document.createElement("div");
48-
const presetType = document.createElement("div");
49-
presetType.className = "cmp-image__editor-dynamicmedia-presettype";
50-
const imagePresetRadio = document.createElement("input");
51-
imagePresetRadio.type = "radio";
52-
imagePresetRadio.name = "./dmPresetType";
53-
imagePresetRadio.value = "imagePreset";
54-
imagePresetRadio.checked = false;
55-
const smartCropRadio = document.createElement("input");
56-
smartCropRadio.type = "radio";
57-
smartCropRadio.name = "./dmPresetType";
58-
smartCropRadio.value = "smartCrop";
59-
presetType.appendChild(imagePresetRadio);
60-
presetType.appendChild(smartCropRadio);
61-
presetTypeWrapper.appendChild(presetType);
62-
group.appendChild(presetTypeWrapper);
63-
64-
const imagePresetWrapper = document.createElement("div");
65-
const imagePreset = document.createElement("select");
66-
imagePreset.className = "cmp-image__editor-dynamicmedia-imagepreset";
67-
imagePresetWrapper.appendChild(imagePreset);
68-
group.appendChild(imagePresetWrapper);
69-
70-
const smartCropWrapper = document.createElement("div");
71-
const smartCrop = document.createElement("coral-select");
72-
smartCrop.className = "cmp-image__editor-dynamicmedia-smartcroprendition";
73-
smartCropWrapper.appendChild(smartCrop);
74-
group.appendChild(smartCropWrapper);
75-
76-
const modifiersWrapper = document.createElement("div");
77-
const modifiers = document.createElement("input");
78-
modifiers.setAttribute("name", "./imageModifiers");
79-
modifiersWrapper.appendChild(modifiers);
80-
group.appendChild(modifiersWrapper);
81-
82-
return root;
83-
}
84+
const isParentVisible = imageV3EditorRemoteAssetIsParentVisible;
85+
const isGroupVisible = imageV3EditorRemoteAssetIsGroupVisible;
86+
const createDynamicMediaDialogFixture = imageV3EditorRemoteAssetCreateDynamicMediaDialogFixture;
8487

8588
beforeAll(function() {
8689
api = globalThis.__IMAGE_V3_EDITOR_TEST_API;
@@ -93,9 +96,7 @@ describe("Image v3 editor remote asset Dynamic Media", function() {
9396
});
9497

9598
afterEach(function() {
96-
if (fixtureRoot && fixtureRoot.parentNode) {
97-
fixtureRoot.parentNode.removeChild(fixtureRoot);
98-
}
99+
fixtureRoot?.remove();
99100
fixtureRoot = null;
100101
});
101102

content/test/mocks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ class JQueryArray extends Array {
6464
}
6565

6666
parent() {
67-
if (!this[0] || !this[0].parentElement) {
67+
const parentElement = this[0]?.parentElement;
68+
if (!parentElement) {
6869
return new JQueryArray();
6970
}
70-
return new JQueryArray(this[0].parentElement);
71+
return new JQueryArray(parentElement);
7172
}
7273

7374
prop(name, value) {

0 commit comments

Comments
 (0)