profileDetailsTable.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  3. import {importProfile, ProfileGroup} from 'sentry/utils/profiling/profile/importProfile';
  4. import {makeSentrySampledProfile} from 'sentry/utils/profiling/profile/sentrySampledProfile.spec';
  5. import * as profileGroupProviderMod from '../../profileGroupProvider';
  6. import {ProfileDetailsTable} from './profileDetailsTable';
  7. const {routerContext} = initializeOrg();
  8. jest.mock('../../profileGroupProvider', () => {
  9. return {
  10. useProfileGroup: jest.fn(),
  11. };
  12. });
  13. jest.mock('../../profilesProvider', () => {
  14. return {
  15. useProfiles: jest.fn().mockReturnValue({type: 'resolved', data: null}),
  16. };
  17. });
  18. const useProfileGroupSpy = jest.spyOn(profileGroupProviderMod, 'useProfileGroup');
  19. const mockUseProfileData: ProfileGroup = importProfile(
  20. makeSentrySampledProfile(),
  21. '',
  22. 'flamechart'
  23. );
  24. useProfileGroupSpy.mockImplementation(() => mockUseProfileData);
  25. function assertTableHeaders(headerText: string[]) {
  26. const gridHeadRow = screen.getByTestId('grid-head-row');
  27. headerText.forEach(txt => {
  28. expect(within(gridHeadRow).getByText(txt)).toBeInTheDocument();
  29. });
  30. }
  31. async function selectView(selection: string) {
  32. const dropdownSelect = screen.getByText('View');
  33. userEvent.click(dropdownSelect);
  34. // attempt to select option from the select option list
  35. // not what is being shown as active selection
  36. const option = await screen.findAllByText(selection);
  37. userEvent.click(option[1] ?? option[0]);
  38. }
  39. describe('profileDetailsTable', () => {
  40. it.each([
  41. {
  42. view: 'Slowest Functions',
  43. tableHeaders: [
  44. 'Symbol',
  45. 'Package',
  46. 'File',
  47. 'Thread',
  48. 'Type',
  49. 'Self Weight',
  50. 'Total Weight',
  51. ],
  52. },
  53. {
  54. view: 'Group by Symbol',
  55. tableHeaders: ['Symbol', 'Type', 'Package', 'P75(Self)', 'P95(Self)', 'Count'],
  56. },
  57. {
  58. view: 'Group by Package',
  59. tableHeaders: ['Package', 'Type', 'P75(Self)', 'P95(Self)', 'Count'],
  60. },
  61. {
  62. view: 'Group by File',
  63. tableHeaders: ['File', 'Type', 'P75(Self)', 'P95(Self)', 'Count'],
  64. },
  65. ])('renders the "$view" view', async ({view, tableHeaders}) => {
  66. render(<ProfileDetailsTable />, {
  67. context: routerContext,
  68. });
  69. await selectView(view);
  70. expect(screen.getByTestId('grid-editable')).toBeInTheDocument();
  71. expect(screen.getByText(view)).toBeInTheDocument();
  72. assertTableHeaders(tableHeaders);
  73. });
  74. });