123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {act, render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
- import type {PlatformKey} from 'sentry/types/project';
- import EventView from 'sentry/utils/discover/eventView';
- import TransactionHeader from 'sentry/views/performance/transactionSummary/header';
- import Tab from 'sentry/views/performance/transactionSummary/tabs';
- type InitialOpts = {
- features?: string[];
- platform?: PlatformKey;
- };
- function initializeData(opts?: InitialOpts) {
- const {features, platform} = opts ?? {};
- const project = ProjectFixture({platform});
- const organization = OrganizationFixture({
- features: features ?? [],
- });
- const initialData = initializeOrg({
- organization,
- router: {
- location: {
- query: {
- project: project.id,
- },
- },
- },
- projects: [],
- });
- const router = initialData.router;
- const eventView = EventView.fromSavedQuery({
- id: undefined,
- version: 2,
- name: '',
- fields: ['transaction.status'], // unused fields
- projects: [parseInt(project.id, 10)],
- });
- return {
- project,
- organization,
- router,
- eventView,
- };
- }
- describe('Performance > Transaction Summary Header', function () {
- beforeEach(function () {
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/replay-count/',
- body: {},
- });
- });
- it('should render web vitals tab when yes', async function () {
- const {project, organization, router, eventView} = initializeData();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: true},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="yes"
- />
- );
- expect(await screen.findByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
- });
- it('should not render web vitals tab when hasWebVitals=no', async function () {
- const {project, organization, router, eventView} = initializeData();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: true},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="no"
- />
- );
- await act(tick);
- expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
- });
- it('should render web vitals tab when maybe and is frontend platform', async function () {
- const {project, organization, router, eventView} = initializeData({
- platform: 'javascript',
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: true},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="maybe"
- />
- );
- expect(await screen.findByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
- });
- it('should render web vitals tab when maybe and has measurements', async function () {
- const {project, organization, router, eventView} = initializeData();
- const eventHasMeasurementsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: true},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="maybe"
- />
- );
- await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
- expect(screen.getByRole('tab', {name: 'Web Vitals'})).toBeInTheDocument();
- });
- it('should not render web vitals tab when maybe and has no measurements', async function () {
- const {project, organization, router, eventView} = initializeData();
- const eventHasMeasurementsMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: false},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/replay-count/',
- body: {},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="maybe"
- />
- );
- await waitFor(() => expect(eventHasMeasurementsMock).toHaveBeenCalled());
- expect(screen.queryByRole('tab', {name: 'Web Vitals'})).not.toBeInTheDocument();
- });
- it('should render spans tab with feature', async function () {
- const {project, organization, router, eventView} = initializeData({});
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: true},
- });
- render(
- <TransactionHeader
- eventView={eventView}
- location={router.location}
- organization={organization}
- projects={[project]}
- projectId={project.id}
- transactionName="transaction_name"
- currentTab={Tab.TRANSACTION_SUMMARY}
- hasWebVitals="yes"
- />
- );
- expect(await screen.findByRole('tab', {name: 'Spans'})).toBeInTheDocument();
- });
- });
|