|
| 1 | +import { renderHook } from '@testing-library/react'; |
| 2 | +import { store as editorStore } from '@wordpress/editor'; |
| 3 | +import { useIsSocialNote } from '../use-is-social-note'; |
| 4 | + |
| 5 | +// Mock the editor store |
| 6 | +jest.mock( '@wordpress/editor', () => ( { |
| 7 | + store: 'core/editor', |
| 8 | +} ) ); |
| 9 | + |
| 10 | +const mockGetCurrentPostType = jest.fn(); |
| 11 | +const mockSelect = jest.fn().mockReturnValue( { getCurrentPostType: mockGetCurrentPostType } ); |
| 12 | + |
| 13 | +jest.mock( '@wordpress/data', () => ( { |
| 14 | + useSelect: jest.fn( fn => fn( mockSelect ) ), |
| 15 | +} ) ); |
| 16 | + |
| 17 | +describe( 'useIsSocialNote', () => { |
| 18 | + beforeEach( () => { |
| 19 | + jest.clearAllMocks(); |
| 20 | + } ); |
| 21 | + |
| 22 | + it( 'should return true when post type is jetpack-social-note', () => { |
| 23 | + mockGetCurrentPostType.mockReturnValue( 'jetpack-social-note' ); |
| 24 | + const { result } = renderHook( () => useIsSocialNote() ); |
| 25 | + |
| 26 | + expect( result.current ).toBe( true ); |
| 27 | + expect( mockSelect ).toHaveBeenCalledWith( editorStore ); |
| 28 | + expect( mockGetCurrentPostType ).toHaveBeenCalled(); |
| 29 | + } ); |
| 30 | + |
| 31 | + it( 'should return false when post type is not jetpack-social-note', () => { |
| 32 | + mockGetCurrentPostType.mockReturnValue( 'post' ); |
| 33 | + const { result } = renderHook( () => useIsSocialNote() ); |
| 34 | + |
| 35 | + expect( result.current ).toBe( false ); |
| 36 | + expect( mockSelect ).toHaveBeenCalledWith( editorStore ); |
| 37 | + expect( mockGetCurrentPostType ).toHaveBeenCalled(); |
| 38 | + } ); |
| 39 | +} ); |
0 commit comments