fix: harden CHRNX editor lifecycle
This commit is contained in:
12 files changed
+512
-95
No files matched your search
@@ -18,6 +18,7 @@ function createWp( topicSlug = 'podcasts' ) {
|
||||
};
|
||||
const wp = {
|
||||
components: { TextControl: 'TextControl', TextareaControl: 'TextareaControl' },
|
||||
i18n: { __: jest.fn( ( text ) => text ) },
|
||||
data: {
|
||||
select: ( store ) => {
|
||||
if ( store === 'core/editor' ) {
|
||||
@@ -55,6 +56,19 @@ describe( 'podcast editor helpers', () => {
|
||||
);
|
||||
} );
|
||||
|
||||
test( 'bounds participant transport to 50 names and 100 Unicode characters each', () => {
|
||||
const helpers = require( modulePath );
|
||||
const longUnicodeName = 'ñ'.repeat( 101 );
|
||||
const lines = [ longUnicodeName ].concat(
|
||||
Array.from( { length: 55 }, ( _value, index ) => `Guest ${ index }` ),
|
||||
);
|
||||
const participants = helpers.participantsFromText( lines.join( '\n' ) );
|
||||
|
||||
expect( participants ).toHaveLength( 50 );
|
||||
expect( Array.from( participants[ 0 ] ) ).toHaveLength( 100 );
|
||||
expect( participants[ 0 ] ).toBe( 'ñ'.repeat( 100 ) );
|
||||
} );
|
||||
|
||||
test( 'updates one meta key while preserving unrelated metadata', () => {
|
||||
const helpers = require( modulePath );
|
||||
const editPost = jest.fn();
|
||||
@@ -93,7 +107,7 @@ describe( 'podcast editor helpers', () => {
|
||||
expect( nonPodcast.registerPlugin.mock.calls[ 0 ][ 1 ].render() ).toBeNull();
|
||||
} );
|
||||
|
||||
test( 'fails closed when required globals or initial editor selector methods are missing', () => {
|
||||
test( 'registers immediately while initial editor selectors are unresolved', () => {
|
||||
const helpers = require( modulePath );
|
||||
expect( helpers.initialize() ).toBe( false );
|
||||
expect( helpers.initialize( {} ) ).toBe( false );
|
||||
@@ -102,8 +116,8 @@ describe( 'podcast editor helpers', () => {
|
||||
const missingEditorMethod = createWp();
|
||||
missingEditorMethod.wp.data.select = () => editorSelector;
|
||||
expect( () => helpers.initialize( missingEditorMethod.wp ) ).not.toThrow();
|
||||
expect( helpers.initialize( missingEditorMethod.wp ) ).toBe( false );
|
||||
expect( missingEditorMethod.registerPlugin ).not.toHaveBeenCalled();
|
||||
expect( helpers.initialize( missingEditorMethod.wp ) ).toBe( true );
|
||||
expect( missingEditorMethod.registerPlugin ).toHaveBeenCalledTimes( 2 );
|
||||
expect( missingEditorMethod.editPost ).not.toHaveBeenCalled();
|
||||
}
|
||||
|
||||
@@ -152,4 +166,18 @@ describe( 'podcast editor helpers', () => {
|
||||
expect( unresolved.registerPlugin.mock.calls[ 0 ][ 1 ].render() ).toBeNull();
|
||||
expect( unresolved.editPost ).not.toHaveBeenCalled();
|
||||
} );
|
||||
|
||||
test( 'localizes podcast controls with the CHRNX text domain', () => {
|
||||
const helpers = require( modulePath );
|
||||
const { wp, registerPlugin } = createWp();
|
||||
wp.i18n.__ = jest.fn( ( text, domain ) => `${ domain }:${ text }` );
|
||||
|
||||
helpers.initialize( wp );
|
||||
const tree = registerPlugin.mock.calls[ 0 ][ 1 ].render();
|
||||
expect( tree.props.title ).toBe( 'chrnx:Podcast episode' );
|
||||
expect( flatten( tree ).find( ( node ) => node.type === 'TextControl' ).props.label ).toBe(
|
||||
'chrnx:Episode number',
|
||||
);
|
||||
expect( wp.i18n.__ ).toHaveBeenCalledWith( 'Podcast episode', 'chrnx' );
|
||||
} );
|
||||
} );
|
||||
Reference in new issue
Block a user