Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,230 @@ describe('EditEmaEditorComponent', () => {
expect(viewUrl).toBeTruthy();
expect(typeof viewUrl?.value).toBe('string');
});

it('should include site URL when site hostname differs from clientHost', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://example.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'demo.dotcms.com',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl?.value).toBe('https://demo.dotcms.com/my-page');
});

it('should not include site URL when site hostname matches the clientHost', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://demo.dotcms.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'demo.dotcms.com',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl).toBeUndefined();
});

it('should include site URL with https when clientHost is absent and hostname differs', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: undefined,
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'demo.dotcms.com',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl?.value).toBe('https://demo.dotcms.com/my-page');
});

it('should include site URL when clientHost has a port and site hostname is portless', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://demo.dotcms.com:8080',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'demo.dotcms.com',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl?.value).toBe('https://demo.dotcms.com/my-page');
});

it('should suppress site URL for the System Host pseudo-site', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://example.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'System Host',
systemHost: true,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl).toBeUndefined();
});

it('should suppress site URL when hostname is malformed and URL construction throws', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://example.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'invalid host name',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl).toBeUndefined();
});

it('should not include site URL when site hostname matches clientHost with different casing', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://demo.dotcms.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: 'Demo.DotCMS.com',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl).toBeUndefined();
});

it('should not include site URL when site has no hostname', () => {
patchState(store, {
pageParams: {
url: '/my-page',
clientHost: 'https://example.com',
language_id: '1',
[PERSONA_KEY]: 'dot:persona'
},
pageAssetResponse: {
pageAsset: {
...MOCK_RESPONSE_HEADLESS,
site: {
identifier: '123',
hostname: '',
systemHost: false,
aliases: null
}
}
}
});

const siteUrl = spectator.component
.$pageURLS()
.find((u) => u.label === 'uve.toolbar.page.site.url');

expect(siteUrl).toBeUndefined();
});
});

describe('$pageURL', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ import {
shouldNavigate
} from '../utils';

type PageURL = { label: string; value: string };

// Message keys constants
const MESSAGE_KEY = {
DUPLICATE_CONTENT: {
Expand Down Expand Up @@ -1450,22 +1452,39 @@ export class EditEmaEditorComponent implements OnInit, OnDestroy, AfterViewInit
}
}

readonly $pageURLS = computed<{ label: string; value: string }[]>(() => {
readonly $pageURLS = computed<PageURL[]>(() => {
const params = this.uveStore.pageParams();
const siteId = this.uveStore.pageAsset()?.site?.identifier;
const site = this.uveStore.pageAsset()?.site;
const siteId = site?.identifier;
const host = params?.clientHost || this.window.location.origin;
const path = params?.url?.replace(/\/index(\.html)?$/, '') || '/';
const liveUrl = new URL(path, host).toString();

return [
const urls: PageURL[] = [
{
label: 'uve.toolbar.page.live.url',
value: new URL(path, host).toString()
value: liveUrl
},
{
label: 'uve.toolbar.page.current.view.url',
value: createFullURL(params, siteId)
}
];

if (site?.hostname && !site.systemHost) {
try {
const siteHostUrl = new URL(path, `https://${site.hostname}`).toString();

if (siteHostUrl !== liveUrl) {
urls.push({
label: 'uve.toolbar.page.site.url',
value: siteHostUrl
});
}
} catch {}
}

return urls;
});

protected triggerCopyToast(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6073,6 +6073,7 @@ uve.toolbar.style.editor=Style Editor
uve.toolbar.page.api.url=Page API URL
uve.toolbar.page.live.url=Live URL
uve.toolbar.page.current.view.url=Current View URL
uve.toolbar.page.site.url=Site URL
uve.preview.mode=Preview Mode
uve.preview.mode.device.subheader=Custom Devices
uve.preview.mode.social.media.subheader=Social Media Tiles
Expand Down
Loading