diff --git a/CHANGELOG.md b/CHANGELOG.md index d1bf34930..58e038a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ and this project adheres to - ✨(domains) add endpoint to list and retrieve domain accesses #404 - 🍱(dev) embark dimail-api as container #366 - ✨(dimail) allow la regie to request a token for another user #416 -- ⚗️(frontend) show username on AccountDropDown #412 ### Changed diff --git a/src/frontend/apps/desk/src/features/header/AccountDropdown.tsx b/src/frontend/apps/desk/src/features/header/AccountDropdown.tsx index 276ac520b..eca93d4f3 100644 --- a/src/frontend/apps/desk/src/features/header/AccountDropdown.tsx +++ b/src/frontend/apps/desk/src/features/header/AccountDropdown.tsx @@ -7,35 +7,32 @@ import { useAuthStore } from '@/core/auth'; export const AccountDropdown = () => { const { t } = useTranslation(); - const { userData, logout } = useAuthStore(); + const { logout } = useAuthStore(); - const userName = userData?.name || t('No Username'); return ( - {userName} + {t('My account')} } > - - - + ); }; diff --git a/src/frontend/apps/desk/src/features/header/__tests__/AccountDropdown.test.tsx b/src/frontend/apps/desk/src/features/header/__tests__/AccountDropdown.test.tsx deleted file mode 100644 index 65bf1149e..000000000 --- a/src/frontend/apps/desk/src/features/header/__tests__/AccountDropdown.test.tsx +++ /dev/null @@ -1,67 +0,0 @@ -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(, { wrapper: AppWrapper }); - - beforeEach(() => { - jest.clearAllMocks(); - useAuthStore.setState({ - userData: { - id: '1', - email: 'test@example.com', - 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: 'test@example.com', - }, - 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); - }); -}); diff --git a/src/frontend/apps/desk/src/i18n/translations.json b/src/frontend/apps/desk/src/i18n/translations.json index 2e17aad41..8acf3f8fd 100644 --- a/src/frontend/apps/desk/src/i18n/translations.json +++ b/src/frontend/apps/desk/src/i18n/translations.json @@ -93,9 +93,9 @@ "Member icon": "Icône de membre", "Member {{name}} added to the team": "Membre {{name}} ajouté au groupe", "More info?": "Plus d'infos ?", + "My account": "Mon compte", "Names": "Noms", "New name...": "Nouveau nom...", - "No Username": "Aucun nom d'utilisateur", "No domains exist.": "Aucun domaine existant.", "No mail box was created with this mail domain.": "Aucune boîte mail n'a été créée avec ce nom de domaine.", "Nothing exceptional, no special privileges related to a .gouv.fr.": "Rien d'exceptionnel, pas de privilèges spéciaux liés à un .gouv.fr.", diff --git a/src/frontend/apps/e2e/__tests__/app-desk/header.spec.ts b/src/frontend/apps/e2e/__tests__/app-desk/header.spec.ts index fce766507..30a407bc0 100644 --- a/src/frontend/apps/e2e/__tests__/app-desk/header.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-desk/header.spec.ts @@ -8,7 +8,7 @@ test.beforeEach(async ({ page, browserName }) => { }); test.describe('Header', () => { - test('checks all the elements are visible', async ({ page, browserName }) => { + test('checks all the elements are visible', async ({ page }) => { const header = page.locator('header').first(); await expect(header.getByAltText('Marianne Logo')).toBeVisible(); @@ -37,15 +37,13 @@ test.describe('Header', () => { ).toBeVisible(); await expect(header.getByRole('combobox').getByText('EN')).toBeVisible(); - await expect( - header.getByText(new RegExp(`E2E ${browserName}`, 'i')), - ).toBeVisible(); + await expect(header.getByText('My account')).toBeVisible(); }); - test('checks logout button', async ({ page, browserName }) => { + test('checks logout button', async ({ page }) => { await page .getByRole('button', { - name: new RegExp(`E2E ${browserName}`, 'i'), + name: 'My account', }) .click();