Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom template creation regression #50797

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function AddCustomGenericTemplateModalContent( { onClose, createTemplate } ) {
placeholder={ defaultTitle }
disabled={ isBusy }
help={ __(
'Describe the template, e.g. "Post with sidebar".'
'Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to match the post editor's modal.

) }
/>
<HStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ export default function NewTemplate( {
const [ modalContent, setModalContent ] = useState(
modalContentMap.templatesList
);
const [
showCustomGenericTemplateModal,
setShowCustomGenericTemplateModal,
] = useState( false );
const [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );
const [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );

Expand Down Expand Up @@ -183,7 +179,7 @@ export default function NewTemplate( {
__( 'Add template: %s' ),
entityForSuggestions.labels.singular_name
);
} else if ( showCustomGenericTemplateModal ) {
} else if ( modalContent === modalContentMap.customGenericTemplate ) {
modalTitle = __( 'Create custom template' );
}
return (
Expand Down Expand Up @@ -246,7 +242,9 @@ export default function NewTemplate( {
'A custom template can be manually applied to any post or page.'
) }
onClick={ () =>
setShowCustomGenericTemplateModal( true )
setModalContent(
modalContentMap.customGenericTemplate
)
}
/>
</Grid>
Expand Down
6 changes: 0 additions & 6 deletions packages/edit-site/src/components/add-new-template/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@
}

.edit-site-custom-generic-template__modal {
.components-base-control {
@include break-medium() {
width: $grid-unit * 40;
}
}

.components-modal__header {
border-bottom: none;
}
Expand Down
43 changes: 43 additions & 0 deletions test/e2e/specs/site-editor/templates.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Templates', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );
test.afterEach( async ( { requestUtils } ) => {
await requestUtils.deleteAllTemplates( 'wp_template' );
} );
test( 'Create a custom template', async ( { admin, page } ) => {
const templateName = 'demo';
await admin.visitSiteEditor();
await page.getByRole( 'button', { name: 'Templates' } ).click();
await page.getByRole( 'button', { name: 'Add New Template' } ).click();
await page
.getByRole( 'button', {
name: 'A custom template can be manually applied to any post or page.',
} )
.click();
// Fill the template title and submit.
const newTemplateDialog = page.locator(
'role=dialog[name="Create custom template"i]'
);
const templateNameInput = newTemplateDialog.locator(
'role=textbox[name="Name"i]'
);
await templateNameInput.fill( templateName );
await page.keyboard.press( 'Enter' );
// Close the pattern suggestions dialog.
await page
.getByRole( 'dialog', { name: 'Choose a pattern' } )
.getByRole( 'button', { name: 'Close' } )
.click();
await expect(
page.locator(
`role=button[name="Dismiss this notice"i] >> text="${ templateName }" successfully created.`
)
).toBeVisible();
} );
} );