index.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import UserEventContext, {
  3. UserEventContextData,
  4. } from 'sentry/components/events/contexts/user';
  5. // the values of this mock are correct and the types need to be updated
  6. export const userMockData = {
  7. data: null,
  8. email: null,
  9. id: '',
  10. ip_address: null,
  11. name: null,
  12. username: null,
  13. } as unknown as UserEventContextData;
  14. export const userMetaMockData = {
  15. email: null,
  16. id: {
  17. '': {
  18. chunks: [
  19. {
  20. remark: 'x',
  21. rule_id: 'project:0',
  22. text: '',
  23. type: 'redaction',
  24. },
  25. ],
  26. len: 9,
  27. rem: [['project:0', 'x', 0, 0]],
  28. },
  29. },
  30. ip_address: {
  31. '': {
  32. err: [
  33. [
  34. 'invalid_data',
  35. {
  36. reason: 'expected an ip address',
  37. },
  38. ],
  39. ],
  40. len: 14,
  41. rem: [['project:0', 'x', 0, 0]],
  42. val: '',
  43. },
  44. },
  45. name: null,
  46. username: null,
  47. };
  48. const event = {
  49. ...TestStubs.Event(),
  50. _meta: {
  51. user: userMetaMockData,
  52. },
  53. };
  54. describe('user event context', function () {
  55. it('display the right context data according to its value and meta', async function () {
  56. render(<UserEventContext event={event} data={userMockData} />);
  57. expect(screen.getByText('ID')).toBeInTheDocument(); // subject
  58. expect(screen.getByText(/redacted/)).toBeInTheDocument(); // value
  59. userEvent.hover(screen.getByText(/redacted/));
  60. expect(
  61. await screen.findByText('Removed because of PII rule "project:0"')
  62. ).toBeInTheDocument(); // tooltip description
  63. expect(screen.getByText('IP Address')).toBeInTheDocument(); // subject
  64. expect(screen.getByText('None')).toBeInTheDocument(); // value
  65. userEvent.hover(screen.getByText('None'));
  66. expect(
  67. await screen.findByText('Removed because of PII rule "project:0"')
  68. ).toBeInTheDocument(); // tooltip description
  69. });
  70. });