rules.spec.tsx 1.7 KB

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