cipher-suites-select.test.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { describe, expect, it, vi } from 'vitest';
  2. import { fireEvent, render, screen } from '@testing-library/react';
  3. import { CipherSuitesSelect } from '@/components/form';
  4. function renderSelect(value: string) {
  5. const onChange = vi.fn();
  6. render(<CipherSuitesSelect aria-label="cipher suites" value={value} onChange={onChange} />);
  7. return onChange;
  8. }
  9. describe('CipherSuitesSelect', () => {
  10. it('shows each colon-separated suite as its own tag', () => {
  11. renderSelect('TLS_AES_256_GCM_SHA384:MY_CUSTOM_SUITE');
  12. expect(screen.getByText('TLS_AES_256_GCM_SHA384')).toBeTruthy();
  13. expect(screen.getByText('MY_CUSTOM_SUITE')).toBeTruthy();
  14. });
  15. it('stores a typed custom suite joined with colons after the existing one', () => {
  16. const onChange = renderSelect('TLS_AES_256_GCM_SHA384');
  17. const input = screen.getByRole('combobox', { name: 'cipher suites' });
  18. fireEvent.change(input, { target: { value: 'MY_CUSTOM_SUITE' } });
  19. fireEvent.keyDown(input, { key: 'Enter', code: 'Enter', keyCode: 13 });
  20. expect(onChange).toHaveBeenLastCalledWith('TLS_AES_256_GCM_SHA384:MY_CUSTOM_SUITE');
  21. });
  22. it('stores an empty string once every suite is removed', () => {
  23. const onChange = renderSelect('TLS_AES_256_GCM_SHA384');
  24. const remove = document.querySelector('.ant-select-selection-item-remove');
  25. expect(remove).not.toBeNull();
  26. fireEvent.click(remove as Element);
  27. expect(onChange).toHaveBeenLastCalledWith('');
  28. });
  29. });