-
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" - udpate translations and tests
- Loading branch information
1 parent
cc9303b
commit 9bb6036
Showing
5 changed files
with
93 additions
and
20 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
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
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { useAuthStore } from '@/core/auth'; | ||
import { AppWrapper } from '@/tests/utils'; | ||
|
||
import { AccountDropdown } from '../AccountDropdown'; | ||
|
||
describe('AccountDropdown', () => { | ||
const mockLogout = jest.fn(); | ||
|
||
const renderAccountDropdown = () => | ||
render(<AccountDropdown />, { wrapper: AppWrapper }); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
useAuthStore.setState({ | ||
userData: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
}, | ||
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.setState({ | ||
userData: { | ||
id: '1', | ||
email: '[email protected]', | ||
}, | ||
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'); | ||
await userEvent.click(dropButton); | ||
|
||
expect(screen.getByText('Logout')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Logout')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls logout function when logout button is clicked', async () => { | ||
renderAccountDropdown(); | ||
|
||
const dropButton = await screen.findByText('Test User'); | ||
await userEvent.click(dropButton); | ||
|
||
const logoutButton = screen.getByLabelText('Logout'); | ||
await userEvent.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