🧪 ci: Update PermissionService tests for PromptGroup resource type

- Refactor tests to use PromptGroup roles instead of Project roles.
- Initialize models and seed default roles in test setup.
- Update error handling for non-existent resource types.
- Ensure proper cleanup of test data while retaining seeded roles.
This commit is contained in:
Danny Avila 2025-08-02 15:23:58 -04:00
parent fc8fd489d6
commit 90b037a67f
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
5 changed files with 66 additions and 99 deletions

View file

@ -96,16 +96,13 @@ jest.mock('~/hooks/useLocalize', () => ({
jest.mock('~/hooks', () => ({
useLocalize: () => mockLocalize,
useDebounce: jest.fn(),
useAgentCategories: jest.fn(),
}));
jest.mock('~/data-provider/Agents', () => ({
useMarketplaceAgentsInfiniteQuery: jest.fn(),
}));
jest.mock('~/hooks/Agents', () => ({
useAgentCategories: jest.fn(),
}));
// Mock utility functions
jest.mock('~/utils/agents', () => ({
renderAgentAvatar: jest.fn(() => <div data-testid="agent-avatar" />),
@ -120,8 +117,7 @@ jest.mock('../SmartLoader', () => ({
// Import the actual modules to get the mocked functions
import { useMarketplaceAgentsInfiniteQuery } from '~/data-provider/Agents';
import { useAgentCategories } from '~/hooks/Agents';
import { useDebounce } from '~/hooks';
import { useAgentCategories, useDebounce } from '~/hooks';
// Get typed mock functions
const mockUseMarketplaceAgentsInfiniteQuery = jest.mocked(useMarketplaceAgentsInfiniteQuery);

View file

@ -10,7 +10,6 @@ import type t from 'librechat-data-provider';
import { Constants, EModelEndpoint } from 'librechat-data-provider';
import AgentDetail from '../AgentDetail';
import { useToast } from '~/hooks';
// Mock dependencies
jest.mock('react-router-dom', () => ({
@ -19,11 +18,15 @@ jest.mock('react-router-dom', () => ({
}));
jest.mock('~/hooks', () => ({
useToast: jest.fn(),
useMediaQuery: jest.fn(() => false), // Mock as desktop by default
useLocalize: jest.fn(),
}));
jest.mock('@librechat/client', () => ({
...jest.requireActual('@librechat/client'),
useToastContext: jest.fn(),
}));
jest.mock('~/utils/agents', () => ({
renderAgentAvatar: jest.fn((agent, options) => (
<div data-testid="agent-avatar" data-size={options?.size} />
@ -101,7 +104,8 @@ describe('AgentDetail', () => {
beforeEach(() => {
jest.clearAllMocks();
(useNavigate as jest.Mock).mockReturnValue(mockNavigate);
(useToast as jest.Mock).mockReturnValue({ showToast: mockShowToast });
const { useToastContext } = require('@librechat/client');
(useToastContext as jest.Mock).mockReturnValue({ showToast: mockShowToast });
const { useLocalize } = require('~/hooks');
(useLocalize as jest.Mock).mockReturnValue(mockLocalize);

View file

@ -4,12 +4,10 @@ import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import SearchBar from '../SearchBar';
// Mock useLocalize hook
jest.mock('~/hooks/useLocalize', () => () => (key: string) => key);
// Mock useDebounce hook
// Mock hooks
jest.mock('~/hooks', () => ({
useDebounce: (value: string) => value, // Return value immediately for testing
useLocalize: () => (key: string) => key,
}));
describe('SearchBar', () => {

View file

@ -274,7 +274,7 @@ describe('AgentFooter', () => {
expect(screen.getByTestId('delete-button')).toBeInTheDocument();
expect(screen.queryByTestId('admin-settings')).not.toBeInTheDocument();
expect(screen.getByTestId('grant-access-dialog')).toBeInTheDocument();
expect(screen.getByTestId('duplicate-agent')).toBeInTheDocument();
expect(screen.getByTestId('duplicate-button')).toBeInTheDocument();
expect(document.querySelector('.spinner')).not.toBeInTheDocument();
});
@ -284,8 +284,11 @@ describe('AgentFooter', () => {
);
expect(document.querySelector('.spinner')).toBeInTheDocument();
expect(screen.queryByText('Save')).not.toBeInTheDocument();
expect(screen.getByRole('button')).toBeDisabled();
expect(screen.getByRole('button')).toHaveAttribute('aria-busy', 'true');
// Find the submit button (the one with aria-busy attribute)
const buttons = screen.getAllByRole('button');
const submitButton = buttons.find((button) => button.getAttribute('type') === 'submit');
expect(submitButton).toBeDisabled();
expect(submitButton).toHaveAttribute('aria-busy', 'true');
unmount();
});
@ -408,7 +411,7 @@ describe('AgentFooter', () => {
expect(screen.queryByTestId('delete-button')).not.toBeInTheDocument();
expect(screen.queryByTestId('grant-access-dialog')).not.toBeInTheDocument();
// Duplicate button should still show as it doesn't depend on permissions loading
expect(screen.getByTestId('duplicate-agent')).toBeInTheDocument();
expect(screen.getByTestId('duplicate-button')).toBeInTheDocument();
});
});