-
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.
Template Parts: Add unit tests for template part creation functions (#…
…47224) * Add unit tests for template part creation functions. * Update packages/edit-site/src/utils/test/template-part-create.js Co-authored-by: Robert Anderson <[email protected]> Co-authored-by: Robert Anderson <[email protected]>
- Loading branch information
1 parent
37bb7c5
commit 3b99268
Showing
1 changed file
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
getUniqueTemplatePartTitle, | ||
getCleanTemplatePartSlug, | ||
} from '../template-part-create'; | ||
|
||
describe( 'getUniqueTemplatePartTitle', () => { | ||
it( 'should return the title if it is unique', () => { | ||
const title = 'My Template Part'; | ||
const templateParts = [ | ||
{ | ||
title: { | ||
rendered: 'Template Part With Another Title', | ||
}, | ||
}, | ||
]; | ||
|
||
expect( getUniqueTemplatePartTitle( title, templateParts ) ).toBe( | ||
title | ||
); | ||
} ); | ||
|
||
it( 'should return the title with a suffix if it is not unique', () => { | ||
const title = 'My Template Part'; | ||
const templateParts = [ | ||
{ | ||
title: { | ||
rendered: 'My Template Part', | ||
}, | ||
}, | ||
{ | ||
title: { | ||
rendered: 'My Template Part 2', | ||
}, | ||
}, | ||
]; | ||
|
||
expect( getUniqueTemplatePartTitle( title, templateParts ) ).toBe( | ||
'My Template Part 3' | ||
); | ||
} ); | ||
} ); | ||
|
||
describe( 'getCleanTemplatePartSlug', () => { | ||
it( 'should return a slug with only latin chars', () => { | ||
const title = 'Myɶ Template Partɮ'; | ||
expect( getCleanTemplatePartSlug( title ) ).toBe( 'my-template-part' ); | ||
} ); | ||
|
||
it( 'should return a slug with only latin chars and numbers', () => { | ||
const title = 'My Template Part 2'; | ||
expect( getCleanTemplatePartSlug( title ) ).toBe( | ||
'my-template-part-2' | ||
); | ||
} ); | ||
|
||
it( 'should default the slug to wp-custom-part', () => { | ||
const title = ''; | ||
expect( getCleanTemplatePartSlug( title ) ).toBe( 'wp-custom-part' ); | ||
} ); | ||
} ); |