mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-15 02:15:01 +03:00
89e200ead4
Zod 4: use the `error` param instead of the deprecated `message`. lint:deprecated missed these because tsgolint's no-deprecated does not resolve object-literal properties on a `string | Params` union. Geodata: key geo entry rows by page position. antd deprecates rowKey's index argument, and kind:value repeats within a page because the reader drops domain attributes (22 pairs in geosite_IR.dat, 108 in geosite_RU). Nord/PIA: the "All cities/regions" option used a null value, which antd warns on. Map it through a sentinel at the Select boundary so form state stays null, with tests that fail when the sentinel is not mapped back. Tests: - Run the oxlint guard through node; .bin/oxlint is a sh shim Windows cannot spawn, and the swallowed error left both guard cases vacuous. - Start unit workers with --no-experimental-webstorage; msw's localStorage probe made Node 25+ warn once per forked worker. - Set IS_REACT_ACT_ENVIRONMENT, which RTL never sets with globals: false, and settle the async updates it exposed inside act(). The row-cells memo test now fails when memo is removed. - Disable antd's click wave in Storybook; it re-rendered inside the next story's act() and tripped "not configured to support act". - Assert InboundFormModal's validation log instead of leaking it, and give the rule-form test a well-formed clients/list response.
58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
|
|
|
import RemarkTemplateField from '@/components/form/RemarkTemplateField';
|
|
import { previewRemark, SUBSCRIPTION_METADATA_VARIABLES } from '@/lib/remark/remarkVariables';
|
|
|
|
describe('RemarkTemplateField', () => {
|
|
it('inserts a {{TOKEN}} when a variable chip is clicked', async () => {
|
|
const onChange = vi.fn();
|
|
render(<RemarkTemplateField value="DE " onChange={onChange} maxLength={256} />);
|
|
|
|
// Open the variable picker (the only button is the addon trigger).
|
|
fireEvent.click(screen.getByRole('button'));
|
|
fireEvent.click(await screen.findByText('{{EMAIL}}'));
|
|
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
const inserted = onChange.mock.calls[0][0] as string;
|
|
expect(inserted).toContain('{{EMAIL}}');
|
|
expect(inserted).toContain('DE');
|
|
});
|
|
|
|
it('renders a live preview of the expanded remark', () => {
|
|
render(<RemarkTemplateField value="{{EMAIL}}" onChange={() => {}} />);
|
|
// Sample expansion of {{EMAIL}} is "john".
|
|
expect(screen.getByText('john')).toBeTruthy();
|
|
});
|
|
|
|
it('supports token insertion in multiline fields', async () => {
|
|
const onChange = vi.fn();
|
|
render(<RemarkTemplateField value="Hello " onChange={onChange} multiline rows={3} />);
|
|
const textarea = screen.getByRole('textbox') as HTMLTextAreaElement;
|
|
act(() => textarea.focus());
|
|
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
|
|
fireEvent.click(screen.getByRole('button'));
|
|
fireEvent.click(await screen.findByText('{{SUB_ID}}'));
|
|
|
|
expect(onChange).toHaveBeenCalledTimes(1);
|
|
expect(onChange.mock.calls[0][0]).toBe('Hello {{SUB_ID}}');
|
|
});
|
|
|
|
it('limits the picker to client identity tokens for metadata fields', async () => {
|
|
render(<RemarkTemplateField value="" onChange={() => {}} metadataOnly />);
|
|
|
|
fireEvent.click(screen.getByRole('button'));
|
|
|
|
expect(await screen.findByText('{{EMAIL}}')).toBeTruthy();
|
|
expect(screen.queryByText('{{INBOUND}}')).toBeNull();
|
|
expect(screen.queryByText('{{TRAFFIC_LEFT}}')).toBeNull();
|
|
});
|
|
|
|
it('previews metadata fields with metadata-safe tokens only', () => {
|
|
expect(previewRemark('{{EMAIL}}/{{TRAFFIC_LEFT}}', SUBSCRIPTION_METADATA_VARIABLES, true)).toBe(
|
|
'john/{{TRAFFIC_LEFT}}',
|
|
);
|
|
});
|
|
});
|