Skip to content

Commit bfcae35

Browse files
authored
Let user open Settings menu in offline mode (#582)
* Let user open Settings menu in offline mode * Update tests to account for the top bar button behavior change
1 parent c5a02f8 commit bfcae35

2 files changed

Lines changed: 9 additions & 36 deletions

File tree

‎src/components/tests/topbar.test.tsx‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ describe( 'TopBar', () => {
2424
jest.clearAllMocks();
2525
} );
2626
it( 'Test unauthenticated TopBar has the Log in button', async () => {
27-
const user = userEvent.setup();
2827
const authenticate = jest.fn();
2928
( useAuth as jest.Mock ).mockReturnValue( { isAuthenticated: false, authenticate } );
3029
await act( async () => render( <TopBar onToggleSidebar={ jest.fn() } /> ) );
30+
expect( screen.queryByRole( 'button', { name: 'Account' } ) ).not.toBeInTheDocument();
3131
expect( screen.getByRole( 'button', { name: 'Log in' } ) ).toBeVisible();
32-
await user.click( screen.getByRole( 'button', { name: 'Log in' } ) );
33-
expect( authenticate ).toHaveBeenCalledTimes( 1 );
3432
} );
3533

3634
it( 'Test authenticated TopBar does not have the log in button and it has the settings and account buttons', async () => {
@@ -39,15 +37,6 @@ describe( 'TopBar', () => {
3937
expect( screen.queryByRole( 'button', { name: 'Log in' } ) ).not.toBeInTheDocument();
4038
expect( screen.getByRole( 'button', { name: 'Account' } ) ).toBeVisible();
4139
} );
42-
it( 'disables log in button when offline', async () => {
43-
( useOffline as jest.Mock ).mockReturnValue( true );
44-
( useAuth as jest.Mock ).mockReturnValue( { isAuthenticated: false } );
45-
await act( async () => render( <TopBar onToggleSidebar={ jest.fn() } /> ) );
46-
const loginButton = screen.getByRole( 'button', { name: 'Log in' } );
47-
expect( loginButton ).toHaveAttribute( 'aria-disabled', 'true' );
48-
fireEvent.mouseOver( loginButton );
49-
expect( screen.getByRole( 'tooltip', { name: 'You’re currently offline.' } ) ).toBeVisible();
50-
} );
5140

5241
it( 'shows offline indicator', async () => {
5342
( useOffline as jest.Mock ).mockReturnValue( true );

‎src/components/top-bar.tsx‎

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ function OfflineIndicator() {
4848
}
4949

5050
function Authentication() {
51-
const { isAuthenticated, authenticate, user } = useAuth();
52-
const isOffline = useOffline();
53-
const offlineMessage = __( 'You’re currently offline.' );
51+
const { isAuthenticated, user } = useAuth();
5452
if ( isAuthenticated ) {
5553
return (
5654
<Button
@@ -66,29 +64,15 @@ function Authentication() {
6664
}
6765

6866
return (
69-
<Tooltip
70-
disabled={ ! isOffline }
71-
icon={ offlineIcon }
72-
text={ offlineMessage }
73-
placement="right"
74-
className="flex"
67+
<Button
68+
onClick={ () => getIpcApi().showUserSettings() }
69+
aria-label={ __( 'Log in' ) }
70+
className="flex gap-x-2 justify-between w-full text-white rounded !px-0 !py-1 h-auto active:!text-white hover:!text-white hover:underline items-end"
7571
>
76-
<Button
77-
aria-description={ isOffline ? offlineMessage : '' }
78-
aria-disabled={ isOffline }
79-
className="flex gap-x-2 justify-between w-full text-white rounded !px-0 !py-1 h-auto active:!text-white hover:!text-white hover:underline items-end"
80-
onClick={ () => {
81-
if ( isOffline ) {
82-
return;
83-
}
84-
authenticate();
85-
} }
86-
>
87-
<WordPressLogo />
72+
<WordPressLogo />
8873

89-
<div className="text-xs text-right">{ __( 'Log in' ) }</div>
90-
</Button>
91-
</Tooltip>
74+
<div className="text-xs text-right">{ __( 'Log in' ) }</div>
75+
</Button>
9276
);
9377
}
9478

0 commit comments

Comments
 (0)