Skip to content

Commit

Permalink
udpdate tests with the new call for dfm pref and add two tests for wh…
Browse files Browse the repository at this point in the history
…en dfm is on
  • Loading branch information
draganescu committed Feb 15, 2024
1 parent 9565014 commit 9dcdf4d
Showing 1 changed file with 40 additions and 0 deletions.
Expand Up @@ -44,6 +44,12 @@ describe( 'listener hook tests', () => {
isViewportMatch: jest.fn(),
},
},
'core/preferences': {
...storeConfig,
selectors: {
get: jest.fn(),
},
},
[ STORE_NAME ]: {
...storeConfig,
actions: {
Expand Down Expand Up @@ -112,6 +118,7 @@ describe( 'listener hook tests', () => {
'getBlockSelectionStart',
true
);
setMockReturnValue( 'core/preferences', 'get', false );

render( <TestedOutput /> );

Expand All @@ -120,19 +127,52 @@ describe( 'listener hook tests', () => {
).toHaveBeenCalledWith( 'edit-post/block' );
} );
it( 'opens document sidebar if block is not selected', () => {
setMockReturnValue( STORE_NAME, 'isEditorSidebarOpened', true );
setMockReturnValue( STORE_NAME, 'isEditorSidebarOpened', true );
setMockReturnValue(
'core/block-editor',
'getBlockSelectionStart',
false
);
setMockReturnValue( 'core/preferences', 'get', false );

render( <TestedOutput /> );

expect(
getSpyedAction( STORE_NAME, 'openGeneralSidebar' )
).toHaveBeenCalledWith( 'edit-post/document' );
} );
it( 'does not open block sidebar if block is selected and distraction free mode is on', () => {
setMockReturnValue( STORE_NAME, 'isEditorSidebarOpened', true );
setMockReturnValue(
'core/block-editor',
'getBlockSelectionStart',
true
);
setMockReturnValue( 'core/preferences', 'get', true );

render( <TestedOutput /> );

expect(
getSpyedAction( STORE_NAME, 'openGeneralSidebar' )
).toHaveBeenCalledTimes( 0 );
} );
it( 'does not open document sidebar if block is not selected and distraction free is on', () => {
setMockReturnValue( STORE_NAME, 'isEditorSidebarOpened', true );
setMockReturnValue( STORE_NAME, 'isEditorSidebarOpened', true );
setMockReturnValue(
'core/block-editor',
'getBlockSelectionStart',
false
);
setMockReturnValue( 'core/preferences', 'get', true );

render( <TestedOutput /> );

expect(
getSpyedAction( STORE_NAME, 'openGeneralSidebar' )
).toHaveBeenCalledTimes( 0 );
} );
} );

describe( 'useUpdatePostLinkListener', () => {
Expand Down

0 comments on commit 9dcdf4d

Please sign in to comment.