refactor: drop the featured-project picker in favour of the project list

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-08-15 14:58:19 -05:00
1 parent 7c0eb51dcc
commit 77dc2ee33b
12 files changed
+6 -362

No files matched your search

+1 -1
View File
@@ -557,7 +557,7 @@ const immutableSurfaces = [
'alter-ego-research-768.webp',
'alter-ego-code-768.webp',
],
// Project names come from chrnx/selected-work: picked projects newest-first,
// Project names come from the project list query: picked projects newest-first,
// then the most recent ones. This is the seeded order, not a frozen string.
headings: [ 'Selected work', 'Ailed', 'Expressive Tea', 'Published research' ],
paragraphs: [],
-102
View File
@@ -1,102 +0,0 @@
const modulePath = '../../assets/js/editor-project.js';
function flatten( node ) {
if ( ! node || typeof node !== 'object' ) {
return [];
}
return [ node ].concat( ( node.children || [] ).flatMap( flatten ) );
}
function createWp( topicSlug = 'projects', meta = { unrelated: 'keep' } ) {
const editPost = jest.fn();
const registerPlugin = jest.fn();
const state = { meta, topic: [ 12 ] };
const wp = {
components: { ToggleControl: 'ToggleControl' },
i18n: { __: jest.fn( ( text ) => text ) },
data: {
select: ( store ) => {
if ( store === 'core/editor' ) {
return {
getCurrentPostType: () => 'post',
getEditedPostAttribute: ( key ) => state[ key ],
};
}
return {
getEntityRecord: () => ( topicSlug ? { id: 12, slug: topicSlug } : undefined ),
};
},
dispatch: () => ( { editPost } ),
useDispatch: ( store ) => wp.data.dispatch( store ),
useSelect: ( mapper ) => mapper( wp.data.select ),
},
editPost: { PluginDocumentSettingPanel: 'PluginDocumentSettingPanel' },
element: {
createElement: ( type, props, ...children ) => ( { type, props: props || {}, children } ),
},
plugins: { registerPlugin },
};
return { wp, editPost, registerPlugin };
}
function renderPanel( context ) {
const { initialize } = require( modulePath );
expect( initialize( context.wp ) ).toBe( true );
const [ , plugin ] = context.registerPlugin.mock.calls[ 0 ];
return plugin.render();
}
describe( 'project editor panel', () => {
beforeEach( () => {
jest.resetModules();
} );
test( 'refuses to initialize without the required editor globals', () => {
const { initialize } = require( modulePath );
expect( initialize( undefined ) ).toBe( false );
expect( initialize( {} ) ).toBe( false );
} );
test( 'renders the Selected work toggle only for the projects topic', () => {
const context = createWp( 'projects' );
const toggles = flatten( renderPanel( context ) ).filter(
( node ) => node.type === 'ToggleControl',
);
expect( toggles ).toHaveLength( 1 );
expect( toggles[ 0 ].props.checked ).toBe( false );
} );
test.each( [ 'podcasts', 'code', null ] )( 'renders nothing for the %s topic', ( slug ) => {
expect( renderPanel( createWp( slug ) ) ).toBeNull();
} );
test( 'reflects an existing flag and preserves unrelated meta when toggling', () => {
const context = createWp( 'projects', { unrelated: 'keep', chrnx_project_featured: true } );
const toggle = flatten( renderPanel( context ) ).find(
( node ) => node.type === 'ToggleControl',
);
expect( toggle.props.checked ).toBe( true );
toggle.props.onChange( false );
expect( context.editPost ).toHaveBeenCalledWith( {
meta: { unrelated: 'keep', chrnx_project_featured: false },
} );
} );
test( 'coerces the toggle value to a boolean', () => {
const context = createWp( 'projects' );
const toggle = flatten( renderPanel( context ) ).find(
( node ) => node.type === 'ToggleControl',
);
toggle.props.onChange( 'yes' );
expect( context.editPost ).toHaveBeenCalledWith( {
meta: { unrelated: 'keep', chrnx_project_featured: true },
} );
} );
test( 'updateMeta ignores a missing dispatcher', () => {
const { updateMeta } = require( modulePath );
expect( () => updateMeta( undefined, {}, 'chrnx_project_featured', true ) ).not.toThrow();
} );
} );
+2 -4
View File
@@ -45,7 +45,7 @@ class EditorAssetsTest extends WP_UnitTestCase {
* Clear only the CHRNX editor script state.
*/
private function reset_editor_scripts() {
foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ) as $handle ) {
foreach ( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ) as $handle ) {
wp_dequeue_script( $handle );
wp_deregister_script( $handle );
}
@@ -83,14 +83,13 @@ class EditorAssetsTest extends WP_UnitTestCase {
)
);
$this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-project', 'chrnx-editor-track' ), $handles );
$this->assertSame( array( 'chrnx-editor-taxonomies', 'chrnx-editor-podcast', 'chrnx-editor-track' ), $handles );
$expected_dependencies = array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' );
foreach (
array(
'chrnx-editor-taxonomies' => 'assets/js/editor-taxonomies.js',
'chrnx-editor-podcast' => 'assets/js/editor-podcast.js',
'chrnx-editor-project' => 'assets/js/editor-project.js',
) as $handle => $asset
) {
$this->assertArrayHasKey( $handle, $scripts->registered );
@@ -123,7 +122,6 @@ class EditorAssetsTest extends WP_UnitTestCase {
do_action( 'enqueue_block_editor_assets' );
$this->assertFalse( wp_script_is( 'chrnx-editor-taxonomies', 'enqueued' ) );
$this->assertFalse( wp_script_is( 'chrnx-editor-podcast', 'enqueued' ) );
$this->assertFalse( wp_script_is( 'chrnx-editor-project', 'enqueued' ) );
$this->assertFalse( wp_script_is( 'chrnx-editor-track', 'enqueued' ) );
}
}
+1 -1
View File
@@ -206,7 +206,7 @@ class PatternsTest extends WP_UnitTestCase {
$contracts = array(
'home-projects' => array(
'heading' => 'Selected work',
// The project names come from chrnx/selected-work now, not the pattern.
// The project names come from the project list query now, not the pattern.
'order' => array( 'Selected work' ),
'art' => 'alter-ego-code-768.webp',
'art_alt' => '',