Repository navigation
feat(blocks): fork I4 widgets cluster (search, latest-posts) (#412) #479
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
3 commits
Select commit
Hold shift + click to select a range
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
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
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
2 changes: 2 additions & 0 deletions
2
packages/visual-editor-renderer-blade/resources/views/blocks/artisanpack/search.blade.php
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,2 @@ | ||
| {{-- artisanpack/search — delegates to core/search (carries the #338 button-icon a11y fix). --}} | ||
| @include('visual-editor-renderer-blade::blocks.core.search', ['attributes' => $attributes ?? [], 'innerContent' => $innerContent ?? '', 'blockName' => $blockName ?? 'artisanpack/search']) |
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
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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
resources/js/visual-editor/blocks/latest-posts/__tests__/deprecated.test.ts
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,48 @@ | ||
| /** | ||
| * Locks the deprecation chain for `artisanpack/latest-posts`. | ||
| * | ||
| * Mirrors upstream's single v1 entry, which migrates the legacy string | ||
| * `categories` attribute (a bare term id) to the array-of-objects shape. | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
|
|
||
| import deprecated from '../deprecated'; | ||
|
|
||
| describe('latest-posts deprecation chain', () => { | ||
| it('ships one deprecation entry (v1) matching upstream', () => { | ||
| expect(Array.isArray(deprecated)).toBe(true); | ||
| expect(deprecated).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('v1 declares the legacy string categories attribute', () => { | ||
| const v1 = deprecated[0]; | ||
| expect((v1.attributes as Record<string, { type: string }>).categories.type).toBe('string'); | ||
| }); | ||
|
|
||
| it('v1 is eligible only when categories is a string', () => { | ||
| const v1 = deprecated[0]; | ||
| expect(v1.isEligible({ categories: '7' })).toBe(true); | ||
| expect(v1.isEligible({ categories: [{ id: 7 }] as unknown as string })).toBe(false); | ||
| expect(v1.isEligible({})).toBe(false); | ||
| }); | ||
|
|
||
| it('v1 migrate() upgrades the string id to an array of objects', () => { | ||
| const v1 = deprecated[0]; | ||
| const migrated = v1.migrate({ categories: '7', postsToShow: 3 }); | ||
| expect(migrated.categories).toEqual([{ id: 7 }]); | ||
| expect(migrated.postsToShow).toBe(3); | ||
| }); | ||
|
|
||
| it('v1 migrate() drops a malformed category instead of emitting { id: NaN }', () => { | ||
| const v1 = deprecated[0]; | ||
| const migrated = v1.migrate({ categories: 'not-a-number', postsToShow: 3 }); | ||
| expect(migrated.categories).toBeUndefined(); | ||
| expect(migrated.postsToShow).toBe(3); | ||
| }); | ||
|
|
||
| it('v1 save() returns null (dynamic block)', () => { | ||
| const v1 = deprecated[0]; | ||
| expect(v1.save()).toBeNull(); | ||
| }); | ||
| }); |
87 changes: 87 additions & 0 deletions
87
resources/js/visual-editor/blocks/latest-posts/__tests__/edit.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,87 @@ | ||
| /** | ||
| * Tests for the `artisanpack/latest-posts` edit component. | ||
| * | ||
| * The preview is server-rendered, so these assertions focus on the | ||
| * inspector controls and that the edit wires the package's | ||
| * <ServerSideRender> seam to the `artisanpack/latest-posts` block name. | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| vi.mock('@wordpress/i18n', () => ({ | ||
| __: (text: string) => text, | ||
| })); | ||
|
|
||
| vi.mock('../../../vendor/i18n', () => ({ | ||
| TEXT_DOMAIN: 'artisanpack-visual-editor', | ||
| })); | ||
|
|
||
| vi.mock('../../../editor/server-side-render', () => ({ | ||
| ServerSideRender: ({ block, attributes }: { block: string; attributes: Record<string, unknown> }) => ( | ||
| <div data-testid="ssr" data-block={block} data-attrs={JSON.stringify(attributes)} /> | ||
| ), | ||
| })); | ||
|
|
||
| vi.mock('@wordpress/components', () => { | ||
| const Panel = ({ title, children }: { title?: string; children?: React.ReactNode }) => ( | ||
| <section data-panel={title}>{children}</section> | ||
| ); | ||
| const Toggle = ({ label, checked }: { label?: string; checked?: boolean }) => ( | ||
| <label data-toggle={label} data-checked={checked ? 'true' : 'false'} /> | ||
| ); | ||
| return { | ||
| PanelBody: Panel, | ||
| ToggleControl: Toggle, | ||
| RadioControl: ({ label }: { label?: string }) => <div data-radio={label} />, | ||
| RangeControl: ({ label }: { label?: string }) => <div data-range={label} />, | ||
| SelectControl: ({ label }: { label?: string }) => <div data-select={label} />, | ||
| }; | ||
| }); | ||
|
|
||
| vi.mock('@wordpress/block-editor', () => ({ | ||
| InspectorControls: ({ children }: { children?: React.ReactNode }) => ( | ||
| <div data-testid="inspector">{children}</div> | ||
| ), | ||
| useBlockProps: (props?: Record<string, unknown>) => ({ ...props }), | ||
| })); | ||
|
|
||
| (globalThis as { React?: unknown }).React = require('react'); | ||
|
|
||
| import LatestPostsEdit from '../edit'; | ||
|
|
||
| describe('LatestPostsEdit', () => { | ||
| it('previews via ServerSideRender for the artisanpack/latest-posts block', () => { | ||
| const { getByTestId } = render( | ||
| <LatestPostsEdit attributes={{ postsToShow: 5 }} setAttributes={vi.fn()} /> | ||
| ); | ||
| const ssr = getByTestId('ssr'); | ||
| expect(ssr.getAttribute('data-block')).toBe('artisanpack/latest-posts'); | ||
| }); | ||
|
|
||
| it('mounts the inspector with the sorting + filtering panel', () => { | ||
| const { getByTestId, container } = render( | ||
| <LatestPostsEdit attributes={{}} setAttributes={vi.fn()} /> | ||
| ); | ||
| expect(getByTestId('inspector')).toBeTruthy(); | ||
| expect(container.querySelector('[data-range="Number of items"]')).toBeTruthy(); | ||
| expect(container.querySelector('[data-select="Order by"]')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('reveals the excerpt-length control only when showing excerpt content', () => { | ||
| const { container } = render( | ||
| <LatestPostsEdit | ||
| attributes={{ displayPostContent: true, displayPostContentRadio: 'excerpt' }} | ||
| setAttributes={vi.fn()} | ||
| /> | ||
| ); | ||
| expect(container.querySelector('[data-range="Max number of words in excerpt"]')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('reveals the columns control only in grid layout', () => { | ||
| const { container } = render( | ||
| <LatestPostsEdit attributes={{ postLayout: 'grid' }} setAttributes={vi.fn()} /> | ||
| ); | ||
| expect(container.querySelector('[data-range="Columns"]')).toBeTruthy(); | ||
| }); | ||
| }); |
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.