-
Notifications
You must be signed in to change notification settings - Fork 34
[Document Editor] Render areabrick previewHtml in the areablock brick picker #4014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e826aeb
[Document Editor] Render areabrick previewHtml in the areablock brick…
kingjia90 d47cbbd
Automatic frontend build
kingjia90 a6ebd1a
Potential fix for pull request finding
kingjia90 cf2c1c5
Automatic frontend build
kingjia90 8b2fbe0
Merge branch '2026.2' into fix/pv272-areabrick-preview-html
kingjia90 fe15f16
Add regression test for the areablock menu previewHtml tooltip
kingjia90 cd3f80a
Automatic frontend build
kingjia90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...nitions/document/editable/components/areablock-editable/hooks/use-areablock-menu.test.tsx
This file contains hidden or 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,122 @@ | ||
| /** | ||
| * This source file is available under the terms of the | ||
| * Pimcore Open Core License (POCL) | ||
| * Full copyright and license information is available in | ||
| * LICENSE.md which is distributed with this source code. | ||
| * | ||
| * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) | ||
| * @license Pimcore Open Core License (POCL) | ||
| */ | ||
|
|
||
| import React from 'react' | ||
| import { render } from '@testing-library/react' | ||
| import { useAreablockMenu, type UseAreablockMenuReturn } from './use-areablock-menu' | ||
| import { type AreablockEditableConfig } from '../areablock-editable' | ||
|
|
||
| jest.mock('react-i18next', () => ({ | ||
| useTranslation: () => ({ t: (key: string) => key }) | ||
| })) | ||
|
|
||
| const getMenuItems = (config?: AreablockEditableConfig): NonNullable<UseAreablockMenuReturn['menuItems']> => { | ||
| let result: UseAreablockMenuReturn['menuItems'] | ||
|
|
||
| const Probe = (): null => { | ||
| result = useAreablockMenu({ config, onAddArea: jest.fn() }).menuItems | ||
| return null | ||
| } | ||
|
|
||
| render(<Probe />) | ||
|
|
||
| return result ?? [] | ||
| } | ||
|
|
||
| const getTooltipTitle = (item: NonNullable<UseAreablockMenuReturn['menuItems']>[number]): React.ReactNode => { | ||
| const label = (item as { label: React.ReactElement<{ title: React.ReactNode }> }).label | ||
| return label.props.title | ||
| } | ||
|
|
||
| const renderTooltipTitle = (title: React.ReactNode): HTMLElement => render(<div>{ title }</div>).container | ||
|
|
||
| describe('useAreablockMenu previewHtml tooltip', () => { | ||
| it('renders the sanitized previewHtml in the tooltip and keeps the description above it', () => { | ||
| const items = getMenuItems({ | ||
| types: [{ | ||
| name: 'My Brick', | ||
| type: 'my-brick', | ||
| description: 'My description', | ||
| previewHtml: '<img src="/preview.png" onerror="alert(1)"><script>alert(2)</script><p>preview text</p>' | ||
| }] | ||
| }) | ||
|
|
||
| expect(items).toHaveLength(1) | ||
|
|
||
| const container = renderTooltipTitle(getTooltipTitle(items[0])) | ||
|
|
||
| expect(container.textContent).toContain('My description') | ||
| expect(container.textContent).toContain('preview text') | ||
|
|
||
| const img = container.querySelector('img') | ||
| expect(img).not.toBeNull() | ||
| expect(img?.getAttribute('src')).toBe('/preview.png') | ||
| expect(img?.getAttribute('onerror')).toBeNull() | ||
| expect(container.querySelector('script')).toBeNull() | ||
| }) | ||
|
|
||
| it('renders the previewHtml without a description wrapper when no description is set', () => { | ||
| const items = getMenuItems({ | ||
| types: [{ | ||
| name: 'My Brick', | ||
| type: 'my-brick', | ||
| previewHtml: '<p>preview only</p>' | ||
| }] | ||
| }) | ||
|
|
||
| const container = renderTooltipTitle(getTooltipTitle(items[0])) | ||
|
|
||
| expect(container.textContent).toBe('preview only') | ||
| }) | ||
|
|
||
| it.each([ | ||
| ['undefined', undefined], | ||
| ['null', null], | ||
| ['empty', ''] | ||
| ])('falls back to the plain description when previewHtml is %s', (_label, previewHtml) => { | ||
| const items = getMenuItems({ | ||
| types: [{ | ||
| name: 'My Brick', | ||
| type: 'my-brick', | ||
| description: 'My description', | ||
| previewHtml | ||
| }] | ||
| }) | ||
|
|
||
| expect(getTooltipTitle(items[0])).toBe('My description') | ||
| }) | ||
|
|
||
| it('has no tooltip title when neither description nor previewHtml are set', () => { | ||
| const items = getMenuItems({ | ||
| types: [{ name: 'My Brick', type: 'my-brick' }] | ||
| }) | ||
|
|
||
| expect(getTooltipTitle(items[0])).toBeUndefined() | ||
| }) | ||
|
|
||
| it('renders the previewHtml tooltip for grouped menu entries too', () => { | ||
| const items = getMenuItems({ | ||
| types: [{ | ||
| name: 'My Brick', | ||
| type: 'my-brick', | ||
| previewHtml: '<p>grouped preview</p>' | ||
| }], | ||
| group: { 'My Group': ['my-brick'] } | ||
| }) | ||
|
|
||
| expect(items).toHaveLength(1) | ||
|
|
||
| const children = (items[0] as { children: NonNullable<UseAreablockMenuReturn['menuItems']> }).children | ||
| expect(children).toHaveLength(1) | ||
|
|
||
| const container = renderTooltipTitle(getTooltipTitle(children[0])) | ||
| expect(container.textContent).toBe('grouped preview') | ||
| }) | ||
| }) |
This file contains hidden or 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
Binary file renamed
BIN
+4.22 MB
build-dist/build-65ed5944030f.zip → build-dist/build-184a98fffefe.zip
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.