screensTable.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  4. import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
  5. function getMockEventView({fields}) {
  6. return new EventView({
  7. id: '1',
  8. name: 'mock query',
  9. fields,
  10. sorts: [],
  11. query: '',
  12. project: [],
  13. start: '2019-10-01T00:00:00',
  14. end: '2019-10-02T00:00:00',
  15. statsPeriod: '14d',
  16. environment: [],
  17. additionalConditions: new MutableSearch(''),
  18. createdBy: undefined,
  19. interval: undefined,
  20. display: '',
  21. team: [],
  22. topEvents: undefined,
  23. yAxis: undefined,
  24. });
  25. }
  26. describe('ScreensTable', () => {
  27. it('renders table header cells with translated names', () => {
  28. render(
  29. <ScreensTable
  30. columnNameMap={{
  31. transaction: 'Screen',
  32. }}
  33. columnTooltipMap={{}}
  34. columnOrder={['transaction']}
  35. data={{
  36. data: [{id: '1', transaction: 'Screen 1'}],
  37. meta: {},
  38. }}
  39. defaultSort={[]}
  40. eventView={getMockEventView({fields: [{field: 'transaction'}]})}
  41. isLoading={false}
  42. pageLinks={undefined}
  43. />
  44. );
  45. expect(screen.getByText('Screen')).toBeInTheDocument();
  46. expect(screen.queryByText('transaction')).not.toBeInTheDocument();
  47. });
  48. it('renders body cells with custom renderer if applicable', () => {
  49. render(
  50. <ScreensTable
  51. columnNameMap={{
  52. transaction: 'Screen',
  53. }}
  54. columnTooltipMap={{}}
  55. columnOrder={['transaction', 'non-custom']}
  56. data={{
  57. data: [
  58. {id: '1', transaction: 'Screen 1', 'non-custom': 'non customized value'},
  59. ],
  60. meta: {fields: {transaction: 'string'}},
  61. }}
  62. defaultSort={[]}
  63. eventView={getMockEventView({
  64. fields: [{field: 'transaction'}, {field: 'non-custom'}],
  65. })}
  66. isLoading={false}
  67. pageLinks={undefined}
  68. customBodyCellRenderer={(column, row) => {
  69. if (column.key === 'transaction') {
  70. return `Custom rendered ${row.transaction}`;
  71. }
  72. return null;
  73. }}
  74. />
  75. );
  76. expect(screen.getByText('Custom rendered Screen 1')).toBeInTheDocument();
  77. expect(screen.getByText('non customized value')).toBeInTheDocument();
  78. });
  79. it('renders column header tooltips', async () => {
  80. render(
  81. <ScreensTable
  82. columnNameMap={{
  83. transaction: 'Screen Column',
  84. }}
  85. columnTooltipMap={{
  86. transaction: 'Screen Column Tooltip',
  87. }}
  88. columnOrder={['transaction', 'non-custom']}
  89. data={{
  90. data: [
  91. {id: '1', transaction: 'Screen 1', 'non-custom': 'non customized value'},
  92. ],
  93. meta: {fields: {transaction: 'string'}},
  94. }}
  95. defaultSort={[]}
  96. eventView={getMockEventView({
  97. fields: [{field: 'transaction'}, {field: 'non-custom'}],
  98. })}
  99. isLoading={false}
  100. pageLinks={undefined}
  101. />
  102. );
  103. const columnHeader = screen.getByText('Screen Column');
  104. await userEvent.hover(columnHeader);
  105. expect(await screen.findByText('Screen Column Tooltip')).toBeInTheDocument();
  106. });
  107. });