Skip to content

Commit 7321b58

Browse files
committed
SITES-28486 - [SLA3] Inconsistency in Inplace Editing Redirecting to Old Content Fragment Editor
* added karma tests for contentfragment editAction
1 parent a3ac4a5 commit 7321b58

File tree

5 files changed

+281
-10
lines changed

5 files changed

+281
-10
lines changed

content/karma.conf.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ module.exports = function(config) {
3030

3131
// list of files / patterns to load in the browser
3232
files: [
33+
'test/mocks.js',
3334
'src/content/jcr_root/apps/core/wcm/components/commons/site/clientlibs/**/js/*.js',
3435
'src/content/jcr_root/apps/core/wcm/components/image/v3/image/clientlibs/site/**/js/*.js',
36+
'src/content/jcr_root/apps/core/wcm/components/contentfragment/v1/contentfragment/clientlibs/editor/authoring/js/editAction.js',
3537
'test/**/*Test.js',
36-
'test/**/*Test.html',
37-
'spec/**/*Test.html'
38+
'test/**/*Test.html'
3839
],
3940

4041

@@ -97,4 +98,4 @@ module.exports = function(config) {
9798
dir: './coverage/'
9899
},
99100
})
100-
}
101+
}

content/package-lock.json

+8-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Adobe
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
******************************************************************************/
16+
describe("Test content fragment edit action for", function() {
17+
18+
beforeAll(function () {
19+
fixture.setBase('test/fixtures/contentfragment')
20+
Granite.author.CFM.Fragments.mappings.set(
21+
"/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia",
22+
{ variation: "master" }
23+
);
24+
Granite.author.CFM.Fragments.mappings.set(
25+
"/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting",
26+
{ variation: "other" }
27+
);
28+
})
29+
30+
afterAll(function () {
31+
Granite.author.CFM.Fragments.mappings.clear();
32+
});
33+
34+
beforeEach(function () {
35+
this.result = fixture.load('editActionTest.html');
36+
spyOn(window, 'open');
37+
});
38+
39+
afterEach(function () {
40+
fixture.cleanup()
41+
});
42+
43+
it("empty content fragment", function() {
44+
const editable = { dom: fixture.el.children.item(0)};
45+
Granite.author.editor.contentfragment.setUp(editable);
46+
47+
const canEdit = Granite.author.editor.contentfragment.canEdit(editable);
48+
Granite.author.editor.contentfragment.setUp(editable);
49+
50+
expect(canEdit).toBeFalse();
51+
expect(window.open).toHaveBeenCalledTimes(0);
52+
});
53+
54+
it("content fragment master variation and feature toggle disabled", function() {
55+
Granite.Toggles.enabled = false;
56+
const editable = { dom: fixture.el.children.item(1)};
57+
58+
const canEdit = Granite.author.editor.contentfragment.canEdit(editable);
59+
Granite.author.editor.contentfragment.setUp(editable);
60+
61+
expect(canEdit).toBeTrue();
62+
const expectedUrl = '/editor.html/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia';
63+
expect(window.open).toHaveBeenCalledOnceWith(expectedUrl);
64+
});
65+
66+
it("content fragment master variation and feature toggle enabled", function() {
67+
Granite.Toggles.enabled = true;
68+
const editable = { dom: fixture.el.children.item(1)};
69+
70+
const canEdit = Granite.author.editor.contentfragment.canEdit(editable);
71+
Granite.author.editor.contentfragment.setUp(editable);
72+
73+
expect(canEdit).toBeTrue();
74+
const expectedUrl = 'https://experience.adobe.com/?repo=localhost#/aem/cf/editor/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia';
75+
expect(window.open).toHaveBeenCalledOnceWith(expectedUrl);
76+
});
77+
78+
it("content fragment other variation and feature toggle disabled", function() {
79+
Granite.Toggles.enabled = false;
80+
const editable = { dom: fixture.el.children.item(2)};
81+
82+
const canEdit = Granite.author.editor.contentfragment.canEdit(editable);
83+
Granite.author.editor.contentfragment.setUp(editable);
84+
85+
expect(canEdit).toBeTrue();
86+
const expectedUrl = '/editor.html/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting?variation=other';
87+
expect(window.open).toHaveBeenCalledOnceWith(expectedUrl);
88+
});
89+
90+
it("content fragment other variation and feature toggle enabled", function() {
91+
Granite.Toggles.enabled = true;
92+
const editable = { dom: fixture.el.children.item(2)};
93+
94+
const canEdit = Granite.author.editor.contentfragment.canEdit(editable);
95+
Granite.author.editor.contentfragment.setUp(editable);
96+
97+
expect(canEdit).toBeTrue();
98+
const expectedUrl = 'https://experience.adobe.com/?repo=localhost#/aem/cf/editor/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting';
99+
expect(window.open).toHaveBeenCalledOnceWith(expectedUrl);
100+
});
101+
102+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2025 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
16+
<div class="contentfragment aem-GridColumn aem-GridColumn--default--12">
17+
<div class="cq-placeholder cq-dd-contentfragment" data-emptytext="Content Fragment"></div>
18+
<cq data-path="/content/wknd/us/en/test-page/jcr:content/root/container/contentfragment" data-config="{}"></cq>
19+
</div>
20+
<div class="contentfragment aem-GridColumn aem-GridColumn--default--12 cq-Editable-dom">
21+
<article id="contentfragment-a379b545ca" class="cmp-contentfragment cmp-contentfragment--riverside-camping-australia"
22+
data-cmp-contentfragment-model="wknd-shared/models/adventure" data-json="{}"
23+
data-cmp-contentfragment-path="/content/dam/wknd-shared/en/adventures/riverside-camping-australia/riverside-camping-australia">
24+
<h3 class="cmp-contentfragment__title">Riverside Camping Australia</h3>
25+
<dl class="cmp-contentfragment__elements cq-dd-contentfragment">
26+
<div class="cmp-contentfragment__element cmp-contentfragment__element--title" data-cmp-contentfragment-element-type="string">
27+
<dt class="cmp-contentfragment__element-title">Title</dt>
28+
<dd class="cmp-contentfragment__element-value">
29+
Riverside Camping Australia
30+
</dd>
31+
</div>
32+
<div class="cmp-contentfragment__element cmp-contentfragment__element--slug" data-cmp-contentfragment-element-type="string">
33+
<dt class="cmp-contentfragment__element-title">Slug</dt>
34+
<dd class="cmp-contentfragment__element-value">
35+
riverside-camping-australia
36+
</dd>
37+
</div>
38+
<div class="cmp-contentfragment__element cmp-contentfragment__element--description" data-cmp-contentfragment-element-type="string">
39+
<dt class="cmp-contentfragment__element-title">Description</dt>
40+
<dd class="cmp-contentfragment__element-value">
41+
<p>Escape the hustle and bustle of city life and recharge with a couple of peaceful days and return with tons of memories of camping in the bush and experiences that will last a lifetime. </p>
42+
</dd>
43+
</div>
44+
</dl>
45+
</article>
46+
<cq data-path="/content/wknd/us/en/test-page/jcr:content/root/container/contentfragment" data-config="{}"></cq>
47+
</div>
48+
<div class="contentfragment aem-GridColumn aem-GridColumn--default--12">
49+
<article id="contentfragment-a379b545cc" class="cmp-contentfragment cmp-contentfragment--napa-wine-tasting"
50+
data-cmp-contentfragment-model="wknd-shared/models/adventure" data-json="{}"
51+
data-cmp-contentfragment-path="/content/dam/wknd-shared/en/adventures/napa-wine-tasting/napa-wine-tasting">
52+
<h3 class="cmp-contentfragment__title">Napa Wine Tasting</h3>
53+
<dl class="cmp-contentfragment__elements cq-dd-contentfragment">
54+
<div class="cmp-contentfragment__element cmp-contentfragment__element--title" data-cmp-contentfragment-element-type="string">
55+
<dt class="cmp-contentfragment__element-title">Title</dt>
56+
<dd class="cmp-contentfragment__element-value">
57+
Napa Wine Tasting
58+
</dd>
59+
</div>
60+
<div class="cmp-contentfragment__element cmp-contentfragment__element--slug" data-cmp-contentfragment-element-type="string">
61+
<dt class="cmp-contentfragment__element-title">Slug</dt>
62+
<dd class="cmp-contentfragment__element-value">
63+
napa-wine-tasting
64+
</dd>
65+
</div>
66+
<div class="cmp-contentfragment__element cmp-contentfragment__element--description" data-cmp-contentfragment-element-type="string">
67+
<dt class="cmp-contentfragment__element-title">Description</dt>
68+
<dd class="cmp-contentfragment__element-value">
69+
<h3>Enjoy spectacular wine tasting in the Napa Valley</h3>
70+
<p>Napa Valley is one of the most famous wine regions in the world. Located an hour north of San Francisco, Napa is renowned for their wine, pleasant temperatures and world class restaurants.</p>
71+
</dd>
72+
</div>
73+
</dl>
74+
</article>
75+
<cq data-path="/content/wknd/us/en/test-page/jcr:content/root/container/contentfragment" data-config="{}"></cq>
76+
</div>

content/test/mocks.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Adobe
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
******************************************************************************/
16+
class JQueryArray extends Array {
17+
find(selector) {
18+
const elem = this[0].querySelector(selector)
19+
return elem ? new JQueryArray(elem) : new JQueryArray();
20+
}
21+
22+
attr(name) {
23+
return this[0] ? this[0].getAttribute(name) : null;
24+
}
25+
}
26+
27+
function jQuery(obj) {
28+
return new JQueryArray(obj);
29+
}
30+
31+
Granite = {
32+
author: {
33+
util: {
34+
mixin: function (dest, src) {
35+
for (var prop in src) {
36+
if (src.hasOwnProperty(prop)) {
37+
dest[prop] = src[prop];
38+
}
39+
}
40+
},
41+
createClass: function (classDefinition) {
42+
var methods = {};
43+
44+
if (!classDefinition.constructor) {
45+
classDefinition.constructor = function () {
46+
};
47+
}
48+
49+
for (var prop in classDefinition) {
50+
if (classDefinition.hasOwnProperty(prop) && prop !== "constructor") {
51+
methods[prop] = classDefinition[prop];
52+
}
53+
}
54+
55+
Granite.author.util.mixin(classDefinition.constructor.prototype, methods);
56+
57+
return classDefinition.constructor;
58+
}
59+
},
60+
editor: {
61+
register: function (type, editor) {
62+
this[type] = editor;
63+
}
64+
},
65+
CFM: {
66+
Fragments: {
67+
mappings: new Map(),
68+
adaptToFragment: function (dom) {
69+
const fragmentElem = dom.querySelector('[data-cmp-contentfragment-path]');
70+
if (fragmentElem) {
71+
const fragmentPath = fragmentElem.getAttribute('data-cmp-contentfragment-path');
72+
return Granite.author.CFM.Fragments.mappings.get(fragmentPath);
73+
} else {
74+
return null;
75+
}
76+
}
77+
}
78+
}
79+
},
80+
Toggles: {
81+
enabled: false,
82+
isEnabled: function (feature) {
83+
return Granite.Toggles.enabled;
84+
}
85+
},
86+
HTTP: {
87+
externalize: function (url) {
88+
return url;
89+
}
90+
},
91+
};

0 commit comments

Comments
 (0)