inbound-form-blocks.test.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { describe, it, expect } from 'vitest';
  2. import { Form } from 'antd';
  3. import type { ReactNode } from 'react';
  4. import { FormProvider, useForm } from 'react-hook-form';
  5. import {
  6. GrpcForm,
  7. HttpUpgradeForm,
  8. KcpForm,
  9. RawForm,
  10. SockoptForm,
  11. WsForm,
  12. XhttpForm,
  13. } from '@/pages/inbounds/form/transport';
  14. import { RealityForm, TlsForm } from '@/pages/inbounds/form/security';
  15. import type { InboundFormValues } from '@/schemas/forms/inbound-form';
  16. import { renderWithProviders, fieldLabels } from './test-utils';
  17. function FormHarness({
  18. children,
  19. defaultValues,
  20. }: {
  21. children: ReactNode;
  22. defaultValues?: Record<string, unknown>;
  23. }) {
  24. const methods = useForm<InboundFormValues>({ defaultValues: defaultValues as never });
  25. return (
  26. <FormProvider {...methods}>
  27. <Form>{children}</Form>
  28. </FormProvider>
  29. );
  30. }
  31. function renderInForm(node: ReactNode, defaultValues?: Record<string, unknown>) {
  32. return renderWithProviders(<FormHarness defaultValues={defaultValues}>{node}</FormHarness>);
  33. }
  34. const noop = () => {};
  35. describe('inbound transport forms', () => {
  36. it('RawForm field structure is stable', () => {
  37. renderInForm(<RawForm />);
  38. expect(fieldLabels()).toMatchSnapshot();
  39. });
  40. it('WsForm field structure is stable', () => {
  41. renderInForm(<WsForm />);
  42. expect(fieldLabels()).toMatchSnapshot();
  43. });
  44. it('GrpcForm field structure is stable', () => {
  45. renderInForm(<GrpcForm />);
  46. expect(fieldLabels()).toMatchSnapshot();
  47. });
  48. it('KcpForm field structure is stable', () => {
  49. renderInForm(<KcpForm />);
  50. expect(fieldLabels()).toMatchSnapshot();
  51. });
  52. it('HttpUpgradeForm field structure is stable', () => {
  53. renderInForm(<HttpUpgradeForm />);
  54. expect(fieldLabels()).toMatchSnapshot();
  55. });
  56. it('XhttpForm field structure is stable', () => {
  57. renderInForm(<XhttpForm />);
  58. expect(fieldLabels()).toMatchSnapshot();
  59. });
  60. it('SockoptForm field structure is stable (server-side fields only)', () => {
  61. /* The inbound sockopt form shows only server/listening-side fields;
  62. outbound-only fields (dialerProxy, domainStrategy, interface,
  63. addressPortStrategy, happyEyeballs, tcpMptcp) live in the outbound form. */
  64. renderInForm(
  65. <SockoptForm toggleSockopt={noop} network="tcp" />,
  66. { streamSettings: { sockopt: { mark: 0 } } },
  67. );
  68. expect(fieldLabels()).toMatchSnapshot();
  69. });
  70. });
  71. describe('inbound security forms', () => {
  72. it('TlsForm field structure is stable', () => {
  73. renderInForm(
  74. <TlsForm
  75. saving={false}
  76. setCertFromPanel={noop}
  77. clearCertFiles={noop}
  78. pinFromCert={noop}
  79. pinFromRemote={noop}
  80. getNewEchCert={noop}
  81. clearEchCert={noop}
  82. />,
  83. );
  84. expect(fieldLabels()).toMatchSnapshot();
  85. });
  86. it('RealityForm field structure is stable', () => {
  87. renderInForm(
  88. <RealityForm
  89. saving={false}
  90. scanning={false}
  91. scanResult={null}
  92. scanRealityTarget={noop}
  93. scanRealityCandidates={async () => []}
  94. applyRealityScanResult={noop}
  95. randomizeShortIds={noop}
  96. randomizeSpiderX={noop}
  97. genRealityKeypair={noop}
  98. clearRealityKeypair={noop}
  99. genMldsa65={noop}
  100. clearMldsa65={noop}
  101. />,
  102. );
  103. expect(fieldLabels()).toMatchSnapshot();
  104. });
  105. });