Skip to content

Commit

Permalink
Add unit tests for getEditedPostSlug selector
Browse files Browse the repository at this point in the history
  • Loading branch information
earnjam committed Mar 18, 2020
1 parent bb2f588 commit bd08f74
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const {
isPermalinkEditable,
getPermalink,
getPermalinkParts,
getEditedPostSlug,
isPostSavingLocked,
isPostAutosavingLocked,
canUserUseUnfilteredHTML,
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit bd08f74

Please sign in to comment.