Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into issue-30367-Implement…
Browse files Browse the repository at this point in the history
…-Abandoned-Job-Detection-and-Recovery-fixes
  • Loading branch information
jgambarios committed Dec 4, 2024
2 parents 81e1c04 + 3b866d6 commit 9258307
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
[cdkCopyToClipboard]="$toolbar().editor.copyUrl"
data-testId="uve-toolbar-copy-url" />

<p-button
<a
title="Page API URL"
pButton
label="API"
styleClass="p-button-text p-button-sm"
data-testId="uve-toolbar-api-link" />
class="p-button-text"
target="_blank"
data-testId="uve-toolbar-api-link"
[href]="$apiURL()"></a>
} @else if ($toolbar().preview) {
<div>PREVIEW MODE CONTENT</div>
<button (click)="togglePreviewMode(false)">Back</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
import { DotEmaBookmarksComponent } from '../dot-ema-bookmarks/dot-ema-bookmarks.component';
import { DotEmaRunningExperimentComponent } from '../dot-ema-running-experiment/dot-ema-running-experiment.component';

const $apiURL = '/api/v1/page/json/123-xyz-567-xxl?host_id=123-xyz-567-xxl&language_id=1';

describe('DotUveToolbarComponent', () => {
let spectator: Spectator<DotUveToolbarComponent>;
let messageService: MessageService;
Expand Down Expand Up @@ -125,6 +127,7 @@ describe('DotUveToolbarComponent', () => {
setSocialMedia: jest.fn(),
pageParams: signal(params),
pageAPIResponse: signal(MOCK_RESPONSE_VTL),
$apiURL: signal($apiURL),
reloadCurrentPage: jest.fn(),
loadPageAsset: jest.fn()
};
Expand Down Expand Up @@ -187,8 +190,8 @@ describe('DotUveToolbarComponent', () => {
});
});

it('should have api link button', () => {
expect(spectator.query(byTestId('uve-toolbar-api-link'))).toBeTruthy();
it('should have not experiments button if experiment is not running', () => {
expect(spectator.query(byTestId('uve-toolbar-running-experiment'))).toBeFalsy();
});

it('should have language selector', () => {
Expand All @@ -202,6 +205,17 @@ describe('DotUveToolbarComponent', () => {
it('should have workflows button', () => {
expect(spectator.query(byTestId('uve-toolbar-workflow-actions'))).toBeTruthy();
});

describe('API URL', () => {
it('should have api link button', () => {
expect(spectator.query(byTestId('uve-toolbar-api-link'))).toBeTruthy();
});

it('should have api link button with correct href', () => {
const btn = spectator.query(byTestId('uve-toolbar-api-link'));
expect(btn.getAttribute('href')).toBe($apiURL);
});
});
});

describe('State changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class DotUveToolbarComponent {
readonly #dotMessageService = inject(DotMessageService);

readonly $toolbar = this.#store.$uveToolbar;
readonly $apiURL = this.#store.$apiURL;

togglePreviewMode(preview: boolean) {
this.#store.togglePreviewMode(preview);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { describe } from '@jest/globals';
import { createServiceFactory, mockProvider, SpectatorService } from '@ngneat/spectator/jest';
import { signalStore, withState } from '@ngrx/signals';
import { of } from 'rxjs';

import { ActivatedRoute, Router } from '@angular/router';

import { withUVEToolbar } from './withUVEToolbar';

import { DotPageApiService } from '../../../../services/dot-page-api.service';
import { UVE_STATUS } from '../../../../shared/enums';
import { MOCK_RESPONSE_HEADLESS } from '../../../../shared/mocks';
import { UVEState } from '../../../models';

const pageParams = {
url: 'test-url',
language_id: '1',
'com.dotmarketing.persona.id': 'dot:persona',
variantName: 'DEFAULT',
clientHost: 'http://localhost:3000'
};

const initialState: UVEState = {
isEnterprise: true,
languages: [],
pageAPIResponse: MOCK_RESPONSE_HEADLESS,
currentUser: null,
experiment: null,
errorCode: null,
pageParams,
status: UVE_STATUS.LOADED,
isTraditionalPage: false,
canEditPage: true,
pageIsLocked: true,
isClientReady: false
};

export const uveStoreMock = signalStore(withState<UVEState>(initialState), withUVEToolbar());

describe('withEditor', () => {
let spectator: SpectatorService<InstanceType<typeof uveStoreMock>>;
let store: InstanceType<typeof uveStoreMock>;

const createService = createServiceFactory({
service: uveStoreMock,
providers: [
mockProvider(Router),
mockProvider(ActivatedRoute),
mockProvider(Router),
mockProvider(ActivatedRoute),
{
provide: DotPageApiService,
useValue: {
get() {
return of(MOCK_RESPONSE_HEADLESS);
},
getClientPage() {
return of(MOCK_RESPONSE_HEADLESS);
},
save: jest.fn()
}
}
]
});

beforeEach(() => {
spectator = createService();
store = spectator.service;
});

describe('Computed', () => {
it('should return the right API URL', () => {
const params = { ...pageParams };
// Delete the url from the params to test the function
delete params.url;

const queryParams = new URLSearchParams(params).toString();
const expectURL = `/api/v1/page/json/test-url?${queryParams}`;

expect(store.$apiURL()).toBe(expectURL);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ export function withUVEToolbar() {
unlockButton: shouldShowUnlock ? unlockButton : null,
showInfoDisplay: shouldShowInfoDisplay
};
}),
$apiURL: computed<string>(() => {
const pageParams = store.pageParams();
const url = sanitizeURL(pageParams?.url);
const params = createPageApiUrlWithQueryParams(url, pageParams);
const pageType = store.isTraditionalPage() ? 'render' : 'json';
const pageAPI = `/api/v1/page/${pageType}/${params}`;

return pageAPI;
})
})),
withMethods((store) => ({
Expand Down

0 comments on commit 9258307

Please sign in to comment.