rules.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {DataScrubbingRelayPiiConfigFixture} from 'sentry-fixture/dataScrubbingRelayPiiConfig';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import {convertRelayPiiConfig} from 'sentry/views/settings/components/dataScrubbing/convertRelayPiiConfig';
  5. import Rules from 'sentry/views/settings/components/dataScrubbing/rules';
  6. const relayPiiConfig = convertRelayPiiConfig(
  7. JSON.stringify(DataScrubbingRelayPiiConfigFixture())
  8. );
  9. describe('Rules', function () {
  10. it('default render', function () {
  11. render(<Rules rules={relayPiiConfig} onEditRule={jest.fn()} />);
  12. expect(screen.getAllByRole('button', {name: 'Edit Rule'})).toHaveLength(3);
  13. expect(
  14. screen.getByText(
  15. textWithMarkupMatcher(
  16. '[Replace] [[a-zA-Z0-9]+] with [Placeholder] from [$message]'
  17. )
  18. )
  19. ).toBeInTheDocument();
  20. expect(
  21. screen.getByText('[Mask] [Credit card numbers] from [$message]')
  22. ).toBeInTheDocument();
  23. expect(
  24. screen.getByText(
  25. textWithMarkupMatcher(
  26. '[Replace] [Password fields] with [Scrubbed] from [password]'
  27. )
  28. )
  29. ).toBeInTheDocument();
  30. });
  31. it('render edit button only', function () {
  32. render(<Rules rules={relayPiiConfig} onEditRule={jest.fn()} />);
  33. expect(screen.getAllByRole('button', {name: 'Edit Rule'})).toHaveLength(3);
  34. expect(screen.queryByRole('button', {name: 'Delete Rule'})).not.toBeInTheDocument();
  35. });
  36. it('render delete button only', function () {
  37. render(<Rules rules={relayPiiConfig} onDeleteRule={jest.fn()} />);
  38. expect(screen.getAllByRole('button', {name: 'Delete Rule'})).toHaveLength(3);
  39. expect(screen.queryByRole('button', {name: 'Edit Rule'})).not.toBeInTheDocument();
  40. });
  41. });