-
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.
1310-feusuaris-add-mentor-section-for-admin-users (#1326)
Update UserRole export/imports
- Loading branch information
Showing
28 changed files
with
427 additions
and
267 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
import { screen } from '@testing-library/react' | ||
import { render } from '../test-utils' | ||
import { Dashboard } from '../../components/organisms' | ||
|
||
describe('Dashboard', () => { | ||
it('renders correctly', () => { | ||
render(<Dashboard />) | ||
|
||
const mainDiv = screen.getByRole('main') | ||
const sideMenuElement = screen.getByText(/Mentors/i) | ||
const filtersWidgetElement = screen.getByAltText(/Calendar/i) | ||
const actionsDropdown = screen.getByTestId('actions-dropdown') | ||
|
||
expect(mainDiv).toBeInTheDocument() | ||
expect(sideMenuElement).toBeInTheDocument() | ||
expect(filtersWidgetElement).toBeInTheDocument() | ||
expect(actionsDropdown).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,69 @@ | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { fireEvent, screen, waitFor } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import { colors } from '@itacademy/ui' | ||
import { describe, beforeEach, it, expect } from 'vitest' | ||
import { render } from '../test-utils' | ||
import { SideMenu } from '../../components/organisms' | ||
import { paths } from '../../constants' | ||
|
||
describe('SideMenu', () => { | ||
beforeEach(() => { | ||
render(<SideMenu />) | ||
}) | ||
|
||
it('renders correctly', () => { | ||
it('renders correctly', async () => { | ||
expect(screen.getByAltText('IT Academy')).toBeInTheDocument() | ||
expect(screen.getByText('Usuaris')).toBeInTheDocument() | ||
expect(screen.getByText('Mentors')).toBeInTheDocument() | ||
expect(screen.getByText('Connector')).toBeInTheDocument() | ||
expect(screen.getByText('Configuració')).toBeInTheDocument() | ||
}) | ||
const usersItem = screen.getByTestId('test-title-Usuarios') | ||
const mentorsItem = screen.getByTestId('test-title-Mentores') | ||
const connectorItem = screen.getByTestId('test-title-Connector') | ||
const settingsItem = screen.getByTestId('test-title-Configuración') | ||
|
||
it('navigates to the correct page when a menu item is clicked', () => { | ||
const firstMenuItem = screen.getByText('Usuaris') | ||
fireEvent.click(firstMenuItem) | ||
expect(window.location.pathname).toEqual('/') | ||
}) | ||
expect(usersItem).toBeInTheDocument() | ||
expect(mentorsItem).toBeInTheDocument() | ||
expect(connectorItem).toBeInTheDocument() | ||
expect(settingsItem).toBeInTheDocument() | ||
|
||
it('changes style on hover over a category', () => { | ||
const category = screen.getByText('Usuaris') | ||
fireEvent.mouseOver(category) | ||
expect(category).toHaveStyle(`color: ${colors.primary}`) | ||
expect(screen.getAllByTestId('test-icon-person').length).toBe(2) | ||
expect(screen.getByTestId('test-icon-bolt')).toBeInTheDocument() | ||
expect(screen.getByTestId('test-icon-settings')).toBeInTheDocument() | ||
|
||
waitFor(() => { | ||
expect(usersItem).toHaveStyle(`color: ${colors.black.black3}`) | ||
expect(mentorsItem).toHaveStyle(`color: ${colors.gray.gray3}`) | ||
expect(connectorItem).toHaveStyle(`color: ${colors.gray.gray3}`) | ||
expect(settingsItem).toHaveStyle(`color: ${colors.gray.gray3}`) | ||
}) | ||
}) | ||
|
||
it('displays the correct icons for each menu item', () => { | ||
const personIcons = screen.getAllByTestId('person') | ||
expect(personIcons.length).toBe(2) | ||
it('navigates to the correct page when a menu item is clicked and changes styles', async () => { | ||
const mentorsMenuItemLink = screen.getByTestId('test-link-Mentores') | ||
const mentorsTitle = screen.getByTestId('test-title-Mentores') | ||
|
||
expect(screen.getByTestId(`test-path-${paths.home}`)).toBeInTheDocument() | ||
waitFor(() => { | ||
expect(mentorsTitle).toHaveStyle(`color: ${colors.gray.gray3}`) | ||
}) | ||
|
||
const boltIcon = screen.getByTestId('bolt') | ||
expect(boltIcon).toBeInTheDocument() | ||
await userEvent.click(mentorsMenuItemLink) | ||
|
||
expect(screen.getByTestId(`test-path-${paths.mentors}`)).toBeInTheDocument() | ||
waitFor(() => { | ||
expect(mentorsTitle).toHaveStyle(`color: ${colors.black.black3}`) | ||
}) | ||
}) | ||
|
||
it('changes style on hover over a category', () => { | ||
const activeCategory = screen.getByText('Usuaris') | ||
fireEvent.mouseOver(activeCategory) | ||
expect(activeCategory).toHaveStyle(`color: ${colors.black.black3}`) | ||
|
||
const settingsIcon = screen.getByTestId('settings') | ||
expect(settingsIcon).toBeInTheDocument() | ||
const inactiveCategory = screen.getByText('Mentors') | ||
fireEvent.mouseOver(inactiveCategory) | ||
expect(inactiveCategory).toHaveStyle(`color: ${colors.primary}`) | ||
}) | ||
|
||
it('ensures menu items are focusable for accessibility', () => { | ||
const firstMenuItem = screen.getByText('Usuaris') | ||
firstMenuItem.focus() | ||
expect(firstMenuItem).toHaveFocus() | ||
const usersMenuItem = screen.getByTestId('test-link-Usuarios') | ||
usersMenuItem.focus() | ||
expect(usersMenuItem).toHaveFocus() | ||
}) | ||
}) |
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,32 @@ | ||
import { screen } from '@testing-library/react' | ||
import { render } from '../test-utils' | ||
import { Mentors } from '../../pages' | ||
import { TAuthContext, useAuth } from '../../context/AuthProvider' | ||
import { UserRole } from '../../types' | ||
import { paths } from '../../constants' | ||
|
||
describe('Mentors page', () => { | ||
beforeEach(() => { | ||
vi.mock('../../context/AuthProvider', async () => { | ||
const actual = await vi.importActual('../../context/AuthProvider') | ||
return { | ||
...actual, | ||
useAuth: vi.fn(), | ||
} | ||
}) | ||
}) | ||
|
||
it('renders correctly Mentors page if Admin user is logged in', () => { | ||
vi.mocked(useAuth).mockReturnValue({ | ||
user: { | ||
dni: '12345678A', | ||
email: 'user@example.cat', | ||
role: UserRole.ADMIN, | ||
}, | ||
} as TAuthContext) | ||
|
||
render(<Mentors />, { initialEntries: [paths.mentors] }) | ||
|
||
expect(screen.getByTestId('test-mentors-page')).toBeInTheDocument() | ||
}) | ||
}) |
Oops, something went wrong.