add-domain-drawer.test.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { App as AntApp, ConfigProvider } from 'antd';
  2. import { render, screen, waitFor } from '@testing-library/react';
  3. import userEvent from '@testing-library/user-event';
  4. import { describe, expect, it, vi } from 'vitest';
  5. import { AddDomainDrawer } from '../../src/components/domain/AddDomainDrawer';
  6. import { I18nProvider } from '../../src/frontend/i18n/react';
  7. import { mailhubTheme } from '../../src/frontend/theme';
  8. import type { RuntimeConfig } from '../../src/frontend/types';
  9. describe('AddDomainDrawer', () => {
  10. it('progressively collects a domain and submits the three-step review', async () => {
  11. const user = userEvent.setup();
  12. const onSubmit = vi.fn(async () => undefined);
  13. render(
  14. <ConfigProvider theme={mailhubTheme}>
  15. <AntApp>
  16. <I18nProvider>
  17. <AddDomainDrawer
  18. open
  19. config={runtimeConfig}
  20. dnsCredentials={[]}
  21. smtpRelays={[]}
  22. onClose={vi.fn()}
  23. onSubmit={onSubmit}
  24. />
  25. </I18nProvider>
  26. </AntApp>
  27. </ConfigProvider>
  28. );
  29. await user.type(screen.getByLabelText('域名'), 'Example.COM');
  30. await user.click(screen.getByRole('button', { name: '下一步' }));
  31. expect(await screen.findByText('手动配置 DNS')).toBeTruthy();
  32. await user.click(screen.getByRole('button', { name: '下一步' }));
  33. expect(await screen.findByText('检查并创建')).toBeTruthy();
  34. await user.click(screen.getByRole('button', { name: /创建并验证/ }));
  35. await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1));
  36. expect(onSubmit.mock.calls[0][0]).toMatchObject({
  37. domain: 'example.com',
  38. senderHost: 'mail.example.test',
  39. sendingIp: '192.0.2.10',
  40. immediateCheck: true
  41. });
  42. });
  43. });
  44. const runtimeConfig: RuntimeConfig = {
  45. appBaseUrl: 'https://mail.example.test',
  46. mailHostname: 'mail.example.test',
  47. sendingIp: '192.0.2.10',
  48. defaultSpfMechanisms: '',
  49. dmarcPolicy: 'none',
  50. dmarcRua: '',
  51. sendRequiresVerified: true,
  52. engagementTrackingEnabled: true,
  53. listUnsubscribeMailto: '',
  54. listUnsubscribeUrl: '',
  55. listUnsubscribePostEnabled: false,
  56. feedbackIdEnabled: false,
  57. reportAbuseTo: '',
  58. csaComplaintsTo: '',
  59. bounceAddress: '',
  60. bounceEnvelopeEnabled: false
  61. };