-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1410-Eliminate-avatarId-in-tests-that-use-useAuth-mock (#1416)
* Fixed issue with avatarId in tests using useAuth mock * Bump version to 0.20.6 and update CHANGELOG * Resolve version conflict in CHANGELOG.md and package.json * update version and changelog
- Loading branch information
Showing
16 changed files
with
94 additions
and
31 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { vi } from 'vitest' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen, waitFor, fireEvent } from '../test-utils' | ||
import { TAuthContext, useAuth } from '../../context/AuthProvider' | ||
import { UsersManager } from '../../components/organisms/UsersManager' | ||
|
||
const mockUsers = [ | ||
{ | ||
id: '2', | ||
email: 'user1@example.com', | ||
dni: '12345678', | ||
name: 'User Two', | ||
status: 'ACTIVE', | ||
role: 'user', | ||
createdAt: '2023-01-01T00:00:00Z', | ||
updatedAt: '2023-01-01T00:00:00Z', | ||
}, | ||
] | ||
|
||
vi.mock('/api/v1/users', () => mockUsers) | ||
const queryClient = new QueryClient() | ||
|
||
const renderWithQueryClient = (component: React.ReactNode) => | ||
render( | ||
<QueryClientProvider client={queryClient}>{component}</QueryClientProvider> | ||
) | ||
|
||
beforeEach(() => { | ||
vi.mock('../../context/AuthProvider', async () => { | ||
const actual: Record<number, unknown> = await vi.importActual( | ||
'../../context/AuthProvider' | ||
) | ||
return { | ||
...actual, | ||
useAuth: vi.fn(), | ||
} | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks() | ||
}) | ||
|
||
describe('UsersManager component', () => { | ||
it('does not render for mentor roles', () => { | ||
vi.mocked(useAuth).mockReturnValue({ | ||
user: { | ||
name: 'MentorName', | ||
role: 'MENTOR', | ||
}, | ||
} as TAuthContext) | ||
render(<UsersManager />) | ||
|
||
expect(screen.queryByText('Users Manager')).not.toBeInTheDocument() | ||
expect(screen.queryByText('AccountAdmin')).not.toBeInTheDocument() | ||
}) | ||
|
||
it('renders correctly for admin roles and allows editing', async () => { | ||
vi.mocked(useAuth).mockReturnValue({ | ||
user: { | ||
name: 'AdminName', | ||
role: 'ADMIN', | ||
}, | ||
} as TAuthContext) | ||
queryClient.setQueryData(['users'], mockUsers) | ||
renderWithQueryClient(<UsersManager />) | ||
|
||
expect(screen.getByText("Llista d'usuaris")).toBeInTheDocument() | ||
expect(screen.queryByText('Error fetching users')).toBeNull() | ||
|
||
const user2 = screen.getByText('User Two') | ||
expect(user2).toBeInTheDocument() | ||
|
||
const searchInput = screen.getByPlaceholderText('Introdueix el DNI') | ||
fireEvent.change(searchInput, { target: { value: '12345678' } }) | ||
|
||
const statusButton = screen.getByTestId('status-desactivar') | ||
fireEvent.click(statusButton) | ||
|
||
await waitFor(() => | ||
expect(screen.getByText('Desactivar')).toBeInTheDocument() | ||
) | ||
}) | ||
}) | ||
|
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
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