forked from cardosofelipe/fast-next-template
Refactor i18n integration and update tests for improved localization
- Updated test components (`PasswordResetConfirmForm`, `PasswordChangeForm`) to use i18n keys directly, ensuring accurate validation messages. - Refined translations in `it.json` to standardize format and content. - Replaced text-based labels with localized strings in `PasswordResetRequestForm` and `RegisterForm`. - Introduced `generateLocalizedMetadata` utility and updated layout metadata generation for locale-aware SEO. - Enhanced e2e tests with locale-prefixed routes and updated assertions for consistency. - Added comprehensive i18n documentation (`I18N.md`) for usage, architecture, and testing.
This commit is contained in:
@@ -253,7 +253,7 @@ describe('Header', () => {
|
||||
const avatarButton = screen.getByText('TU').closest('button')!;
|
||||
await user.click(avatarButton);
|
||||
|
||||
const adminLink = await screen.findByRole('menuitem', { name: /admin panel/i });
|
||||
const adminLink = await screen.findByRole('menuitem', { name: /admin/i });
|
||||
expect(adminLink).toHaveAttribute('href', '/admin');
|
||||
});
|
||||
|
||||
@@ -270,7 +270,12 @@ describe('Header', () => {
|
||||
await user.click(avatarButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole('menuitem', { name: /admin panel/i })).not.toBeInTheDocument();
|
||||
// Only check for a link to /admin since "Admin" text might appear in navigation
|
||||
const adminMenuLinks = screen.queryAllByRole('menuitem', { name: /admin/i });
|
||||
const adminLinkInMenu = adminMenuLinks.find(
|
||||
(link) => link.getAttribute('href') === '/admin'
|
||||
);
|
||||
expect(adminLinkInMenu).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -288,7 +293,7 @@ describe('Header', () => {
|
||||
const avatarButton = screen.getByText('TU').closest('button')!;
|
||||
await user.click(avatarButton);
|
||||
|
||||
const logoutButton = await screen.findByRole('menuitem', { name: /log out/i });
|
||||
const logoutButton = await screen.findByRole('menuitem', { name: /logout/i });
|
||||
await user.click(logoutButton);
|
||||
|
||||
expect(mockLogout).toHaveBeenCalledTimes(1);
|
||||
@@ -312,7 +317,8 @@ describe('Header', () => {
|
||||
await user.click(avatarButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Logging out...')).toBeInTheDocument();
|
||||
// i18n key shown as literal when translation isn't found
|
||||
expect(screen.getByText('loggingOut')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -333,7 +339,7 @@ describe('Header', () => {
|
||||
const avatarButton = screen.getByText('TU').closest('button')!;
|
||||
await user.click(avatarButton);
|
||||
|
||||
const logoutButton = await screen.findByRole('menuitem', { name: /logging out/i });
|
||||
const logoutButton = await screen.findByRole('menuitem', { name: /loggingOut/i });
|
||||
expect(logoutButton).toHaveAttribute('data-disabled');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user