-
Notifications
You must be signed in to change notification settings - Fork 86
Fix: Topbar icons display padding in macOS fullscreen #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,80 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import { useFullscreen } from '../../hooks/use-fullscreen'; | ||
| import { isWindowFrameRtl } from '../../lib/is-window-frame-rtl'; | ||
| import MacTitlebar from '../mac-titlebar'; | ||
|
|
||
| jest.mock( '../../hooks/use-fullscreen' ); | ||
| jest.mock( '../../lib/is-window-frame-rtl' ); | ||
|
|
||
| const FULLSCREEN_CLASSES = { | ||
| ltr: 'ltr:pl-4', | ||
| rtl: 'rtl:pr-4', | ||
| } as const; | ||
|
|
||
| const NON_FULLSCREEN_CLASSES = { | ||
| ltr: { | ||
| normal: 'ltr:pl-window-controls-width-mac', | ||
| chrome: 'rtl:pl-window-controls-width-excl-chrome-mac rtl:pr-chrome', | ||
| }, | ||
| rtl: { | ||
| normal: | ||
| 'ltr:pr-window-controls-width-excl-chrome-mac ltr:pl-chrome rtl:pr-window-controls-width-mac rtl:-ml-chrome', | ||
| }, | ||
| } as const; | ||
|
|
||
| describe( 'MacTitlebar', () => { | ||
| beforeEach( () => { | ||
| jest.clearAllMocks(); | ||
| ( useFullscreen as jest.Mock ).mockReturnValue( false ); | ||
| ( isWindowFrameRtl as jest.Mock ).mockReturnValue( false ); | ||
| } ); | ||
|
|
||
| it( 'should render with correct padding in non-fullscreen LTR mode', () => { | ||
| ( useFullscreen as jest.Mock ).mockReturnValue( false ); | ||
| ( isWindowFrameRtl as jest.Mock ).mockReturnValue( false ); | ||
|
|
||
| const { container } = render( <MacTitlebar /> ); | ||
| const titlebar = container.firstChild; | ||
|
|
||
| expect( titlebar ).toHaveClass( NON_FULLSCREEN_CLASSES.ltr.normal ); | ||
| expect( titlebar ).toHaveClass( NON_FULLSCREEN_CLASSES.ltr.chrome ); | ||
| expect( titlebar ).not.toHaveClass( FULLSCREEN_CLASSES.ltr ); | ||
| expect( titlebar ).not.toHaveClass( FULLSCREEN_CLASSES.rtl ); | ||
| } ); | ||
|
|
||
| it( 'should render with correct padding in non-fullscreen RTL mode', () => { | ||
| ( useFullscreen as jest.Mock ).mockReturnValue( false ); | ||
| ( isWindowFrameRtl as jest.Mock ).mockReturnValue( true ); | ||
|
|
||
| const { container } = render( <MacTitlebar /> ); | ||
| const titlebar = container.firstChild; | ||
|
|
||
| expect( titlebar ).toHaveClass( NON_FULLSCREEN_CLASSES.rtl.normal ); | ||
| expect( titlebar ).not.toHaveClass( FULLSCREEN_CLASSES.ltr ); | ||
| expect( titlebar ).not.toHaveClass( FULLSCREEN_CLASSES.rtl ); | ||
| } ); | ||
|
|
||
| it( 'should render with minimal padding in fullscreen mode', () => { | ||
| ( useFullscreen as jest.Mock ).mockReturnValue( true ); | ||
|
|
||
| const { container } = render( <MacTitlebar /> ); | ||
| const titlebar = container.firstChild; | ||
|
|
||
| expect( titlebar ).toHaveClass( FULLSCREEN_CLASSES.ltr ); | ||
| expect( titlebar ).toHaveClass( FULLSCREEN_CLASSES.rtl ); | ||
| expect( titlebar ).not.toHaveClass( NON_FULLSCREEN_CLASSES.ltr.normal ); | ||
| expect( titlebar ).not.toHaveClass( NON_FULLSCREEN_CLASSES.rtl.normal ); | ||
| } ); | ||
|
|
||
| it( 'should render children', () => { | ||
| const { getByText } = render( <MacTitlebar>Test Content</MacTitlebar> ); | ||
| expect( getByText( 'Test Content' ) ).toBeInTheDocument(); | ||
| } ); | ||
|
|
||
| it( 'should apply additional className if provided', () => { | ||
| const { container } = render( <MacTitlebar className="custom-class" /> ); | ||
| const titlebar = container.firstChild; | ||
|
|
||
| expect( titlebar ).toHaveClass( 'custom-class' ); | ||
| } ); | ||
| } ); |
This file contains hidden or 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,78 @@ | ||
| import { renderHook, waitFor } from '@testing-library/react'; | ||
| import { act } from 'react'; | ||
| import { getIpcApi } from '../../lib/get-ipc-api'; | ||
| import { useFullscreen } from '../use-fullscreen'; | ||
| import { useIpcListener } from '../use-ipc-listener'; | ||
|
|
||
| jest.mock( '../../lib/get-ipc-api' ); | ||
| jest.mock( '../use-ipc-listener' ); | ||
|
|
||
| const mockIpcApi = { | ||
| isFullscreen: jest.fn(), | ||
| }; | ||
|
|
||
| ( getIpcApi as jest.Mock ).mockReturnValue( mockIpcApi ); | ||
|
|
||
| describe( 'useFullscreen', () => { | ||
| beforeEach( () => { | ||
| jest.clearAllMocks(); | ||
| } ); | ||
|
|
||
| it( 'should initialize with false and update when isFullscreen resolves', async () => { | ||
| mockIpcApi.isFullscreen.mockResolvedValue( true ); | ||
| const { result } = renderHook( () => useFullscreen() ); | ||
|
|
||
| expect( result.current ).toBe( false ); | ||
|
|
||
| await waitFor( () => { | ||
| expect( mockIpcApi.isFullscreen ).toHaveBeenCalledTimes( 1 ); | ||
| } ); | ||
|
|
||
| expect( result.current ).toBe( true ); | ||
| } ); | ||
|
|
||
| it( 'should update state when receiving window-fullscreen-change event', async () => { | ||
| mockIpcApi.isFullscreen.mockResolvedValue( false ); | ||
| let eventHandler: ( _: unknown, fullscreen: boolean ) => void = () => undefined; | ||
| ( useIpcListener as jest.Mock ).mockImplementation( ( _channel, handler ) => { | ||
| eventHandler = handler; | ||
| } ); | ||
|
|
||
| const { result } = renderHook( () => useFullscreen() ); | ||
|
|
||
| await waitFor( () => { | ||
| expect( mockIpcApi.isFullscreen ).toHaveBeenCalledTimes( 1 ); | ||
| } ); | ||
|
|
||
| await act( async () => { | ||
| eventHandler( null, true ); | ||
| } ); | ||
|
|
||
| expect( result.current ).toBe( true ); | ||
|
|
||
| await act( async () => { | ||
| eventHandler( null, false ); | ||
| } ); | ||
|
|
||
| expect( result.current ).toBe( false ); | ||
| } ); | ||
|
|
||
| it( 'should not update state if component is unmounted', async () => { | ||
| let eventHandler: ( _: unknown, fullscreen: boolean ) => void = () => undefined; | ||
| ( useIpcListener as jest.Mock ).mockImplementation( ( _channel, handler ) => { | ||
| eventHandler = handler; | ||
| } ); | ||
|
|
||
| const { result, unmount } = renderHook( () => useFullscreen() ); | ||
|
|
||
| expect( result.current ).toBe( false ); | ||
|
|
||
| unmount(); | ||
|
|
||
| await act( async () => { | ||
| eventHandler( null, true ); | ||
| } ); | ||
|
|
||
| expect( result.current ).toBe( false ); | ||
| } ); | ||
| } ); | ||
This file contains hidden or 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,27 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { getIpcApi } from '../lib/get-ipc-api'; | ||
| import { useIpcListener } from './use-ipc-listener'; | ||
|
|
||
| export function useFullscreen() { | ||
| const [ isFullscreen, setIsFullscreen ] = useState( false ); | ||
|
|
||
| useEffect( () => { | ||
| let mounted = true; | ||
| getIpcApi() | ||
| .isFullscreen() | ||
| .then( ( fullscreen ) => { | ||
| if ( mounted ) { | ||
| setIsFullscreen( fullscreen ); | ||
| } | ||
| } ); | ||
| return () => { | ||
| mounted = false; | ||
| }; | ||
| }, [] ); | ||
|
|
||
| useIpcListener( 'window-fullscreen-change', ( _, fullscreen: boolean ) => { | ||
| setIsFullscreen( fullscreen ); | ||
| } ); | ||
|
|
||
| return isFullscreen; | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for adding tests!