123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import QuickTrace from 'sentry/components/quickTrace';
- import {Event} from 'sentry/types/event';
- import {QuickTraceEvent} from 'sentry/utils/performance/quickTrace/types';
- describe('Quick Trace', function () {
- let location;
- let organization;
- const initialize = () => {
- const context = initializeOrg();
- organization = context.organization;
- };
- function makeQuickTraceEvents(generation, {n = 1, parentId = null} = {}) {
- const events: QuickTraceEvent[] = [];
- for (let i = 0; i < n; i++) {
- const suffix = n > 1 ? `-${i}` : '';
- events.push({
- event_id: `e${generation}${suffix}`,
- generation,
- span_id: `s${generation}${suffix}`,
- transaction: `t${generation}${suffix}`,
- 'transaction.duration': 1234,
- project_id: generation,
- project_slug: `p${generation}`,
- parent_event_id:
- generation === 0 ? null : parentId === null ? `e${generation - 1}` : parentId,
- parent_span_id:
- generation === 0
- ? null
- : parentId === null
- ? `s${generation - 1}${parentId}`
- : `s${parentId}`,
- });
- }
- return events;
- }
- function makeTransactionEvent(id) {
- return {
- id: `e${id}`,
- type: 'transaction',
- startTimestamp: 1615921516.132774,
- endTimestamp: 1615921517.924861,
- };
- }
- function makeTransactionHref(
- pid: string,
- eid: string,
- transaction: string,
- project: string
- ) {
- return `/organizations/${organization.slug}/performance/${pid}:${eid}/?project=${project}&transaction=${transaction}`;
- }
- beforeEach(function () {
- initialize();
- location = {
- pathname: '/',
- query: {},
- };
- });
- describe('Empty Trace', function () {
- it('renders nothing for empty trace', function () {
- const {container} = render(
- <QuickTrace
- event={makeTransactionEvent(1) as Event}
- quickTrace={{
- type: 'empty',
- trace: [],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- expect(container).toHaveTextContent('\u2014');
- });
- });
- describe('Partial Trace', function () {
- it('renders nothing when partial trace is empty', function () {
- const {container} = render(
- <QuickTrace
- event={makeTransactionEvent(1) as Event}
- quickTrace={{
- type: 'partial',
- trace: null,
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- expect(container).toHaveTextContent('\u2014');
- });
- it('renders nothing when partial trace missing current event', function () {
- const {container} = render(
- <QuickTrace
- event={makeTransactionEvent('not-1') as Event}
- quickTrace={{
- type: 'partial',
- trace: makeQuickTraceEvents(1),
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- expect(container).toHaveTextContent('\u2014');
- });
- // TODO
- it('renders partial trace with no children', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(4) as Event}
- quickTrace={{
- type: 'partial',
- trace: makeQuickTraceEvents(4),
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(1);
- expect(nodes[0]).toHaveTextContent('This Event');
- });
- it('renders partial trace with single child', async function () {
- render(
- <QuickTrace
- event={makeTransactionEvent(4) as Event}
- quickTrace={{
- type: 'partial',
- trace: [...makeQuickTraceEvents(4), ...makeQuickTraceEvents(5)],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(2);
- ['This Event', '1 Child'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders partial trace with multiple children', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(4) as Event}
- quickTrace={{
- type: 'partial',
- trace: [...makeQuickTraceEvents(4), ...makeQuickTraceEvents(5, {n: 3})],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(2);
- ['This Event', '3 Children'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders full trace with root as parent', async function () {
- render(
- <QuickTrace
- event={makeTransactionEvent(1) as Event}
- quickTrace={{
- type: 'partial',
- trace: [...makeQuickTraceEvents(0), ...makeQuickTraceEvents(1)],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(2);
- ['Parent', 'This Event'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- });
- describe('Full Trace', function () {
- it('renders full trace with single ancestor', async function () {
- render(
- <QuickTrace
- event={makeTransactionEvent(3) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ...makeQuickTraceEvents(3),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(4);
- ['Root', '1 Ancestor', 'Parent', 'This Event'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders full trace with multiple ancestors', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(5) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ...makeQuickTraceEvents(3),
- ...makeQuickTraceEvents(4),
- ...makeQuickTraceEvents(5),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(4);
- ['Root', '3 Ancestors', 'Parent', 'This Event'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders full trace with single descendant', async function () {
- render(
- <QuickTrace
- event={makeTransactionEvent(0) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(3);
- ['This Event', '1 Child', '1 Descendant'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders full trace with multiple descendants', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(0) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ...makeQuickTraceEvents(3),
- ...makeQuickTraceEvents(4),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(3);
- ['This Event', '1 Child', '3 Descendants'].forEach((text, i) =>
- expect(nodes[i]).toHaveTextContent(text)
- );
- });
- it('renders full trace', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(5) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ...makeQuickTraceEvents(3),
- ...makeQuickTraceEvents(4),
- ...makeQuickTraceEvents(5),
- ...makeQuickTraceEvents(6),
- ...makeQuickTraceEvents(7),
- ...makeQuickTraceEvents(8),
- ...makeQuickTraceEvents(9),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(6);
- ['Root', '3 Ancestors', 'Parent', 'This Event', '1 Child', '3 Descendants'].forEach(
- (text, i) => expect(nodes[i]).toHaveTextContent(text)
- );
- });
- });
- describe('Event Node Clicks', function () {
- it('renders single event targets', async function () {
- const routerContext = TestStubs.routerContext();
- render(
- <QuickTrace
- event={makeTransactionEvent(3) as Event}
- quickTrace={{
- type: 'full',
- trace: [
- ...makeQuickTraceEvents(0),
- ...makeQuickTraceEvents(1),
- ...makeQuickTraceEvents(2),
- ...makeQuickTraceEvents(3),
- ...makeQuickTraceEvents(4),
- ...makeQuickTraceEvents(5),
- ],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />,
- {context: routerContext}
- );
- const nodes = await screen.findAllByTestId('event-node');
- expect(nodes.length).toEqual(6);
- [
- makeTransactionHref('p0', 'e0', 't0', '0'),
- makeTransactionHref('p1', 'e1', 't1', '1'),
- makeTransactionHref('p2', 'e2', 't2', '2'),
- undefined, // the "This Event" node has no target
- makeTransactionHref('p4', 'e4', 't4', '4'),
- makeTransactionHref('p5', 'e5', 't5', '5'),
- ].forEach((target, i) => {
- const linkNode = nodes[i].children[0];
- if (target) {
- expect(linkNode).toHaveAttribute('href', target);
- } else {
- expect(linkNode).not.toHaveAttribute('href');
- }
- });
- });
- it('renders multiple event targets', async function () {
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/projects/`,
- body: [],
- });
- render(
- <QuickTrace
- event={makeTransactionEvent(0) as Event}
- quickTrace={{
- type: 'full',
- trace: [...makeQuickTraceEvents(0), ...makeQuickTraceEvents(1, {n: 3})],
- }}
- anchor="left"
- errorDest="issue"
- transactionDest="performance"
- location={location}
- organization={organization}
- />
- );
- const items = await screen.findAllByTestId('dropdown-item');
- expect(items.length).toEqual(3);
- // can't easily assert the target is correct since it uses an onClick handler
- });
- });
- });
|