diff --git a/web/wiki/CHANGELOG.md b/web/wiki/CHANGELOG.md index 84d2b226c..ae4085d39 100644 --- a/web/wiki/CHANGELOG.md +++ b/web/wiki/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [0.22.1] - 2024-07-25 + +## Changed + +- Eliminated avatarId in tests that use useAuth mock + ## [0.22.0] - 2024-07-24 ### Deleted @@ -9,7 +15,6 @@ All notable changes to this project will be documented in this file. - Deleted AccountAdmin component and test - Deleted UsersManager component and test - ## [0.21.0] - 2024-06-25 ### Added diff --git a/web/wiki/package.json b/web/wiki/package.json index 407c1b892..6261d522d 100644 --- a/web/wiki/package.json +++ b/web/wiki/package.json @@ -1,7 +1,7 @@ { "name": "web_wiki", "private": true, - "version": "0.22.0", + "version": "0.22.1", "type": "module", "scripts": { "dev": "vite", @@ -61,4 +61,4 @@ "vite": "5.0.13", "vitest": "1.2.2" } -} \ No newline at end of file +} diff --git a/web/wiki/src/__tests__/molecules/FavoritesIcon.test.tsx b/web/wiki/src/__tests__/molecules/FavoritesIcon.test.tsx index bf5633a86..19f3aaeb7 100644 --- a/web/wiki/src/__tests__/molecules/FavoritesIcon.test.tsx +++ b/web/wiki/src/__tests__/molecules/FavoritesIcon.test.tsx @@ -31,7 +31,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'TestName', - avatarId: 'TestAvatar', role: 'REGISTERED', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/molecules/UserButton.test.tsx b/web/wiki/src/__tests__/molecules/UserButton.test.tsx index e92babc14..15dbd4e30 100644 --- a/web/wiki/src/__tests__/molecules/UserButton.test.tsx +++ b/web/wiki/src/__tests__/molecules/UserButton.test.tsx @@ -45,7 +45,6 @@ describe('UserButton', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'User', - avatarId: 'Avatar', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/organisms/CardResource.test.tsx b/web/wiki/src/__tests__/organisms/CardResource.test.tsx index 167277678..da52b863c 100644 --- a/web/wiki/src/__tests__/organisms/CardResource.test.tsx +++ b/web/wiki/src/__tests__/organisms/CardResource.test.tsx @@ -88,7 +88,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Test author name', - avatarId: 'profileAvatar.jpg', }, } as TAuthContext) @@ -111,7 +110,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) @@ -151,7 +149,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Test author name', - avatarId: 'profileAvatar.jpg', }, } as TAuthContext) @@ -182,7 +179,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Test author name', - avatarId: 'profileAvatar.jpg', }, } as TAuthContext) @@ -215,7 +211,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Test author name', - avatarId: 'profileAvatar.jpg', }, } as TAuthContext) @@ -251,7 +246,6 @@ describe('CardResource component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Test author name', - avatarId: 'profileAvatar.jpg', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/organisms/MyFavoritesList.test.tsx b/web/wiki/src/__tests__/organisms/MyFavoritesList.test.tsx index cc4102b13..dc63417b5 100644 --- a/web/wiki/src/__tests__/organisms/MyFavoritesList.test.tsx +++ b/web/wiki/src/__tests__/organisms/MyFavoritesList.test.tsx @@ -19,7 +19,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'TestName', - avatarId: 'TestAvatar', }, } as TAuthContext) vi.mock('react-router-dom', async () => { diff --git a/web/wiki/src/__tests__/organisms/MyResources.test.tsx b/web/wiki/src/__tests__/organisms/MyResources.test.tsx index c1f8c5cdb..60f4e4d75 100644 --- a/web/wiki/src/__tests__/organisms/MyResources.test.tsx +++ b/web/wiki/src/__tests__/organisms/MyResources.test.tsx @@ -19,7 +19,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) vi.mock('react-router-dom', async () => { @@ -96,7 +95,6 @@ describe('MyResources component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/organisms/Navbar.test.tsx b/web/wiki/src/__tests__/organisms/Navbar.test.tsx index 557ec4a6e..b750f3b9a 100644 --- a/web/wiki/src/__tests__/organisms/Navbar.test.tsx +++ b/web/wiki/src/__tests__/organisms/Navbar.test.tsx @@ -27,7 +27,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'TestName', - avatarId: 'TestAvatar', role: 'REGISTERED', }, } as TAuthContext) @@ -185,7 +184,6 @@ describe('Navbar', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'TestName', - avatarId: 'TestAvatar', role: 'MENTOR', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/organisms/SettingsManager.test.tsx b/web/wiki/src/__tests__/organisms/SettingsManager.test.tsx index acecf2aea..eb39c2aab 100644 --- a/web/wiki/src/__tests__/organisms/SettingsManager.test.tsx +++ b/web/wiki/src/__tests__/organisms/SettingsManager.test.tsx @@ -12,7 +12,6 @@ const mockUsers = [ email: 'user1@example.com', dni: '12345678', name: 'User One', - avatarId: 'testAvatar.jpg', itineraryId: 'react', status: 'ACTIVE', role: 'REGISTERED', @@ -41,7 +40,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'AdminName', - avatarId: 'AdminAvatar', role: 'ADMIN', }, } as TAuthContext) @@ -84,7 +82,6 @@ describe('SettingsManager component', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'MentorName', - avatarId: 'MentorAvatar', role: 'MENTOR', }, } as TAuthContext) @@ -105,7 +102,6 @@ describe('User Permissions', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'MentorName', - avatarId: 'MentorAvatar', role: 'MENTOR', }, } as TAuthContext) diff --git a/web/wiki/src/__tests__/organisms/TopicsManagerBoard.test.tsx b/web/wiki/src/__tests__/organisms/TopicsManagerBoard.test.tsx index b9ead31dd..1b7908ec3 100644 --- a/web/wiki/src/__tests__/organisms/TopicsManagerBoard.test.tsx +++ b/web/wiki/src/__tests__/organisms/TopicsManagerBoard.test.tsx @@ -12,13 +12,11 @@ import { server } from '../../__mocks__/server' const userMentor = { name: 'Name', - avatarId: 'Avatar', role: 'MENTOR', } const userStudent = { name: 'Name', - avatarId: 'Avatar', role: 'REGISTERED', } diff --git a/web/wiki/src/__tests__/organisms/UserProfileResourcesWidget.test.tsx b/web/wiki/src/__tests__/organisms/UserProfileResourcesWidget.test.tsx index 7c6d44ca6..a9ea8f667 100644 --- a/web/wiki/src/__tests__/organisms/UserProfileResourcesWidget.test.tsx +++ b/web/wiki/src/__tests__/organisms/UserProfileResourcesWidget.test.tsx @@ -124,7 +124,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) }) diff --git a/web/wiki/src/__tests__/organisms/UsersManager.test.tsx b/web/wiki/src/__tests__/organisms/UsersManager.test.tsx new file mode 100644 index 000000000..e4dc82a30 --- /dev/null +++ b/web/wiki/src/__tests__/organisms/UsersManager.test.tsx @@ -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( + {component} + ) + +beforeEach(() => { + vi.mock('../../context/AuthProvider', async () => { + const actual: Record = 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() + + 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() + + 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() + ) + }) +}) + diff --git a/web/wiki/src/__tests__/organisms/VotesDateController.test.tsx b/web/wiki/src/__tests__/organisms/VotesDateController.test.tsx index 8cd4a71a2..ac32cd5dc 100644 --- a/web/wiki/src/__tests__/organisms/VotesDateController.test.tsx +++ b/web/wiki/src/__tests__/organisms/VotesDateController.test.tsx @@ -20,7 +20,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'TestName', - avatarId: 'TestAvatar', }, } as TAuthContext) }) @@ -33,7 +32,7 @@ describe('VotesDate component', () => { it('changes Votos and Fecha styles on click', () => { render( { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Name', - avatarId: 'Avatar', }, } as TAuthContext) }) @@ -68,7 +67,6 @@ it('renders Navbar for logged in users', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Name', - avatarId: 'Avatar', }, } as TAuthContext) render() @@ -147,7 +145,6 @@ it('status filter widget appears for users who are logged in', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Name', - avatarId: 'Avatar', }, } as TAuthContext) render() diff --git a/web/wiki/src/__tests__/pages/Home.test.tsx b/web/wiki/src/__tests__/pages/Home.test.tsx index 985659833..1d3a0ef38 100644 --- a/web/wiki/src/__tests__/pages/Home.test.tsx +++ b/web/wiki/src/__tests__/pages/Home.test.tsx @@ -20,7 +20,6 @@ describe('Home page', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) render() @@ -49,7 +48,6 @@ describe('Home page', () => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'Hola', - avatarId: 'Adios', }, } as TAuthContext) render() diff --git a/web/wiki/src/__tests__/pages/UserProfile.test.tsx b/web/wiki/src/__tests__/pages/UserProfile.test.tsx index 8d31ba4a2..7ee37f72b 100644 --- a/web/wiki/src/__tests__/pages/UserProfile.test.tsx +++ b/web/wiki/src/__tests__/pages/UserProfile.test.tsx @@ -18,7 +18,6 @@ beforeEach(() => { vi.mocked(useAuth).mockReturnValue({ user: { name: 'User Test Name', - avatarId: 'Adios', email: 'mail@test.com', }, } as TAuthContext)