-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️(frontend) show username on AccountDropDown
- show username instead of "My account"
- Loading branch information
1 parent
232ea97
commit 74bb43f
Showing
6 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
Submodule secrets
updated
from 2572ba to 49b591
This file contains 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
69 changes: 69 additions & 0 deletions
69
src/frontend/apps/desk/src/features/header/__tests__/AccountDropdown.test.tsx
This file contains 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,69 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import { useAuthStore } from '@/core/auth'; | ||
import { AppWrapper } from '@/tests/utils'; | ||
|
||
import { AccountDropdown } from '../AccountDropdown'; | ||
|
||
jest.mock('@/core/auth', () => ({ | ||
useAuthStore: jest.fn(), | ||
})); | ||
|
||
describe('AccountDropdown', () => { | ||
const mockLogout = jest.fn(); | ||
const mockUserData = { | ||
id: '1', | ||
email: 'test@example.com', | ||
name: 'Test User', | ||
}; | ||
|
||
const renderAccountDropdown = () => | ||
render(<AccountDropdown />, { wrapper: AppWrapper }); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
(useAuthStore as unknown as jest.Mock).mockReturnValue({ | ||
userData: mockUserData, | ||
logout: mockLogout, | ||
}); | ||
}); | ||
|
||
it('renders the user name correctly', async () => { | ||
renderAccountDropdown(); | ||
|
||
expect(await screen.findByText('Test User')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders "No Username" when userData name is missing', () => { | ||
(useAuthStore as unknown as jest.Mock).mockReturnValue({ | ||
userData: { id: '1', email: 'test@example.com' }, // No name property | ||
logout: mockLogout, | ||
}); | ||
renderAccountDropdown(); | ||
expect(screen.getByText('No Username')).toBeInTheDocument(); | ||
}); | ||
|
||
it('opens the dropdown and shows logout button when clicked', async () => { | ||
renderAccountDropdown(); | ||
|
||
const dropButton = await screen.findByText('Test User'); | ||
fireEvent.click(dropButton); | ||
|
||
expect(screen.getByText('Logout')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Logout')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls logout function when logout button is clicked', async () => { | ||
renderAccountDropdown(); | ||
|
||
// Open the dropdown first | ||
const dropButton = await screen.findByText('Test User'); | ||
fireEvent.click(dropButton); | ||
|
||
// Click the logout button | ||
const logoutButton = screen.getByLabelText('Logout'); | ||
fireEvent.click(logoutButton); | ||
|
||
expect(mockLogout).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains 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 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