Files
pterodactyl-panel/resources/scripts/components/admin/settings/SettingsForms.spec.tsx
T
ItzLinaton 4257022c66 Feat: Company/Brand Logo (V2) (#7269)
Added a configurable panel company/brand logo.

## Extra Details:
- New logo is used for:
  - Login page
  - Navigation bar
  - Page Favicon
- Panel Falls back to the default Ptero logo when no custom one is set.
- Supported File Formats: PNG, JPEG, WebP, AVIF, ICO, and safe SVG
files.

---

## Preview:
<img width="912" height="151"
alt="{67E9647B-AD26-41F8-8272-8B7F4D1CDFB7}"
src="https://github.com/user-attachments/assets/1af9c52b-ad4a-4f82-bb67-14a2b662beb2"
/>

<img width="916" height="256"
alt="{F49323AE-974C-4C16-B129-D60D3494BA0F}"
src="https://github.com/user-attachments/assets/3e35d7f1-c95b-4007-bf1f-69e2ce9891a2"
/>

<img width="1749" height="940"
alt="{252E88D0-BA45-43C8-99E2-5B31E81B739E}"
src="https://github.com/user-attachments/assets/2e807035-bbd0-48ca-823a-4510a9be696e"
/>

<img width="996" height="452" alt="image"
src="https://github.com/user-attachments/assets/c0bef229-285c-4cda-9291-7295e70b2189"
/>
2026-11-01 19:50:03 -05:00

122 lines
4.6 KiB
TypeScript

/** @vitest-environment jsdom */
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { AdminSettings } from '@/api/admin/settings/queries';
import type * as SettingsQueries from '@/api/admin/settings/queries';
import GeneralSettingsForm from './GeneralSettingsForm';
import AdvancedSettingsForm from './AdvancedSettingsForm';
import MailSettingsForm from './MailSettingsForm';
const mutations = vi.hoisted(() => ({
general: vi.fn(),
advanced: vi.fn(),
mail: vi.fn(),
testMail: vi.fn(),
uploadLogo: vi.fn(),
clearLogo: vi.fn(),
}));
vi.mock('@/api/admin/settings/queries', async (importOriginal) => ({
...(await importOriginal<typeof SettingsQueries>()),
useUpdateAdminGeneralSettings: () => ({ mutateAsync: mutations.general }),
useUploadAdminLogo: () => ({ isPending: false, mutateAsync: mutations.uploadLogo }),
useClearAdminLogo: () => ({ isPending: false, mutateAsync: mutations.clearLogo }),
useUpdateAdminAdvancedSettings: () => ({ mutateAsync: mutations.advanced }),
useUpdateAdminMailSettings: () => ({ mutateAsync: mutations.mail }),
useSendTestAdminMail: () => ({ mutateAsync: mutations.testMail }),
}));
vi.mock('@/api/admin/languages/queries', () => ({
useAdminLanguages: () => ({ data: { en: 'English' }, isLoading: false }),
}));
const settings: AdminSettings = {
general: {
'app:name': 'Panel',
'pterodactyl:auth:2fa_required': 0,
'pterodactyl:client_features:avatars:enabled': false,
'app:locale': 'en',
},
logo: null,
mail: {
'mail:default': 'smtp',
'mail:mailers:smtp:host': 'localhost',
'mail:mailers:smtp:port': 587,
'mail:mailers:smtp:encryption': 'tls',
'mail:mailers:smtp:username': null,
'mail:mailers:smtp:password': '',
'mail:from:address': 'panel@example.com',
'mail:from:name': 'Panel',
},
advanced: {
'recaptcha:enabled': false,
'recaptcha:secret_key': '',
'recaptcha:website_key': '',
'pterodactyl:guzzle:timeout': 10,
'pterodactyl:guzzle:connect_timeout': 5,
'pterodactyl:client_features:allocations:enabled': false,
'pterodactyl:client_features:allocations:range_start': null,
'pterodactyl:client_features:allocations:range_end': null,
},
meta: { load_environment_only: true, show_recaptcha_warning: false },
};
afterEach(cleanup);
beforeEach(() => vi.clearAllMocks());
const forms = [
{ name: 'general', Component: GeneralSettingsForm, mutation: mutations.general },
{ name: 'advanced', Component: AdvancedSettingsForm, mutation: mutations.advanced },
{ name: 'mail', Component: MailSettingsForm, mutation: mutations.mail },
];
describe('mail settings', () => {
it('submits the entered password once and then clears it', async () => {
const user = userEvent.setup();
render(
<MailSettingsForm settings={{ ...settings, meta: { ...settings.meta, load_environment_only: false } }} />
);
const password = screen.getByLabelText('Password');
await user.type(password, 'smtp-secret');
await user.click(screen.getByRole('button', { name: 'Save Changes' }));
expect(mutations.mail).toHaveBeenCalledWith({
body: { smtp: expect.objectContaining({ port: 587, password: 'smtp-secret' }) },
});
expect(password).toHaveValue('');
});
});
describe.each(forms)('$name settings', ({ Component, mutation }) => {
it('disables every setting and ignores native submissions in environment-only mode', async () => {
const { container } = render(<Component settings={settings} />);
const controls = container.querySelectorAll('input, button');
expect(controls.length).toBeGreaterThan(1);
for (const control of controls) {
expect(control).toBeDisabled();
}
await act(async () => fireEvent.submit(container.querySelector('form')!));
expect(mutation).not.toHaveBeenCalled();
expect(mutations.testMail).not.toHaveBeenCalled();
});
it('allows saving when settings are loaded dynamically', async () => {
render(<Component settings={{ ...settings, meta: { ...settings.meta, load_environment_only: false } }} />);
const save = screen.getByRole('button', { name: 'Save Changes' });
expect(save).toBeEnabled();
await act(async () => fireEvent.click(save));
expect(mutation).toHaveBeenCalledOnce();
});
});