screensTable.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {render, screen} 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/performance/mobile/components/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. columnOrder={['transaction']}
  34. data={{
  35. data: [{id: '1', transaction: 'Screen 1'}],
  36. meta: {},
  37. }}
  38. defaultSort={[]}
  39. eventView={getMockEventView({fields: [{field: 'transaction'}]})}
  40. isLoading={false}
  41. pageLinks={undefined}
  42. />
  43. );
  44. expect(screen.getByText('Screen')).toBeInTheDocument();
  45. expect(screen.queryByText('transaction')).not.toBeInTheDocument();
  46. });
  47. it('renders body cells with custom renderer if applicable', () => {
  48. render(
  49. <ScreensTable
  50. columnNameMap={{
  51. transaction: 'Screen',
  52. }}
  53. columnOrder={['transaction', 'non-custom']}
  54. data={{
  55. data: [
  56. {id: '1', transaction: 'Screen 1', 'non-custom': 'non customized value'},
  57. ],
  58. meta: {fields: {transaction: 'string'}},
  59. }}
  60. defaultSort={[]}
  61. eventView={getMockEventView({
  62. fields: [{field: 'transaction'}, {field: 'non-custom'}],
  63. })}
  64. isLoading={false}
  65. pageLinks={undefined}
  66. customBodyCellRenderer={(column, row) => {
  67. if (column.key === 'transaction') {
  68. return `Custom rendered ${row.transaction}`;
  69. }
  70. return null;
  71. }}
  72. />
  73. );
  74. expect(screen.getByText('Custom rendered Screen 1')).toBeInTheDocument();
  75. expect(screen.getByText('non customized value')).toBeInTheDocument();
  76. });
  77. });