diff --git a/mailpoet/tests/acceptance/EmailEditor/EmailTemplatesCest.php b/mailpoet/tests/acceptance/EmailEditor/EmailTemplatesCest.php index 6d93895662..ae17562002 100644 --- a/mailpoet/tests/acceptance/EmailEditor/EmailTemplatesCest.php +++ b/mailpoet/tests/acceptance/EmailEditor/EmailTemplatesCest.php @@ -98,8 +98,8 @@ class EmailTemplatesCest { $i->waitForElementClickable('.email-editor-start_from_scratch_button'); $i->click('[aria-label="Basic"]'); $i->waitForElement('.block-editor-block-patterns-list__item-title'); - $i->waitForText($template); - $i->click("//div[@class='block-editor-block-patterns-list__item-title' and text()='$template']"); + $i->waitForText($template, 5); + $i->click("//h4[@class='block-editor-block-patterns-list__item-title' and text()='$template']"); } private function checkTextIsInEmail(\AcceptanceTester $i, string $text): void { diff --git a/packages/js/email-editor/src/components/template-select/select-modal.tsx b/packages/js/email-editor/src/components/template-select/select-modal.tsx index 6d32083c7d..c3e091a1e0 100644 --- a/packages/js/email-editor/src/components/template-select/select-modal.tsx +++ b/packages/js/email-editor/src/components/template-select/select-modal.tsx @@ -32,13 +32,15 @@ function SelectTemplateBody( { handleTemplateSelection, } ) { const [ selectedCategory, setSelectedCategory ] = useState( - TemplateCategories[ 0 ].name // Show the “Recent” category by default + TemplateCategories[ 1 ].name // Show the “Basic” category by default ); useEffect( () => { - if ( ! hasEmailPosts ) { - setSelectedCategory( TemplateCategories[ 1 ].name ); - } + setTimeout( () => { + if ( hasEmailPosts ) { + setSelectedCategory( TemplateCategories[ 0 ].name ); + } + }, 1000 ); // using setTimeout to ensure the template styles are available before block preview }, [ hasEmailPosts ] ); return ( diff --git a/packages/js/email-editor/src/store/selectors.ts b/packages/js/email-editor/src/store/selectors.ts index c2a1f1bfc0..0bef3acac5 100644 --- a/packages/js/email-editor/src/store/selectors.ts +++ b/packages/js/email-editor/src/store/selectors.ts @@ -148,7 +148,7 @@ export const getSentEmailEditorPosts = createRegistrySelector( } ) ?.filter( ( post: EmailEditorPostType ) => post?.content?.raw !== '' // filter out empty content - ) + ) || [] ); /**