From c309178cbb731ed98f159e0bb69081cf540bd708 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index b71aaf31..bdc15f9b 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -148,6 +148,7 @@ export const normalizeResults = ({ type: ContentSearchMode | string; url: string; info?: string; + embedded?: WP_REST_API_Search_Result['_embedded'] | WP_REST_API_User['_embedded']; }> => { const filteredResults = filterOutExcludedItems({ results, excludeItems }); return filteredResults.map((item) => { @@ -158,6 +159,7 @@ export const normalizeResults = ({ type: ContentSearchMode | string; url: string; info?: string; + embedded?: WP_REST_API_Search_Result['_embedded'] | WP_REST_API_User['_embedded']; }; switch (mode) { @@ -169,6 +171,7 @@ export const normalizeResults = ({ title: toPlainTextTitle(userItem.name), type: mode, url: userItem.link, + embedded: userItem._embedded, }; break; default: @@ -179,6 +182,7 @@ export const normalizeResults = ({ title: toPlainTextTitle(searchItem.title), type: searchItem.type, url: searchItem.url, + embedded: searchItem._embedded, }; break; } From 69f7e29a3487c4612a1354b593fda370577d6a1c 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/content-search/utils.ts b/components/content-search/utils.ts index bdc15f9b..299917d3 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -78,6 +78,13 @@ export const prepareSearchQuery = ({ fields = queryFieldsFilter(fields, mode); } + if (!fields.includes('_links')) { + fields.push('_links'); + } + if (!fields.includes('_embedded')) { + fields.push('_embedded'); + } + switch (mode) { case 'user': searchQuery = addQueryArgs('wp/v2/users', { From 5b54e2e889cb67ec5eac6c52f91b36cd1f1b082a 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 | 70 +++++++++++++------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/example/src/blocks/content-search-example/edit.tsx b/example/src/blocks/content-search-example/edit.tsx index e8d14a09..56782293 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -3,9 +3,28 @@ import { useCallback } from '@wordpress/element'; 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}, @@ -33,38 +52,47 @@ 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 0c092c45b0a33459110e6b546c315bfe079d6b68 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 | 4 ++++ components/content-search/types.ts | 1 + components/content-search/utils.ts | 37 +++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/components/content-search/index.tsx b/components/content-search/index.tsx index b92b912f..13585458 100644 --- a/components/content-search/index.tsx +++ b/components/content-search/index.tsx @@ -83,6 +83,7 @@ export interface ContentSearchProps { queryFilter?: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; searchResultFilter?: SearchResultFilter; + includeEmbeds?: boolean; excludeItems?: Array; renderItemType?: (props: NormalizedSuggestion) => string; renderItem?: (props: RenderItemComponentProps) => JSX.Element; @@ -109,6 +110,7 @@ const ContentSearch: React.FC = ({ queryFilter = (query: string) => query, queryFieldsFilter, searchResultFilter, + includeEmbeds = false, excludeItems = [], renderItemType = undefined, renderItem: SearchResultItem = SearchItem, @@ -144,6 +146,7 @@ const ContentSearch: React.FC = ({ queryFilter, queryFieldsFilter, searchResultFilter, + includeEmbeds, ], queryFn: async ({ pageParam = 1, signal }) => fetchSearchResults({ @@ -155,6 +158,7 @@ const ContentSearch: React.FC = ({ queryFilter, queryFieldsFilter, searchResultFilter, + includeEmbeds, excludeItems, signal, }), diff --git a/components/content-search/types.ts b/components/content-search/types.ts index 5f8723ba..8bb62fc7 100644 --- a/components/content-search/types.ts +++ b/components/content-search/types.ts @@ -31,6 +31,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 299917d3..0f0f956b 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -50,6 +50,7 @@ interface PrepareSearchQueryArgs { contentTypes: Array; queryFilter: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; + includeEmbeds?: boolean; } /* @@ -63,6 +64,7 @@ export const prepareSearchQuery = ({ contentTypes, queryFilter, queryFieldsFilter, + includeEmbeds = false, }: PrepareSearchQueryArgs): string => { let searchQuery; @@ -78,17 +80,20 @@ export const prepareSearchQuery = ({ fields = queryFieldsFilter(fields, mode); } - if (!fields.includes('_links')) { - fields.push('_links'); - } - if (!fields.includes('_embedded')) { - fields.push('_embedded'); + if (includeEmbeds) { + if (!fields.includes('_links')) { + fields.push('_links'); + } + if (!fields.includes('_embedded')) { + fields.push('_embedded'); + } } switch (mode) { case 'user': searchQuery = addQueryArgs('wp/v2/users', { search: keyword, + ...(includeEmbeds ? { _embed: true } : {}), _fields: fields, }); break; @@ -97,7 +102,7 @@ export const prepareSearchQuery = ({ search: keyword, subtype: contentTypes.join(','), type: mode, - _embed: true, + ...(includeEmbeds ? { _embed: true } : {}), per_page: perPage, page, _fields: fields, @@ -112,6 +117,7 @@ export const prepareSearchQuery = ({ contentTypes, mode, keyword, + includeEmbeds, }); }; @@ -120,6 +126,7 @@ interface NormalizeResultsArgs { results: WP_REST_API_Search_Result[] | WP_REST_API_User[]; excludeItems: Array; searchResultFilter?: SearchResultFilter; + includeEmbeds?: boolean; } /** @@ -136,7 +143,7 @@ export const toPlainTextTitle = (input: string | undefined | null): string => { const doc = new DOMParser().parseFromString(String(input), 'text/html'); const text = doc.body.textContent ?? ''; - return decodeEntities(text).replace(/\u00A0/g, ' ').trim(); + return decodeEntities(text).replace(/ /g, ' ').trim(); }; /* @@ -148,6 +155,7 @@ export const normalizeResults = ({ results, excludeItems, searchResultFilter, + includeEmbeds = false, }: NormalizeResultsArgs): Array<{ id: number; subtype: ContentSearchMode | string; @@ -178,7 +186,7 @@ export const normalizeResults = ({ title: toPlainTextTitle(userItem.name), type: mode, url: userItem.link, - embedded: userItem._embedded, + ...(includeEmbeds ? { embedded: userItem._embedded } : {}), }; break; default: @@ -189,7 +197,7 @@ export const normalizeResults = ({ title: toPlainTextTitle(searchItem.title), type: searchItem.type, url: searchItem.url, - embedded: searchItem._embedded, + ...(includeEmbeds ? { embedded: searchItem._embedded } : {}), }; break; } @@ -214,6 +222,7 @@ interface FetchSearchResultsArgs { queryFilter: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; searchResultFilter?: SearchResultFilter; + includeEmbeds?: boolean; excludeItems: Array; signal?: AbortSignal; } @@ -227,6 +236,7 @@ export async function fetchSearchResults({ queryFilter, queryFieldsFilter, searchResultFilter, + includeEmbeds, excludeItems, signal, }: FetchSearchResultsArgs) { @@ -238,6 +248,7 @@ export async function fetchSearchResults({ contentTypes, queryFilter, queryFieldsFilter, + includeEmbeds, }); const response = await apiFetch({ path: searchQueryString, @@ -261,7 +272,13 @@ export async function fetchSearchResults({ break; } - const normalizedResults = normalizeResults({ results, excludeItems, mode, searchResultFilter }); + const normalizedResults = normalizeResults({ + results, + excludeItems, + mode, + searchResultFilter, + includeEmbeds, + }); const hasNextPage = totalPages > page; const hasPreviousPage = page > 1; From 3f7b464228ba55a86cf6b58dd14a56ce54f35369 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 56782293..aac866b4 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -71,6 +71,7 @@ export const BlockEdit = (props) => { queryFilter={queryFilter} queryFieldsFilter={queryFieldsFilter} searchResultFilter={searchResultFilter} + includeEmbeds renderItemType={renderItemType} fetchInitialResults /> From 6283cc7657c77dbebc7fb124838f7047e0dd9628 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 | 11 ++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/components/content-search/index.tsx b/components/content-search/index.tsx index 13585458..ebabff82 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, QueryFieldsFilter, RenderItemComponentProps, @@ -83,7 +84,7 @@ export interface ContentSearchProps { queryFilter?: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; searchResultFilter?: SearchResultFilter; - 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 8bb62fc7..4c28a455 100644 --- a/components/content-search/types.ts +++ b/components/content-search/types.ts @@ -31,7 +31,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 0f0f956b..2bbdddc4 100644 --- a/components/content-search/utils.ts +++ b/components/content-search/utils.ts @@ -16,6 +16,7 @@ import { decodeEntities } from '@wordpress/html-entities'; */ import type { ContentSearchMode, + QueryArgs, QueryFilter, QueryFieldsFilter, SearchResultFilter, @@ -50,7 +51,7 @@ interface PrepareSearchQueryArgs { contentTypes: Array; queryFilter: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; } /* @@ -93,7 +94,7 @@ export const prepareSearchQuery = ({ case 'user': searchQuery = addQueryArgs('wp/v2/users', { search: keyword, - ...(includeEmbeds ? { _embed: true } : {}), + ...(includeEmbeds ? { _embed: includeEmbeds } : {}), _fields: fields, }); break; @@ -102,7 +103,7 @@ export const prepareSearchQuery = ({ search: keyword, subtype: contentTypes.join(','), type: mode, - ...(includeEmbeds ? { _embed: true } : {}), + ...(includeEmbeds ? { _embed: includeEmbeds } : {}), per_page: perPage, page, _fields: fields, @@ -126,7 +127,7 @@ interface NormalizeResultsArgs { results: WP_REST_API_Search_Result[] | WP_REST_API_User[]; excludeItems: Array; searchResultFilter?: SearchResultFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; } /** @@ -222,7 +223,7 @@ interface FetchSearchResultsArgs { queryFilter: QueryFilter; queryFieldsFilter?: QueryFieldsFilter; searchResultFilter?: SearchResultFilter; - includeEmbeds?: boolean; + includeEmbeds?: QueryArgs['includeEmbeds']; excludeItems: Array; signal?: AbortSignal; } From b10bf23beb2a99d270960d8ed7c8cd4e86e957ca 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 aac866b4..eb44de2b 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -71,7 +71,7 @@ export const BlockEdit = (props) => { queryFilter={queryFilter} queryFieldsFilter={queryFieldsFilter} searchResultFilter={searchResultFilter} - includeEmbeds + includeEmbeds="self" renderItemType={renderItemType} fetchInitialResults /> From 16dfdcb5a1c3db295150ae0b72af2f611b50624a 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/content-picker/index.tsx b/components/content-picker/index.tsx index 2820cd10..f28e8222 100644 --- a/components/content-picker/index.tsx +++ b/components/content-picker/index.tsx @@ -11,6 +11,7 @@ import { StyledComponentContext } from '../styled-components-context'; import { defaultRenderItemType } from '../content-search/SearchItem'; import { ContentSearchMode, + QueryArgs, QueryFilter, QueryFieldsFilter, RenderItemComponentProps, @@ -64,6 +65,7 @@ export interface ContentPickerProps { queryFieldsFilter?: QueryFieldsFilter; searchResultFilter?: SearchResultFilter; pickedItemFilter?: PickedItemFilter; + includeEmbeds?: QueryArgs['includeEmbeds']; maxContentItems?: number; isOrderable?: boolean; singlePickedLabel?: string; @@ -92,6 +94,7 @@ export const ContentPicker: React.FC = ({ queryFieldsFilter, searchResultFilter, pickedItemFilter, + includeEmbeds, maxContentItems = 1, isOrderable = false, singlePickedLabel = __('You have selected the following item:', '10up-block-components'), @@ -173,6 +176,7 @@ export const ContentPicker: React.FC = ({ queryFilter={queryFilter} queryFieldsFilter={queryFieldsFilter} searchResultFilter={searchResultFilter} + includeEmbeds={includeEmbeds} perPage={perPage} fetchInitialResults={fetchInitialResults} renderItemType={renderItemType} From cc99cd8f0247d628d7e393fecb6892fff6866103 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 | 73 +++++++++++++------ 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/example/src/blocks/content-picker-example/edit.tsx b/example/src/blocks/content-picker-example/edit.tsx index 0b841b7b..f5247469 100644 --- a/example/src/blocks/content-picker-example/edit.tsx +++ b/example/src/blocks/content-picker-example/edit.tsx @@ -3,9 +3,28 @@ import { useCallback } from '@wordpress/element'; 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}, @@ -35,38 +54,46 @@ 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 d329647e8cc28d54212fd3526045f6451d8bdec3 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/components/content-search/readme.md b/components/content-search/readme.md index 028f816b..85c4920a 100644 --- a/components/content-search/readme.md +++ b/components/content-search/readme.md @@ -67,6 +67,7 @@ function MyComponent( props ) { | `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 | | `queryFieldsFilter` | `function` | `undefined` | Function to customize which fields are fetched from the API. Receives `(fields: string[], mode: ContentSearchMode) => string[]`. It's advisable to use `useCallback` to save this parameter. | | `searchResultFilter` | `function` | `undefined` | Function to customize the normalized search result item. Receives `(item: NormalizedSuggestion, originalResult: WP_REST_API_Search_Result \| WP_REST_API_User) => NormalizedSuggestion`. 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` | From 75b75f799b29ebcd24d9b7b3e4cde8e385806322 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 85c4920a..9527e9bc 100644 --- a/components/content-search/readme.md +++ b/components/content-search/readme.md @@ -79,3 +79,33 @@ function MyComponent( props ) { | `renderItem` | `function` | `undefined` | Function to customize the rendering of each search result item. Receives `RenderItemComponentProps` and must return a JSX element. | | `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 e953d164eeb08543c3983099ac86cde4cbe31058 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 f5247469..ffba8a5e 100644 --- a/example/src/blocks/content-picker-example/edit.tsx +++ b/example/src/blocks/content-picker-example/edit.tsx @@ -20,7 +20,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 eb44de2b..599dcdbc 100644 --- a/example/src/blocks/content-search-example/edit.tsx +++ b/example/src/blocks/content-search-example/edit.tsx @@ -20,7 +20,7 @@ const renderItemType = ( props ) => { <> { subtype ? subtype : type }
- { postDate.toLocaleDateString() } + ); }; From c07eb7e1d0536cccfbb785cfaee558906e46c6bf 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'); + }); + }) })