mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-13 00:25:04 +03:00
fix(xray): read and write log.logLevel in the Xray basics tab
xray-core 26.11.9 (#7329) spells the key log.logLevel and still accepts loglevel. A template written with the new spelling showed "warning" in the panel, and changing the level added a second loglevel key beside it, leaving the core to pick between two values. The select now reads either spelling and saves a single logLevel key.
This commit is contained in:
@@ -414,12 +414,15 @@ export default function BasicsTab({
|
|||||||
paddings="small"
|
paddings="small"
|
||||||
control={
|
control={
|
||||||
<Select
|
<Select
|
||||||
value={(log.loglevel as string) || 'warning'}
|
value={((log.logLevel ?? log.loglevel) as string) || 'warning'}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
options={LOG_LEVELS.map((s) => ({ value: s, label: s }))}
|
options={LOG_LEVELS.map((s) => ({ value: s, label: s }))}
|
||||||
onChange={(v) =>
|
onChange={(v) =>
|
||||||
mutate((tt) => {
|
mutate((tt) => {
|
||||||
if (tt.log) tt.log.loglevel = v;
|
if (!tt.log) return;
|
||||||
|
// The core reads either spelling, so keeping both would let the stale one win.
|
||||||
|
delete tt.log.loglevel;
|
||||||
|
tt.log.logLevel = v;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
|
import { fireEvent, screen } from '@testing-library/react';
|
||||||
|
|
||||||
|
import BasicsTab from '@/pages/xray/basics/BasicsTab';
|
||||||
|
import type { XraySettingsValue } from '@/hooks/useXraySetting';
|
||||||
|
|
||||||
|
import { renderWithProviders } from './test-utils';
|
||||||
|
|
||||||
|
// xray-core 26.11.9 (#7329) spells the key log.logLevel and still reads loglevel.
|
||||||
|
describe('BasicsTab log level spelling', () => {
|
||||||
|
it('shows a template written as logLevel and saves one key, not both spellings', () => {
|
||||||
|
const setTemplateSettings = vi.fn();
|
||||||
|
renderWithProviders(
|
||||||
|
<BasicsTab
|
||||||
|
templateSettings={{ log: { logLevel: 'debug' } } as unknown as XraySettingsValue}
|
||||||
|
setTemplateSettings={setTemplateSettings}
|
||||||
|
outboundTestUrl=""
|
||||||
|
onChangeOutboundTestUrl={vi.fn()}
|
||||||
|
onResetDefault={vi.fn()}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
fireEvent.click(screen.getByRole('tab', { name: /Log/ }));
|
||||||
|
const combobox = screen.getByRole('combobox', { name: 'Log Level' });
|
||||||
|
expect(combobox.closest('.ant-select')?.textContent).toContain('debug');
|
||||||
|
|
||||||
|
fireEvent.mouseDown(combobox);
|
||||||
|
fireEvent.click(screen.getByTitle('error'));
|
||||||
|
const update = setTemplateSettings.mock.calls.at(-1)?.[0] as (
|
||||||
|
prev: XraySettingsValue,
|
||||||
|
) => XraySettingsValue;
|
||||||
|
const legacy = { log: { loglevel: 'warning' } } as unknown as XraySettingsValue;
|
||||||
|
expect(update(legacy).log).toEqual({ logLevel: 'error' });
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user