Skip to content

Commit e667151

Browse files
authored
fix: usage of contentSourceEditPattern (#804)
* fix: usage of contentSourceEditPattern * fix: added test
1 parent d91ccf5 commit e667151

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/extension/app/store/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,8 @@ export class AppStore {
12931293
}
12941294

12951295
let updatedStatus = await this.fetchStatus(false, true, isReview);
1296-
let editUrl = updatedStatus.edit?.url || this.getBYOMSourceUrl(updatedStatus);
1296+
// prefer configured contentSourceEditPattern URL; otherwise fall back to status edit URL.
1297+
let editUrl = this.getBYOMSourceUrl(updatedStatus) || updatedStatus.edit?.url;
12971298

12981299
if (isReview) {
12991300
// restore original pathname and state
@@ -1302,7 +1303,8 @@ export class AppStore {
13021303
if (!editUrl) {
13031304
// no snapshot source, fall back to original edit URL
13041305
updatedStatus = await this.fetchStatus(false, true);
1305-
editUrl = updatedStatus.edit?.url || this.getBYOMSourceUrl(updatedStatus);
1306+
// prefer configured contentSourceEditPattern URL; otherwise fall back to status edit URL.
1307+
editUrl = this.getBYOMSourceUrl(updatedStatus) || updatedStatus.edit?.url;
13061308
}
13071309
}
13081310

test/app/store/app.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ describe('Test App Store', () => {
708708
expect(openPageArgs[0]).to.include(liveHost);
709709
});
710710

711-
it('switches from preview to BYOM editor', async () => {
711+
it('switches from preview to BYOM editor, no edit URL', async () => {
712712
instance.siteStore.contentSourceUrl = 'https://aemcloud.com';
713713
instance.siteStore.contentSourceEditLabel = 'Universal Editor';
714714
instance.siteStore.contentSourceEditPattern = '{{contentSourceUrl}}{{pathname}}?cmd=open';
@@ -722,6 +722,23 @@ describe('Test App Store', () => {
722722
expect(loadPage.calledWith('https://aemcloud.com/index?cmd=open')).to.be.true;
723723
});
724724

725+
it('switches from preview to BYOM editor, overwrites edit URL ', async () => {
726+
instance.siteStore.contentSourceUrl = 'https://aemcloud.com';
727+
instance.siteStore.contentSourceEditLabel = 'Universal Editor';
728+
instance.siteStore.contentSourceEditPattern = '{{contentSourceUrl}}{{pathname}}?cmd=open';
729+
730+
const fetchStatusStub = sidekickTest.sandbox.stub(instance, 'fetchStatus');
731+
fetchStatusStub.onCall(0).resolves({
732+
webPath: '/',
733+
edit: { url: 'https://edit.example.com/original-path' },
734+
});
735+
736+
instance.location = new URL(mockStatus.preview.url);
737+
instance.status = mockStatus;
738+
await instance.switchEnv('edit');
739+
expect(loadPage.calledWith('https://aemcloud.com/index?cmd=open')).to.be.true;
740+
});
741+
725742
it('switches from review to edit with snapshot path', async () => {
726743
const fetchStatusStub = sidekickTest.sandbox.stub(instance, 'fetchStatus');
727744
const isReviewStub = sidekickTest.sandbox.stub(instance, 'isReview');

0 commit comments

Comments
 (0)