domainViewHeader.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import type {Location, Query} from 'history';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import {DomainViewHeader} from 'sentry/views/insights/pages/domainViewHeader';
  7. import {ModuleName} from 'sentry/views/insights/types';
  8. jest.mock('sentry/utils/useLocation');
  9. jest.mock('sentry/utils/useOrganization');
  10. const useLocationMock = jest.mocked(useLocation);
  11. describe('DomainViewHeader', function () {
  12. const organization = OrganizationFixture({
  13. features: ['insights-entry-points', 'insights-mobile-screens-module'],
  14. });
  15. beforeEach(() => {
  16. jest.resetAllMocks();
  17. useLocationMock.mockReturnValue({
  18. pathname: '/organizations/org-slug/insights/frontend/',
  19. } as Location);
  20. jest.mocked(useOrganization).mockReturnValue(organization);
  21. });
  22. it('renders', () => {
  23. render(
  24. <DomainViewHeader
  25. domainBaseUrl="domainBaseUrl"
  26. domainTitle="domainTitle"
  27. modules={[ModuleName.HTTP]}
  28. selectedModule={undefined}
  29. />
  30. );
  31. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  32. expect(screen.getByRole('tab', {name: 'Overview'})).toBeInTheDocument();
  33. expect(screen.getByRole('tab', {name: 'Network Requests'})).toBeInTheDocument();
  34. });
  35. it('renders link with page filters', () => {
  36. useLocationMock.mockClear();
  37. useLocationMock.mockReturnValue({
  38. pathname: '/organizations/org-slug/insights/frontend/',
  39. query: {
  40. project: ['1'],
  41. environment: ['prod'],
  42. statsPeriod: '14d',
  43. transaction: '123',
  44. } as Query,
  45. } as Location);
  46. render(
  47. <DomainViewHeader
  48. domainBaseUrl="domainBaseUrl"
  49. domainTitle="domainTitle"
  50. modules={[ModuleName.HTTP]}
  51. selectedModule={undefined}
  52. />
  53. );
  54. const overviewTab = screen.getByRole('tab', {name: 'Overview'});
  55. const networkRequestsTab = screen.getByRole('tab', {name: 'Network Requests'});
  56. expect(overviewTab.firstChild).toHaveAttribute(
  57. 'href',
  58. '/domainBaseUrl?environment=prod&project=1&statsPeriod=14d'
  59. );
  60. expect(networkRequestsTab.firstChild).toHaveAttribute(
  61. 'href',
  62. '/organizations/org-slug/insights/frontend/http/?environment=prod&project=1&statsPeriod=14d'
  63. );
  64. });
  65. it('does not show network requests without features', () => {
  66. jest.mocked(useOrganization).mockReturnValue(OrganizationFixture());
  67. render(
  68. <DomainViewHeader
  69. domainBaseUrl="domainBaseUrl"
  70. domainTitle="domainTitle"
  71. modules={[ModuleName.HTTP]}
  72. selectedModule={undefined}
  73. />
  74. );
  75. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  76. expect(screen.getByRole('tab', {name: 'Overview'})).toBeInTheDocument();
  77. expect(screen.queryByRole('tab', {name: 'Network Requests'})).not.toBeInTheDocument();
  78. });
  79. it('does not show overview tab with hasOverviewPage=false', () => {
  80. render(
  81. <DomainViewHeader
  82. domainBaseUrl="domainBaseUrl"
  83. domainTitle="domainTitle"
  84. modules={[ModuleName.HTTP]}
  85. selectedModule={undefined}
  86. hasOverviewPage={false}
  87. />
  88. );
  89. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  90. expect(screen.queryByRole('tab', {name: 'Overview'})).not.toBeInTheDocument();
  91. expect(screen.getByRole('tab', {name: 'Network Requests'})).toBeInTheDocument();
  92. });
  93. it('renders a new badge only for mobile vitals', () => {
  94. render(
  95. <DomainViewHeader
  96. domainBaseUrl="domainBaseUrl"
  97. domainTitle="domainTitle"
  98. modules={[ModuleName.HTTP, ModuleName.MOBILE_VITALS]}
  99. selectedModule={undefined}
  100. hasOverviewPage={false}
  101. />
  102. );
  103. expect(screen.getByRole('tab', {name: 'Mobile Vitals New'})).toBeInTheDocument();
  104. expect(screen.getByRole('tab', {name: 'Network Requests'})).toBeInTheDocument();
  105. expect(
  106. screen.queryByRole('tab', {name: 'Network Requests New'})
  107. ).not.toBeInTheDocument();
  108. });
  109. });