From 67cccc33b9bdc381d27f7c95767587b62cd0b2e6 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Mon, 15 Sep 2025 13:34:56 -0500 Subject: [PATCH 01/13] add embedded property to normalized result --- components/content-search/utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index 6f150c75..6b912eea 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -97,6 +97,7 @@ export const normalizeResults = ({ title: string; type: ContentSearchMode | string; url: string; + embedded?: WP_REST_API_Search_Result['_embedded'] | WP_REST_API_User['_embedded']; }> => { const filteredResults = filterOutExcludedItems({ results, excludeItems }); return filteredResults.map((item) => { @@ -109,6 +110,7 @@ export const normalizeResults = ({ title: userItem.name, type: mode, url: userItem.link, + embedded: userItem._embedded, }; default: const searchItem = item as WP_REST_API_Search_Result; @@ -118,6 +120,7 @@ export const normalizeResults = ({ title: searchItem.title, type: searchItem.type, url: searchItem.url, + embedded: searchItem._embedded, }; } }); From b971113ff7f5d4d5943658000f25d5eb929b643e Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Mon, 15 Sep 2025 14:02:25 -0500 Subject: [PATCH 02/13] ensure both _links and _embedded are part of _fields array --- components/content-search/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index 6b912eea..e2037132 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -51,7 +51,7 @@ export const prepareSearchQuery = ({ case 'user': searchQuery = addQueryArgs('wp/v2/users', { search: keyword, - _fields: ['id', 'link', 'url', 'type', 'name', 'subtype'], + _fields: ['id', 'link', 'url', 'type', 'name', 'subtype', '_links', '_embedded'], }); break; default: @@ -62,7 +62,7 @@ export const prepareSearchQuery = ({ _embed: true, per_page: perPage, page, - _fields: ['id', 'link', 'url', 'type', 'title', 'subtype'], + _fields: ['id', 'link', 'url', 'type', 'title', 'subtype', '_links', '_embedded'], }); break; From 47dda759919b3e5964ca3a4f806a5c408da4e5c1 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Mon, 15 Sep 2025 14:03:51 -0500 Subject: [PATCH 03/13] update content search example to demonstrate query and result customization --- .../blocks/content-search-example/edit.tsx | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/example/src/blocks/content-search-example/edit.tsx b/example/src/blocks/content-search-example/edit.tsx index 88770eb7..8328de13 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -1,10 +1,28 @@ -import React from 'react'; import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, Placeholder } from '@wordpress/components'; +import { addQueryArgs } from '@wordpress/url'; import { ContentSearch } from '@10up/block-components'; +/** + * Example search result customization that uses embedded data to display the + * post date. + */ +const renderItemType = ( props ) => { + const { type, subtype, embedded } = props; + const { date } = embedded?.self?.[ 0 ] ?? {}; + const postDate = new Date( Date.parse( date ) ); + + return ( + <> + { subtype ? subtype : type } +
+ { postDate.toLocaleDateString() } + + ); +}; + export const BlockEdit = (props) => { const { attributes: {selectedPost}, @@ -17,34 +35,45 @@ export const BlockEdit = (props) => { const blockProps = useBlockProps(); + /** + * Example query string filter that returns results in reverse chronological + * order. + */ + const queryFilter = ( query ) => { + return addQueryArgs( query, { + orderby: 'date', + order: 'desc', + } ); + }; + + const ContentSearchControl = () => ( + + ); + return ( <> - +
-
- { - selectedPost && +
+ { selectedPost && (

{__('Selected Post:', 'example')} {selectedPost.title}

- } + ) }
- +
) -} \ No newline at end of file +} From c36c49008818b2149d5b58025c14dfe1e816c7c4 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:33:19 -0500 Subject: [PATCH 04/13] new includeEmbeds prop to include embeds in search response --- components/content-search/index.tsx | 3 +++ components/content-search/types.ts | 1 + components/content-search/utils.ts | 37 ++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/components/content-search/index.tsx b/components/content-search/index.tsx index bedea0d8..c6234bf7 100644 --- a/components/content-search/index.tsx +++ b/components/content-search/index.tsx @@ -79,6 +79,7 @@ export interface ContentSearchProps { mode?: ContentSearchMode; perPage?: number; queryFilter?: QueryFilter; + includeEmbeds?: boolean; excludeItems?: Array; renderItemType?: (props: NormalizedSuggestion) => string; renderItem?: (props: RenderItemComponentProps) => JSX.Element; @@ -103,6 +104,7 @@ const ContentSearch: React.FC = ({ mode = 'post', perPage = 20, queryFilter = (query: string) => query, + includeEmbeds = false, excludeItems = [], renderItemType = undefined, renderItem: SearchResultItem = SearchItem, @@ -138,6 +140,7 @@ const ContentSearch: React.FC = ({ perPage, contentTypes, queryFilter, + includeEmbeds, excludeItems, signal, }), diff --git a/components/content-search/types.ts b/components/content-search/types.ts index 30421aca..58842c03 100644 --- a/components/content-search/types.ts +++ b/components/content-search/types.ts @@ -20,6 +20,7 @@ export interface QueryArgs { contentTypes: Array; mode: ContentSearchMode; keyword: string; + includeEmbeds?: boolean; } export type QueryFilter = (query: string, args: QueryArgs) => string; diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index e2037132..2b92f32f 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -32,6 +32,7 @@ interface PrepareSearchQueryArgs { perPage: number; contentTypes: Array; queryFilter: QueryFilter; + includeEmbeds?: boolean; } /* @@ -44,6 +45,7 @@ export const prepareSearchQuery = ({ perPage, contentTypes, queryFilter, + includeEmbeds = false, }: PrepareSearchQueryArgs): string => { let searchQuery; @@ -51,7 +53,16 @@ export const prepareSearchQuery = ({ case 'user': searchQuery = addQueryArgs('wp/v2/users', { search: keyword, - _fields: ['id', 'link', 'url', 'type', 'name', 'subtype', '_links', '_embedded'], + ...(includeEmbeds ? { _embed: true } : {}), + _fields: [ + 'id', + 'link', + 'url', + 'type', + 'name', + 'subtype', + ...(includeEmbeds ? ['_links', '_embedded'] : []), + ], }); break; default: @@ -59,10 +70,18 @@ export const prepareSearchQuery = ({ search: keyword, subtype: contentTypes.join(','), type: mode, - _embed: true, per_page: perPage, page, - _fields: ['id', 'link', 'url', 'type', 'title', 'subtype', '_links', '_embedded'], + ...(includeEmbeds ? { _embed: true } : {}), + _fields: [ + 'id', + 'link', + 'url', + 'type', + 'title', + 'subtype', + ...(includeEmbeds ? ['_links', '_embedded'] : []), + ], }); break; @@ -74,6 +93,7 @@ export const prepareSearchQuery = ({ contentTypes, mode, keyword, + includeEmbeds, }); }; @@ -81,6 +101,7 @@ interface NormalizeResultsArgs { mode: ContentSearchMode; results: WP_REST_API_Search_Result[] | WP_REST_API_User[]; excludeItems: Array; + includeEmbeds?: boolean; } /* @@ -91,6 +112,7 @@ export const normalizeResults = ({ mode, results, excludeItems, + includeEmbeds = false, }: NormalizeResultsArgs): Array<{ id: number; subtype: ContentSearchMode | string; @@ -110,7 +132,7 @@ export const normalizeResults = ({ title: userItem.name, type: mode, url: userItem.link, - embedded: userItem._embedded, + ...(includeEmbeds ? { embedded: userItem._embedded } : {}), }; default: const searchItem = item as WP_REST_API_Search_Result; @@ -120,7 +142,7 @@ export const normalizeResults = ({ title: searchItem.title, type: searchItem.type, url: searchItem.url, - embedded: searchItem._embedded, + ...(includeEmbeds ? { embedded: searchItem._embedded } : {}), }; } }); @@ -136,6 +158,7 @@ interface FetchSearchResultsArgs { perPage: number; contentTypes: Array; queryFilter: QueryFilter; + includeEmbeds?: boolean; excludeItems: Array; signal?: AbortSignal; } @@ -147,6 +170,7 @@ export async function fetchSearchResults({ perPage, contentTypes, queryFilter, + includeEmbeds, excludeItems, signal, }: FetchSearchResultsArgs) { @@ -157,6 +181,7 @@ export async function fetchSearchResults({ perPage, contentTypes, queryFilter, + includeEmbeds, }); const response = await apiFetch({ path: searchQueryString, @@ -180,7 +205,7 @@ export async function fetchSearchResults({ break; } - const normalizedResults = normalizeResults({ results, excludeItems, mode }); + const normalizedResults = normalizeResults({ results, excludeItems, mode, includeEmbeds }); const hasNextPage = totalPages > page; const hasPreviousPage = page > 1; From 4cbe2b34006ab8c49d36d60440c29dded1bb8451 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:33:31 -0500 Subject: [PATCH 05/13] use includeEmbed prop in example --- example/src/blocks/content-search-example/edit.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/example/src/blocks/content-search-example/edit.tsx b/example/src/blocks/content-search-example/edit.tsx index 8328de13..a91fabae 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -52,6 +52,7 @@ export const BlockEdit = (props) => { contentTypes={['page', 'post']} onSelectItem={handlePostSelection} queryFilter={queryFilter} + includeEmbeds renderItemType={renderItemType} fetchInitialResults /> From f8ab6151820af065fd8dcd71d8ea80ba09a67e52 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:40:14 -0500 Subject: [PATCH 06/13] update includeEmbeds arg to support string and array types, inherit same type everywhere --- components/content-search/index.tsx | 3 ++- components/content-search/types.ts | 2 +- components/content-search/utils.ts | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/content-search/index.tsx b/components/content-search/index.tsx index c6234bf7..65cb10da 100644 --- a/components/content-search/index.tsx +++ b/components/content-search/index.tsx @@ -9,6 +9,7 @@ import { StyledComponentContext } from '../styled-components-context'; import type { ContentSearchMode, IdentifiableObject, + QueryArgs, QueryFilter, RenderItemComponentProps, } from './types'; @@ -79,7 +80,7 @@ export interface ContentSearchProps { mode?: ContentSearchMode; perPage?: number; queryFilter?: QueryFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; excludeItems?: Array; renderItemType?: (props: NormalizedSuggestion) => string; renderItem?: (props: RenderItemComponentProps) => JSX.Element; diff --git a/components/content-search/types.ts b/components/content-search/types.ts index 58842c03..400c7659 100644 --- a/components/content-search/types.ts +++ b/components/content-search/types.ts @@ -20,7 +20,7 @@ export interface QueryArgs { contentTypes: Array; mode: ContentSearchMode; keyword: string; - includeEmbeds?: boolean; + includeEmbeds?: boolean | string | Array; } export type QueryFilter = (query: string, args: QueryArgs) => string; diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index 2b92f32f..9b07bab3 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -2,7 +2,7 @@ import type { WP_REST_API_User, WP_REST_API_Search_Result } from 'wp-types'; import apiFetch from '@wordpress/api-fetch'; import { addQueryArgs } from '@wordpress/url'; -import type { ContentSearchMode, QueryFilter } from './types'; +import type { ContentSearchMode, QueryArgs, QueryFilter } from './types'; interface IdentifiableObject extends Object { id: number; @@ -32,7 +32,7 @@ interface PrepareSearchQueryArgs { perPage: number; contentTypes: Array; queryFilter: QueryFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; } /* @@ -53,7 +53,7 @@ export const prepareSearchQuery = ({ case 'user': searchQuery = addQueryArgs('wp/v2/users', { search: keyword, - ...(includeEmbeds ? { _embed: true } : {}), + ...(includeEmbeds ? { _embed: includeEmbeds } : {}), _fields: [ 'id', 'link', @@ -72,7 +72,7 @@ export const prepareSearchQuery = ({ type: mode, per_page: perPage, page, - ...(includeEmbeds ? { _embed: true } : {}), + ...(includeEmbeds ? { _embed: includeEmbeds } : {}), _fields: [ 'id', 'link', @@ -101,7 +101,7 @@ interface NormalizeResultsArgs { mode: ContentSearchMode; results: WP_REST_API_Search_Result[] | WP_REST_API_User[]; excludeItems: Array; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; } /* @@ -158,7 +158,7 @@ interface FetchSearchResultsArgs { perPage: number; contentTypes: Array; queryFilter: QueryFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; excludeItems: Array; signal?: AbortSignal; } From 181dfb69a3ec4be439dbf31bc6a6feb8d06a3c17 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:40:33 -0500 Subject: [PATCH 07/13] update example --- example/src/blocks/content-search-example/edit.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/src/blocks/content-search-example/edit.tsx b/example/src/blocks/content-search-example/edit.tsx index a91fabae..63d634e8 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -52,7 +52,7 @@ export const BlockEdit = (props) => { contentTypes={['page', 'post']} onSelectItem={handlePostSelection} queryFilter={queryFilter} - includeEmbeds + includeEmbeds="self" renderItemType={renderItemType} fetchInitialResults /> From c98a9c9a1ab994d580a7f9ec79cb53bc8e1e0346 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:51:57 -0500 Subject: [PATCH 08/13] add includeEmbed prop to ContentPicker --- components/content-picker/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/content-picker/index.tsx b/components/content-picker/index.tsx index 47c10860..c58c3031 100644 --- a/components/content-picker/index.tsx +++ b/components/content-picker/index.tsx @@ -8,7 +8,12 @@ import { ContentSearch } from '../content-search'; import SortableList from './SortableList'; import { StyledComponentContext } from '../styled-components-context'; import { defaultRenderItemType } from '../content-search/SearchItem'; -import { ContentSearchMode, QueryFilter, RenderItemComponentProps } from '../content-search/types'; +import { + ContentSearchMode, + QueryArgs, + QueryFilter, + RenderItemComponentProps, +} from '../content-search/types'; import { NormalizedSuggestion } from '../content-search/utils'; import { PickedItemType } from './PickedItem'; @@ -48,6 +53,7 @@ export interface ContentPickerProps { placeholder?: string; onPickChange?: (ids: any[]) => void; queryFilter?: QueryFilter; + includeEmbeds?: QueryArgs['includeEmbeds']; maxContentItems?: number; isOrderable?: boolean; singlePickedLabel?: string; @@ -73,6 +79,7 @@ export const ContentPicker: React.FC = ({ console.log('Content picker list change', ids); // eslint-disable-line no-console }, queryFilter = undefined, + includeEmbeds, maxContentItems = 1, isOrderable = false, singlePickedLabel = __('You have selected the following item:', '10up-block-components'), @@ -152,6 +159,7 @@ export const ContentPicker: React.FC = ({ contentTypes={contentTypes} mode={mode} queryFilter={queryFilter} + includeEmbeds={includeEmbeds} perPage={perPage} fetchInitialResults={fetchInitialResults} renderItemType={renderItemType} From 8fb782fc2ae117a23de16cbc7cfd96aef8329658 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 07:52:49 -0500 Subject: [PATCH 09/13] update ContentPicker exmple --- .../blocks/content-picker-example/edit.tsx | 65 ++++++++++++++----- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/example/src/blocks/content-picker-example/edit.tsx b/example/src/blocks/content-picker-example/edit.tsx index 2d8ad48d..986b50ff 100644 --- a/example/src/blocks/content-picker-example/edit.tsx +++ b/example/src/blocks/content-picker-example/edit.tsx @@ -1,10 +1,28 @@ -import React from 'react'; import { __ } from '@wordpress/i18n'; import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { PanelBody, Placeholder } from '@wordpress/components'; +import { addQueryArgs } from '@wordpress/url'; import { ContentPicker } from '@10up/block-components'; +/** + * Example search result customization that uses embedded data to display the + * post date. + */ +const renderItemType = ( props ) => { + const { type, subtype, embedded } = props; + const { date } = embedded?.self?.[ 0 ] ?? {}; + const postDate = new Date( Date.parse( date ) ); + + return ( + <> + { subtype ? subtype : type } +
+ { postDate.toLocaleDateString() } + + ); +}; + export const BlockEdit = (props) => { const { attributes: {selectedPosts}, @@ -17,32 +35,43 @@ export const BlockEdit = (props) => { const blockProps = useBlockProps(); + /** + * Example query string filter that returns results in reverse chronological + * order. + */ + const queryFilter = ( query ) => { + return addQueryArgs( query, { + orderby: 'date', + order: 'desc', + } ); + }; + + const ContentPickerControl = () => ( + + ); + return ( <> - +
- +
) -} \ No newline at end of file +} From 0c58e21a81e98624929e65b1737c1329a57cef29 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 08:01:13 -0500 Subject: [PATCH 10/13] update content search readme props --- components/content-search/readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/content-search/readme.md b/components/content-search/readme.md index 03fbd192..5d622d1c 100644 --- a/components/content-search/readme.md +++ b/components/content-search/readme.md @@ -26,6 +26,7 @@ function MyComponent( props ) { |-----------------------|------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------------| | `onSelectItem` | `function` | `undefined` | Function called when a searched item is clicked | | `queryFilter` | `function` | `(query, parametersObject) => query` | Function called to allow you to customize the query before it's made. It's advisable to use `useCallback` to save this parameter | +| `includeEmbeds` | `bool, string, array` | `undefined` | Whether to include embedded items in the search results. A string or array of strings can be passed to specify the specific embeds. | | `label` | `string` | `''` | Renders a label for the Search Field. | `hideLabelFromVision` | `bool` | `true` | Whether to hide the label | | `mode` | `string` | `'post'` | One of: `post`, `user`, `term` | @@ -34,5 +35,6 @@ function MyComponent( props ) { | `excludeItems` | `array` | `[ { id: 1, type: 'post' ]` | Items to exclude from search | | `perPage` | `number` | `50` | Number of items to show during search | | `renderItemType` | `function` | `undefined` | Function called to override the item type label in `SearchItem`. Must return the new label. | +| `renderItem` | `function` | `undefined` | Function called to override the entire item in `SearchItem`. Must return a React component. | | `fetchInitialResults` | `bool` | `false` | Fetch initial results to present when focusing the search input | | `options.inputDelay` | `number` | `undefined` | Debounce delay passed to the internal search input, defaults to 350ms | From dd50c9f47f8be0599e59a1d74eab93bf4e0ace24 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 08:19:30 -0500 Subject: [PATCH 11/13] search result customization explanation in readme --- components/content-search/readme.md | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/components/content-search/readme.md b/components/content-search/readme.md index 5d622d1c..f636540d 100644 --- a/components/content-search/readme.md +++ b/components/content-search/readme.md @@ -38,3 +38,33 @@ function MyComponent( props ) { | `renderItem` | `function` | `undefined` | Function called to override the entire item in `SearchItem`. Must return a React component. | | `fetchInitialResults` | `bool` | `false` | Fetch initial results to present when focusing the search input | | `options.inputDelay` | `number` | `undefined` | Debounce delay passed to the internal search input, defaults to 350ms | + +## Search Result Item Customization + +There are a number of vectors for customizing how search results are rendered. You can customize the item type label (e.g. "Post", "Page", "Category") by passing a function to the `renderItemType` prop. This function returns a string and receives a single `suggestion` argument, an object with the following shape: + +```js +{ + id: number; + subtype: string; + title: string; + type: string; + url: string; + embedded?: object; +} +``` + +You can also customize the entire item by passing a function to the `renderItem` prop. This function should be a React component that receives these props: + +```js +{ + item: object; // The suggestion object (see above). + onSelect: () => void; + searchTerm: string; + id: string; + contentTypes: string[]; + renderType: ( suggestion: object ) => string; +} +``` + +You may need more than the default suggestion fields to render your custom item. The search endpoint is limited (by design) in what fields it returns, but you can use the linking & embedding functionality of the REST API to include the entire post object (or term, or user) in the response via the `embedded` prop. To do this, pass the `includeEmbeds` prop, which can be a boolean (to include all embeds), a string (to include a single embed type), or an array of strings (to include multiple embed types). This is useful if you want to display additional information about a post, such as its publication date. See the [content search example](example/src/blocks/content-search-example/edit.tsx) for a demonstration of this in action. From 9c1a65de819b7cbbc26f09eaf7507d4fe39bf7b9 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 08:56:20 -0500 Subject: [PATCH 12/13] use time tag for dates --- example/src/blocks/content-picker-example/edit.tsx | 2 +- example/src/blocks/content-search-example/edit.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/blocks/content-picker-example/edit.tsx b/example/src/blocks/content-picker-example/edit.tsx index 986b50ff..5e66e11a 100644 --- a/example/src/blocks/content-picker-example/edit.tsx +++ b/example/src/blocks/content-picker-example/edit.tsx @@ -18,7 +18,7 @@ const renderItemType = ( props ) => { <> { subtype ? subtype : type }
- { postDate.toLocaleDateString() } + ); }; diff --git a/example/src/blocks/content-search-example/edit.tsx b/example/src/blocks/content-search-example/edit.tsx index 63d634e8..33aef1fc 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -18,7 +18,7 @@ const renderItemType = ( props ) => { <> { subtype ? subtype : type }
- { postDate.toLocaleDateString() } + ); }; From c30440db56d82345e2dbc6dc5077b5a4ba2f7ab8 Mon Sep 17 00:00:00 2001 From: Cory Hughart Date: Tue, 16 Sep 2025 09:04:43 -0500 Subject: [PATCH 13/13] update integration tests --- cypress/integration/ContentPicker.spec.js | 14 ++++++++++++-- cypress/integration/ContentSearch.spec.js | 12 +++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cypress/integration/ContentPicker.spec.js b/cypress/integration/ContentPicker.spec.js index 8e1040bd..8f15d9f2 100644 --- a/cypress/integration/ContentPicker.spec.js +++ b/cypress/integration/ContentPicker.spec.js @@ -13,8 +13,18 @@ context('ContentPicker', () => { it('allows the user to see results when on focus', () => { cy.createPost({title: 'Post Picker'}); - cy.insertBlock('Hello World'); - cy.get('.wp-block-example-hello-world .components-text-control__input').focus(); + cy.insertBlock('Content Picker'); + cy.get('.wp-block-example-content-picker .components-input-control__input').focus(); cy.get('.tenup-content-search-list').should('exist'); }) + + it('displays the post date in the search results', () => { + cy.createPost({title: 'Post Picker with Post Date'}); + cy.insertBlock('Content Picker'); + cy.get('.wp-block-example-content-picker .components-input-control__input').focus(); + cy.get('.tenup-content-search-list .tenup-content-search-list-item time').invoke('attr', 'datetime').then((datetime) => { + const date = new Date(datetime); + expect(date.toString()).to.not.equal('Invalid Date'); + }); + }) }) diff --git a/cypress/integration/ContentSearch.spec.js b/cypress/integration/ContentSearch.spec.js index 5ff4d389..f5978388 100644 --- a/cypress/integration/ContentSearch.spec.js +++ b/cypress/integration/ContentSearch.spec.js @@ -14,7 +14,17 @@ context('ContentSearch', () => { it('allows the user to see initial results on focus', () => { cy.createPost({title: 'Post Searcher with fetchOnFocus'}); cy.insertBlock('Post Searcher'); - cy.get('.wp-block-example-content-search .components-text-control__input').focus(); + cy.get('.wp-block-example-content-search .components-input-control__input').focus(); cy.get('.tenup-content-search-list').should('exist'); }) + + it('displays the post date in the search results', () => { + cy.createPost({title: 'Post Searcher with Post Date'}); + cy.insertBlock('Post Searcher'); + cy.get('.wp-block-example-content-search .components-input-control__input').focus(); + cy.get('.tenup-content-search-list .tenup-content-search-list-item time').invoke('attr', 'datetime').then((datetime) => { + const date = new Date(datetime); + expect(date.toString()).to.not.equal('Invalid Date'); + }); + }) })