-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Templates: Apply template for new post only (#9288)
* Templates: Apply template for new post only * Testing: Update snapshot name for single template block removal
- Loading branch information
Showing
5 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,56 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { clickOnMoreMenuItem, newPost } from '../support/utils'; | ||
import { | ||
META_KEY, | ||
newPost, | ||
getEditedPostContent, | ||
saveDraft, | ||
pressWithModifier, | ||
} from '../support/utils'; | ||
import { activatePlugin, deactivatePlugin } from '../support/plugins'; | ||
|
||
describe( 'Using a CPT with a predefined template', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'gutenberg-test-plugin-templates' ); | ||
await newPost( { postType: 'book' } ); | ||
} ); | ||
describe( 'templates', () => { | ||
describe( 'Using a CPT with a predefined template', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'gutenberg-test-plugin-templates' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await deactivatePlugin( 'gutenberg-test-plugin-templates' ); | ||
} ); | ||
beforeEach( async () => { | ||
await newPost( { postType: 'book' } ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await deactivatePlugin( 'gutenberg-test-plugin-templates' ); | ||
} ); | ||
|
||
it( 'Should add a custom post types with a predefined template', async () => { | ||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'Should respect user edits to not re-apply template after save (single block removal)', async () => { | ||
// Remove a block from the template to verify that it's not | ||
// re-added after saving and reloading the editor. | ||
await page.click( '.editor-post-title__input' ); | ||
await page.keyboard.press( 'ArrowDown' ); | ||
await page.keyboard.press( 'Backspace' ); | ||
await saveDraft(); | ||
await page.reload(); | ||
|
||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
|
||
it( 'Should add a custom post types with a predefined template', async () => { | ||
//Switch to Code Editor to check HTML output | ||
await clickOnMoreMenuItem( 'Code Editor' ); | ||
it( 'Should respect user edits to not re-apply template after save (full delete)', async () => { | ||
// Remove all blocks from the template to verify that they're not | ||
// re-added after saving and reloading the editor. | ||
await page.type( '.editor-post-title__input', 'My Empty Book' ); | ||
await page.keyboard.press( 'ArrowDown' ); | ||
await pressWithModifier( META_KEY, 'A' ); | ||
await page.keyboard.press( 'Backspace' ); | ||
await saveDraft(); | ||
await page.reload(); | ||
|
||
// Assert that the post already contains the template defined blocks | ||
const textEditorContent = await page.$eval( '.editor-post-text-editor', ( element ) => element.value ); | ||
expect( textEditorContent ).toMatchSnapshot(); | ||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters