domainViewHeader.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import type {Location} 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. describe('DomainViewHeader', function () {
  11. const organization = OrganizationFixture({
  12. features: ['insights-entry-points'],
  13. });
  14. beforeEach(() => {
  15. jest.resetAllMocks();
  16. jest.mocked(useLocation).mockReturnValue({
  17. pathname: '/organizations/org-slug/insights/frontend/',
  18. } as Location);
  19. jest.mocked(useOrganization).mockReturnValue(organization);
  20. });
  21. it('renders', () => {
  22. render(
  23. <DomainViewHeader
  24. domainBaseUrl="domainBaseUrl"
  25. domainTitle="domainTitle"
  26. modules={[ModuleName.HTTP]}
  27. selectedModule={undefined}
  28. />
  29. );
  30. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  31. expect(screen.getByRole('tab', {name: 'Overview'})).toBeInTheDocument();
  32. expect(screen.getByRole('tab', {name: 'Network Requests'})).toBeInTheDocument();
  33. });
  34. it('does not show network requests without features', () => {
  35. jest.mocked(useOrganization).mockReturnValue(OrganizationFixture());
  36. render(
  37. <DomainViewHeader
  38. domainBaseUrl="domainBaseUrl"
  39. domainTitle="domainTitle"
  40. modules={[ModuleName.HTTP]}
  41. selectedModule={undefined}
  42. />
  43. );
  44. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  45. expect(screen.getByRole('tab', {name: 'Overview'})).toBeInTheDocument();
  46. expect(screen.queryByRole('tab', {name: 'Network Requests'})).not.toBeInTheDocument();
  47. });
  48. it('does not show overview tab with hasOverviewPage=false', () => {
  49. render(
  50. <DomainViewHeader
  51. domainBaseUrl="domainBaseUrl"
  52. domainTitle="domainTitle"
  53. modules={[ModuleName.HTTP]}
  54. selectedModule={undefined}
  55. hasOverviewPage={false}
  56. />
  57. );
  58. expect(screen.getByText('domainTitle')).toBeInTheDocument();
  59. expect(screen.queryByRole('tab', {name: 'Overview'})).not.toBeInTheDocument();
  60. expect(screen.getByRole('tab', {name: 'Network Requests'})).toBeInTheDocument();
  61. });
  62. });