-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FTM): New UVE Toolbar - Implement "API" button (#30830)
This pull request includes several changes to the `DotUveToolbarComponent` and related files to enhance the functionality and testing of the API URL link. The most important changes include updating the toolbar component to use an anchor tag for the API URL link, adding a computed property for the API URL, and enhancing the tests to verify the correct behavior of the API URL link. Changes to `DotUveToolbarComponent`: * Updated the toolbar component to use an anchor (`<a>`) tag instead of a button for the API URL link, and added attributes such as `title`, `target`, and `href` to improve accessibility and functionality. (`[core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/components/dot-uve-toolbar/dot-uve-toolbar.component.htmlL19-R26](diffhunk://#diff-9937556e73b051b878ba22ad1ce971a70019a617d7979b3e0bcc814801ad350bL19-R26)`) Enhancements to testing: * Added a constant `$apiURL` and updated the `DotUveToolbarComponent` tests to include this constant and verify the presence and correctness of the API URL link. (`[[1]](diffhunk://#diff-3eaa147616a5d1ff374a5fa27b0f38f0159a9039ef7e8d672dec43631f48a9e1R38-R39)`, `[[2]](diffhunk://#diff-3eaa147616a5d1ff374a5fa27b0f38f0159a9039ef7e8d672dec43631f48a9e1R123)`, `[[3]](diffhunk://#diff-3eaa147616a5d1ff374a5fa27b0f38f0159a9039ef7e8d672dec43631f48a9e1L177-L180)`, `[[4]](diffhunk://#diff-3eaa147616a5d1ff374a5fa27b0f38f0159a9039ef7e8d672dec43631f48a9e1R195-R205)`) Computed property for API URL: * Added a computed property `$apiURL` in the `DotUveToolbarComponent` to dynamically generate the API URL based on the page parameters. (`[[1]](diffhunk://#diff-217a9e619d6590c4f652e85353b9637ba5e464ddeb0424be35aef39bb8dceb30R34)`, `[[2]](diffhunk://#diff-e6d3fb6319626fa85a4fc6894b57935843713366be593de6dd1dc5ed68bf6afcR119-R127)`) New test for `withUVEToolbar`: * Added a new test file `withUVEToolbar.spec.ts` to verify the computed property `$apiURL` and ensure it returns the correct API URL based on given page parameters. (`[core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/toolbar/withUVEToolbar.spec.tsR1-R83](diffhunk://#diff-7a5de702ac1dc81304f4c31816f5c0363aa56141f8afa583a87856e7a0d8482dR1-R83)`) ### Videos #### Traditional https://github.com/user-attachments/assets/3042d0d0-c964-4d1c-b454-736e71542f21 #### Headless https://github.com/user-attachments/assets/25fc13b6-5101-47e0-871a-feea0b65156a
- Loading branch information
Showing
5 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...bs/portlets/edit-ema/portlet/src/lib/store/features/editor/toolbar/withUVEToolbar.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters