1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192 |
- import {browserHistory} from 'react-router';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import TeamStore from 'sentry/stores/teamStore';
- import {Project} from 'sentry/types';
- import {
- MEPSetting,
- MEPState,
- } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
- import TransactionSummary from 'sentry/views/performance/transactionSummary/transactionOverview';
- const teams = [
- TestStubs.Team({id: '1', slug: 'team1', name: 'Team 1'}),
- TestStubs.Team({id: '2', slug: 'team2', name: 'Team 2'}),
- ];
- function initializeData({
- features: additionalFeatures = [],
- query = {},
- project: prj,
- }: {features?: string[]; project?: Project; query?: Record<string, any>} = {}) {
- const features = ['discover-basic', 'performance-view', ...additionalFeatures];
- const project = prj ?? TestStubs.Project({teams});
- const organization = TestStubs.Organization({
- features,
- projects: [project],
- apdexThreshold: 400,
- });
- const initialData = initializeOrg({
- ...initializeOrg(),
- organization,
- router: {
- location: {
- query: {
- transaction: '/performance',
- project: project.id,
- transactionCursor: '1:0:0',
- ...query,
- },
- },
- },
- });
- ProjectsStore.loadInitialData(initialData.organization.projects);
- TeamStore.loadInitialData(teams, false, null);
- return initialData;
- }
- const TestComponent = ({...props}: React.ComponentProps<typeof TransactionSummary>) => {
- return <TransactionSummary {...props} />;
- };
- describe('Performance > TransactionSummary', function () {
- beforeEach(function () {
- // @ts-ignore no-console
- // eslint-disable-next-line no-console
- jest.spyOn(console, 'error').mockImplementation(jest.fn());
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/user.email/values/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {data: [[123, []]]},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/stats/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/?limit=5&project=2&query=is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/recent-searches/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/recent-searches/',
- method: 'POST',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sdk-updates/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/prompts-activity/',
- body: {},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-facets-performance/',
- body: {},
- });
- // Mock totals for the sidebar and other summary data
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {
- count: 'number',
- apdex: 'number',
- count_miserable_user: 'number',
- user_misery: 'number',
- count_unique_user: 'number',
- p95: 'number',
- failure_rate: 'number',
- tpm: 'number',
- project_threshold_config: 'string',
- },
- data: [
- {
- count: 2,
- apdex: 0.6,
- count_miserable_user: 122,
- user_misery: 0.114,
- count_unique_user: 1,
- p95: 750.123,
- failure_rate: 1,
- tpm: 1,
- project_threshold_config: ['duration', 300],
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('p95()');
- },
- ],
- });
- // Eventsv2 Transaction list response
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
- '<http://localhost/api/0/organizations/org-slug/eventsv2/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
- },
- body: {
- meta: {
- id: 'string',
- 'user.display': 'string',
- 'transaction.duration': 'duration',
- 'project.id': 'integer',
- timestamp: 'date',
- },
- data: [
- {
- id: 'deadbeef',
- 'user.display': 'uhoh@example.com',
- 'transaction.duration': 400,
- 'project.id': 2,
- timestamp: '2020-05-21T15:31:18+00:00',
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('user.display');
- },
- ],
- });
- // Eventsv2 Mock totals for status breakdown
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {
- 'transaction.status': 'string',
- count: 'number',
- },
- data: [
- {
- count: 2,
- 'transaction.status': 'ok',
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('transaction.status');
- },
- ],
- });
- // Events Mock totals for the sidebar and other summary data
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- body: {
- meta: {
- fields: {
- 'count()': 'number',
- 'apdex()': 'number',
- 'count_miserable_user()': 'number',
- 'user_misery()': 'number',
- 'count_unique_user()': 'number',
- 'p95()': 'number',
- 'failure_rate()': 'number',
- 'tpm()': 'number',
- project_threshold_config: 'string',
- },
- },
- data: [
- {
- 'count()': 2,
- 'apdex()': 0.6,
- 'count_miserable_user()': 122,
- 'user_misery()': 0.114,
- 'count_unique_user()': 1,
- 'p95()': 750.123,
- 'failure_rate()': 1,
- 'tpm()': 1,
- project_threshold_config: ['duration', 300],
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('p95()');
- },
- ],
- });
- // Events Transaction list response
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- headers: {
- Link:
- '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
- '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
- },
- body: {
- meta: {
- fields: {
- id: 'string',
- 'user.display': 'string',
- 'transaction.duration': 'duration',
- 'project.id': 'integer',
- timestamp: 'date',
- },
- },
- data: [
- {
- id: 'deadbeef',
- 'user.display': 'uhoh@example.com',
- 'transaction.duration': 400,
- 'project.id': 2,
- timestamp: '2020-05-21T15:31:18+00:00',
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('user.display');
- },
- ],
- });
- // Events Mock totals for status breakdown
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- body: {
- meta: {
- fields: {
- 'transaction.status': 'string',
- 'count()': 'number',
- },
- },
- data: [
- {
- 'count()': 2,
- 'transaction.status': 'ok',
- },
- ],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('transaction.status');
- },
- ],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-facets/',
- body: [
- {
- key: 'release',
- topValues: [{count: 3, value: 'abcd123', name: 'abcd123'}],
- },
- {
- key: 'environment',
- topValues: [{count: 2, value: 'dev', name: 'dev'}],
- },
- {
- key: 'foo',
- topValues: [{count: 1, value: 'bar', name: 'bar'}],
- },
- ],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/project-transaction-threshold-override/',
- method: 'GET',
- body: {
- threshold: '800',
- metric: 'lcp',
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-vitals/',
- body: {
- 'measurements.fcp': {
- poor: 3,
- meh: 100,
- good: 47,
- total: 150,
- p75: 1500,
- },
- 'measurements.lcp': {
- poor: 2,
- meh: 38,
- good: 40,
- total: 80,
- p75: 2750,
- },
- 'measurements.fid': {
- poor: 2,
- meh: 53,
- good: 5,
- total: 60,
- p75: 1000,
- },
- 'measurements.cls': {
- poor: 3,
- meh: 10,
- good: 4,
- total: 17,
- p75: 0.2,
- },
- },
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: `/organizations/org-slug/key-transactions-list/`,
- body: teams.map(({id}) => ({
- team: id,
- count: 0,
- keyed: [],
- })),
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-has-measurements/',
- body: {measurements: false},
- });
- jest.spyOn(MEPSetting, 'get').mockImplementation(() => MEPState.auto);
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- ProjectsStore.reset();
- jest.clearAllMocks();
- // @ts-ignore no-console
- // eslint-disable-next-line no-console
- console.error.mockRestore();
- });
- describe('with eventsv2', function () {
- it('renders basic UI elements', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // It shows the header
- await screen.findByText('Transaction Summary');
- expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
- // It shows a chart
- expect(
- screen.getByRole('button', {name: 'Display Duration Breakdown'})
- ).toBeInTheDocument();
- // It shows a searchbar
- expect(screen.getByLabelText('Search events')).toBeInTheDocument();
- // It shows a table
- expect(screen.getByTestId('transactions-table')).toBeInTheDocument();
- // Ensure open in discover button exists.
- expect(screen.getByTestId('transaction-events-open')).toBeInTheDocument();
- // Ensure open issues button exists.
- expect(screen.getByRole('button', {name: 'Open in Issues'})).toBeInTheDocument();
- // Ensure transaction filter button exists
- expect(screen.getByText('Filter').closest('button')).toBeInTheDocument();
- // Ensure create alert from discover is hidden without metric alert
- expect(
- screen.queryByRole('button', {name: 'Create Alert'})
- ).not.toBeInTheDocument();
- // Ensure status breakdown exists
- expect(screen.getByText('Status Breakdown')).toBeInTheDocument();
- });
- it('renders feature flagged UI elements', function () {
- const {organization, router, routerContext} = initializeData({
- features: ['incidents'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Ensure create alert from discover is shown with metric alerts
- expect(screen.getByRole('button', {name: 'Create Alert'})).toBeInTheDocument();
- });
- it('renders Web Vitals widget', async function () {
- const {organization, router, routerContext} = initializeData({
- project: TestStubs.Project({teams, platform: 'javascript'}),
- query: {
- query:
- 'transaction.duration:<15m transaction.op:pageload event.type:transaction transaction:/organizations/:orgId/issues/',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // It renders the web vitals widget
- await screen.findByRole('heading', {name: 'Web Vitals'});
- const vitalStatues = screen.getAllByTestId('vital-status');
- expect(vitalStatues).toHaveLength(3);
- expect(vitalStatues[0]).toHaveTextContent('31%');
- expect(vitalStatues[1]).toHaveTextContent('65%');
- expect(vitalStatues[2]).toHaveTextContent('3%');
- });
- it('renders sidebar widgets', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Renders Apdex widget
- await screen.findByRole('heading', {name: 'Apdex'});
- expect(screen.getByTestId('apdex-summary-value')).toHaveTextContent('0.6');
- // Renders Failure Rate widget
- expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
- expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
- // Renders TPM widget
- expect(screen.getByRole('heading', {name: 'TPM'})).toBeInTheDocument();
- expect(screen.getByTestId('tpm-summary-value')).toHaveTextContent('1 tpm');
- });
- it('fetches transaction threshold', function () {
- const {organization, router, routerContext} = initializeData();
- const getTransactionThresholdMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/project-transaction-threshold-override/',
- method: 'GET',
- body: {
- threshold: '800',
- metric: 'lcp',
- },
- });
- const getProjectThresholdMock = MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
- method: 'GET',
- body: {
- threshold: '200',
- metric: 'duration',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
- expect(getProjectThresholdMock).not.toHaveBeenCalled();
- });
- it('fetches project transaction threshdold', async function () {
- const {organization, router, routerContext} = initializeData();
- const getTransactionThresholdMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/project-transaction-threshold-override/',
- method: 'GET',
- statusCode: 404,
- });
- const getProjectThresholdMock = MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
- method: 'GET',
- body: {
- threshold: '200',
- metric: 'duration',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
- expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
- });
- it('triggers a navigation on search', function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Fill out the search box, and submit it.
- userEvent.type(screen.getByLabelText('Search events'), 'user.email:uhoh*{enter}');
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledTimes(1);
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- statsPeriod: '14d',
- query: 'user.email:uhoh*',
- transactionCursor: '1:0:0',
- },
- });
- });
- it('can mark a transaction as key', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- const mockUpdate = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/key-transactions/`,
- method: 'POST',
- body: {},
- });
- await screen.findByRole('button', {name: 'Star for Team'});
- // Click the key transaction button
- userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
- userEvent.click(screen.getByText('team1'), undefined, {
- skipPointerEventsCheck: true,
- });
- // Ensure request was made.
- expect(mockUpdate).toHaveBeenCalled();
- });
- it('triggers a navigation on transaction filter', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- // Open the transaction filter dropdown
- userEvent.click(
- screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
- );
- userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- showTransactions: 'slow',
- transactionCursor: undefined,
- },
- });
- });
- it('renders pagination buttons', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(screen.getByLabelText('Previous')).toBeInTheDocument();
- // Click the 'next' button
- userEvent.click(screen.getByLabelText('Next'));
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- transactionCursor: '2:0:0',
- },
- });
- });
- it('forwards conditions to related issues', async function () {
- const issueGet = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
- body: [],
- });
- const {organization, router, routerContext} = initializeData({
- query: {query: 'tag:value'},
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(issueGet).toHaveBeenCalled();
- });
- it('does not forward event type to related issues', async function () {
- const issueGet = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
- body: [],
- match: [
- (_, options) => {
- // event.type must NOT be in the query params
- return !options.query?.query?.includes('event.type');
- },
- ],
- });
- const {organization, router, routerContext} = initializeData({
- query: {query: 'tag:value event.type:transaction'},
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(issueGet).toHaveBeenCalled();
- });
- it('renders the suspect spans table if the feature is enabled', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-spans-performance/',
- body: [],
- });
- const {organization, router, routerContext} = initializeData({
- features: ['performance-suspect-spans-view'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
- });
- it('adds search condition on transaction status when clicking on status breakdown', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByTestId('status-ok');
- userEvent.click(screen.getByTestId('status-ok'));
- expect(browserHistory.push).toHaveBeenCalledTimes(1);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- query: expect.objectContaining({
- query: expect.stringContaining('transaction.status:ok'),
- }),
- })
- );
- });
- it('appends tag value to existing query when clicked', async function () {
- const {organization, router, routerContext} = initializeData();
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Tag Summary');
- userEvent.click(
- screen.getByLabelText('Add the dev segment tag to the search query')
- );
- userEvent.click(
- screen.getByLabelText('Add the bar segment tag to the search query')
- );
- expect(router.push).toHaveBeenCalledTimes(2);
- expect(router.push).toHaveBeenNthCalledWith(1, {
- query: {
- project: '2',
- query: 'tags[environment]:dev',
- transaction: '/performance',
- transactionCursor: '1:0:0',
- },
- });
- expect(router.push).toHaveBeenNthCalledWith(2, {
- query: {
- project: '2',
- query: 'foo:bar',
- transaction: '/performance',
- transactionCursor: '1:0:0',
- },
- });
- });
- });
- describe('with events', function () {
- it('renders basic UI elements', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // It shows the header
- await screen.findByText('Transaction Summary');
- expect(screen.getByRole('heading', {name: '/performance'})).toBeInTheDocument();
- // It shows a chart
- expect(
- screen.getByRole('button', {name: 'Display Duration Breakdown'})
- ).toBeInTheDocument();
- // It shows a searchbar
- expect(screen.getByLabelText('Search events')).toBeInTheDocument();
- // It shows a table
- expect(screen.getByTestId('transactions-table')).toBeInTheDocument();
- // Ensure open in discover button exists.
- expect(screen.getByTestId('transaction-events-open')).toBeInTheDocument();
- // Ensure open issues button exists.
- expect(screen.getByRole('button', {name: 'Open in Issues'})).toBeInTheDocument();
- // Ensure transaction filter button exists
- expect(screen.getByText('Filter').closest('button')).toBeInTheDocument();
- // Ensure create alert from discover is hidden without metric alert
- expect(
- screen.queryByRole('button', {name: 'Create Alert'})
- ).not.toBeInTheDocument();
- // Ensure status breakdown exists
- expect(screen.getByText('Status Breakdown')).toBeInTheDocument();
- });
- it('renders feature flagged UI elements', function () {
- const {organization, router, routerContext} = initializeData({
- features: ['incidents', 'performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Ensure create alert from discover is shown with metric alerts
- expect(screen.getByRole('button', {name: 'Create Alert'})).toBeInTheDocument();
- });
- it('renders Web Vitals widget', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- project: TestStubs.Project({teams, platform: 'javascript'}),
- query: {
- query:
- 'transaction.duration:<15m transaction.op:pageload event.type:transaction transaction:/organizations/:orgId/issues/',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // It renders the web vitals widget
- await screen.findByRole('heading', {name: 'Web Vitals'});
- const vitalStatues = screen.getAllByTestId('vital-status');
- expect(vitalStatues).toHaveLength(3);
- expect(vitalStatues[0]).toHaveTextContent('31%');
- expect(vitalStatues[1]).toHaveTextContent('65%');
- expect(vitalStatues[2]).toHaveTextContent('3%');
- });
- it('renders sidebar widgets', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Renders Apdex widget
- await screen.findByRole('heading', {name: 'Apdex'});
- expect(screen.getByTestId('apdex-summary-value')).toHaveTextContent('0.6');
- // Renders Failure Rate widget
- expect(screen.getByRole('heading', {name: 'Failure Rate'})).toBeInTheDocument();
- expect(screen.getByTestId('failure-rate-summary-value')).toHaveTextContent('100%');
- // Renders TPM widget
- expect(screen.getByRole('heading', {name: 'TPM'})).toBeInTheDocument();
- expect(screen.getByTestId('tpm-summary-value')).toHaveTextContent('1 tpm');
- });
- it('fetches transaction threshold', function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- const getTransactionThresholdMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/project-transaction-threshold-override/',
- method: 'GET',
- body: {
- threshold: '800',
- metric: 'lcp',
- },
- });
- const getProjectThresholdMock = MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
- method: 'GET',
- body: {
- threshold: '200',
- metric: 'duration',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
- expect(getProjectThresholdMock).not.toHaveBeenCalled();
- });
- it('fetches project transaction threshdold', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- const getTransactionThresholdMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/project-transaction-threshold-override/',
- method: 'GET',
- statusCode: 404,
- });
- const getProjectThresholdMock = MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/transaction-threshold/configure/',
- method: 'GET',
- body: {
- threshold: '200',
- metric: 'duration',
- },
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(getTransactionThresholdMock).toHaveBeenCalledTimes(1);
- expect(getProjectThresholdMock).toHaveBeenCalledTimes(1);
- });
- it('triggers a navigation on search', function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- // Fill out the search box, and submit it.
- userEvent.type(screen.getByLabelText('Search events'), 'user.email:uhoh*{enter}');
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledTimes(1);
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- statsPeriod: '14d',
- query: 'user.email:uhoh*',
- transactionCursor: '1:0:0',
- },
- });
- });
- it('can mark a transaction as key', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- const mockUpdate = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/key-transactions/`,
- method: 'POST',
- body: {},
- });
- await screen.findByRole('button', {name: 'Star for Team'});
- // Click the key transaction button
- userEvent.click(screen.getByRole('button', {name: 'Star for Team'}));
- userEvent.click(screen.getByText('team1'), undefined, {
- skipPointerEventsCheck: true,
- });
- // Ensure request was made.
- expect(mockUpdate).toHaveBeenCalled();
- });
- it('triggers a navigation on transaction filter', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- // Open the transaction filter dropdown
- userEvent.click(
- screen.getByRole('button', {name: 'Filter Slow Transactions (p95)'})
- );
- userEvent.click(screen.getAllByText('Slow Transactions (p95)')[1]);
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- showTransactions: 'slow',
- transactionCursor: undefined,
- },
- });
- });
- it('renders pagination buttons', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(screen.getByLabelText('Previous')).toBeInTheDocument();
- // Click the 'next' button
- userEvent.click(screen.getByLabelText('Next'));
- // Check the navigation.
- expect(browserHistory.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- transaction: '/performance',
- project: '2',
- transactionCursor: '2:0:0',
- },
- });
- });
- it('forwards conditions to related issues', async function () {
- const issueGet = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
- body: [],
- });
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- query: {query: 'tag:value'},
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(issueGet).toHaveBeenCalled();
- });
- it('does not forward event type to related issues', async function () {
- const issueGet = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/?limit=5&project=2&query=tag%3Avalue%20is%3Aunresolved%20transaction%3A%2Fperformance&sort=new&statsPeriod=14d',
- body: [],
- match: [
- (_, options) => {
- // event.type must NOT be in the query params
- return !options.query?.query?.includes('event.type');
- },
- ],
- });
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- query: {query: 'tag:value event.type:transaction'},
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Transaction Summary');
- expect(issueGet).toHaveBeenCalled();
- });
- it('renders the suspect spans table if the feature is enabled', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-spans-performance/',
- body: [],
- });
- const {organization, router, routerContext} = initializeData({
- features: [
- 'performance-suspect-spans-view',
- 'performance-frontend-use-events-endpoint',
- ],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- expect(await screen.findByText('Suspect Spans')).toBeInTheDocument();
- });
- it('adds search condition on transaction status when clicking on status breakdown', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByTestId('status-ok');
- userEvent.click(screen.getByTestId('status-ok'));
- expect(browserHistory.push).toHaveBeenCalledTimes(1);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- query: expect.objectContaining({
- query: expect.stringContaining('transaction.status:ok'),
- }),
- })
- );
- });
- it('appends tag value to existing query when clicked', async function () {
- const {organization, router, routerContext} = initializeData({
- features: ['performance-frontend-use-events-endpoint'],
- });
- render(<TestComponent location={router.location} />, {
- context: routerContext,
- organization,
- });
- await screen.findByText('Tag Summary');
- userEvent.click(
- screen.getByLabelText('Add the dev segment tag to the search query')
- );
- userEvent.click(
- screen.getByLabelText('Add the bar segment tag to the search query')
- );
- expect(router.push).toHaveBeenCalledTimes(2);
- expect(router.push).toHaveBeenNthCalledWith(1, {
- query: {
- project: '2',
- query: 'tags[environment]:dev',
- transaction: '/performance',
- transactionCursor: '1:0:0',
- },
- });
- expect(router.push).toHaveBeenNthCalledWith(2, {
- query: {
- project: '2',
- query: 'foo:bar',
- transaction: '/performance',
- transactionCursor: '1:0:0',
- },
- });
- });
- });
- });
|