diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index b8586a36b0d054..25782997c88ced 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -171,6 +171,7 @@ const { isPermalinkEditable, getPermalink, getPermalinkParts, + getEditedPostSlug, isPostSavingLocked, isPostAutosavingLocked, canUserUseUnfilteredHTML, @@ -2904,6 +2905,87 @@ describe( 'selectors', () => { } ); } ); + describe( 'getEditedPostSlug', () => { + it( 'should return the current post’s slug if one exists and has not been edited', () => { + const state = { + currentPost: { + slug: 'custom-slug', + title: 'Sample Post', + }, + editor: { + present: { + edits: {}, + }, + }, + }; + + expect( getEditedPostSlug( state ) ).toBe( 'custom-slug' ); + } ); + + it( 'should return the edited post slug if it has been edited', () => { + const state = { + currentPost: { + slug: 'custom-slug', + title: 'Sample Post', + }, + editor: { + present: { + edits: { + slug: 'edited-slug', + }, + }, + }, + }; + + expect( getEditedPostSlug( state ) ).toBe( 'edited-slug' ); + } ); + + it( 'should return the cleaned title as slug if no saved or edited slug exists', () => { + const state = { + currentPost: { + title: 'Sample Post', + }, + editor: { + present: { + edits: {}, + }, + }, + }; + + expect( getEditedPostSlug( state ) ).toBe( 'sample-post' ); + } ); + + it( 'should return cleaned, edited title as slug if it has been edited and no saved or edited slug exists', () => { + const state = { + currentPost: { + title: 'Sample Post', + }, + editor: { + present: { + edits: { + title: 'Edited Title', + }, + }, + }, + }; + + expect( getEditedPostSlug( state ) ).toBe( 'edited-title' ); + } ); + + it( 'should return the post ID if no slug or post title exists', () => { + const state = { + postId: 123, + editor: { + present: { + edits: {}, + }, + }, + }; + + expect( getEditedPostSlug( state ) ).toBe( 123 ); + } ); + } ); + describe( 'canUserUseUnfilteredHTML', () => { it( 'should return true if the _links object contains the property wp:action-unfiltered-html', () => { const state = {