* feat: add team roles management and update related hooks and types * feat: implement add new team member functionality with modal and actions * test: add some missing tests * test: add unit tests for AddNewTeamMemberModal and update context mocks * test: add toast close functionality and loading state handling in AddNewTeamMemberTrigger tests * fix: update LibrariesAuthZTeamView to include canManageTeam check for AddNewTeamMemberTrigger * fix: correct API endpoint paths and update authorization scope format * refactor: improve error handling & address PR feedback * refactor: group AddNewTeamMemberModal in 1 folder * fix: reset modal values to close action * refactor: replace useAddTeamMember with useAssignTeamMembersRole * feat: add tooltip * test: fix test after rebase * refactor: enhance user intruction with placeholder * style: remove unnecessary inline style * fix: remove the error style on change the textarea value * fix: add useState to display toast * fix: remove empty strings from the user input * fix: validate error users to apply style --------- Co-authored-by: Diana Olarte <diana.olarte@edunext.co>
97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
import { ReactNode } from 'react';
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import AuthZTitle, { AuthZTitleProps } from './AuthZTitle';
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
...jest.requireActual('react-router-dom'),
|
|
Link: ({ children, to }:{ children:ReactNode, to:string }) => <a href={to}>{children}</a>,
|
|
}));
|
|
|
|
describe('AuthZTitle', () => {
|
|
const defaultProps: AuthZTitleProps = {
|
|
activeLabel: 'Current Page',
|
|
pageTitle: 'Page Title',
|
|
pageSubtitle: 'Page Subtitle',
|
|
};
|
|
|
|
it('renders without optional fields', () => {
|
|
render(<AuthZTitle {...defaultProps} />);
|
|
expect(screen.getByText(defaultProps.activeLabel)).toBeInTheDocument();
|
|
expect(screen.getByText(defaultProps.pageTitle)).toBeInTheDocument();
|
|
expect(screen.getByText(defaultProps.pageSubtitle as string)).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders breadcrumb with links and active label', () => {
|
|
const navLinks = [
|
|
{ label: 'Root', to: '/' },
|
|
{ label: 'Section', to: '/section' },
|
|
];
|
|
|
|
render(<AuthZTitle {...defaultProps} navLinks={navLinks} />);
|
|
|
|
navLinks.forEach(({ label, to }) => {
|
|
expect(screen.getByText(label)).toBeInTheDocument();
|
|
expect(screen.getByText(label)).toHaveAttribute('href', expect.stringContaining(to));
|
|
});
|
|
|
|
expect(screen.getByText(defaultProps.activeLabel)).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders page title', () => {
|
|
render(<AuthZTitle {...defaultProps} />);
|
|
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent(defaultProps.pageTitle);
|
|
});
|
|
|
|
it('renders page subtitle as ReactNode', () => {
|
|
const subtitleNode = <div data-testid="custom-subtitle">Custom Subtitle</div>;
|
|
render(<AuthZTitle {...defaultProps} pageSubtitle={subtitleNode} />);
|
|
expect(screen.getByTestId('custom-subtitle')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders action buttons and triggers onClick', () => {
|
|
const onClick1 = jest.fn();
|
|
const onClick2 = jest.fn();
|
|
const actions = [
|
|
{ label: 'Save', onClick: onClick1 },
|
|
{ label: 'Cancel', onClick: onClick2 },
|
|
];
|
|
|
|
render(<AuthZTitle {...defaultProps} actions={actions} />);
|
|
|
|
actions.forEach(({ label, onClick }) => {
|
|
const button = screen.getByRole('button', { name: label });
|
|
expect(button).toBeInTheDocument();
|
|
fireEvent.click(button);
|
|
expect(onClick).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
it('renders action buttons with icons', () => {
|
|
const mockIcon = () => <span data-testid="mock-icon">Icon</span>;
|
|
const onClick = jest.fn();
|
|
const actions = [
|
|
{ label: 'Save', icon: mockIcon, onClick },
|
|
];
|
|
|
|
render(<AuthZTitle {...defaultProps} actions={actions} />);
|
|
|
|
const button = screen.getByRole('button', { name: 'Icon Save' });
|
|
expect(button).toBeInTheDocument();
|
|
expect(screen.getByTestId('mock-icon')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders ReactNode actions alongside button actions', () => {
|
|
const onClick = jest.fn();
|
|
const customAction = <div data-testid="custom-action">Custom Action</div>;
|
|
const actions = [
|
|
{ label: 'Save', onClick },
|
|
customAction,
|
|
];
|
|
|
|
render(<AuthZTitle {...defaultProps} actions={actions} />);
|
|
|
|
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
|
|
expect(screen.getByTestId('custom-action')).toBeInTheDocument();
|
|
});
|
|
});
|