123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- import {browserHistory} from 'react-router';
- import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
- import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
- import ConfigStore from 'sentry/stores/configStore';
- import {Commit, Repository, User} from 'sentry/types';
- import {
- EntryType,
- Event,
- EventError,
- EventOrGroupType,
- ExceptionType,
- ExceptionValue,
- Frame,
- } from 'sentry/types/event';
- import EventView, {EventData} from 'sentry/utils/discover/eventView';
- import {useLocation} from 'sentry/utils/useLocation';
- import {ContextType, QuickContextHoverWrapper} from './quickContext';
- const defaultRow: EventData = {
- id: '6b43e285de834ec5b5fe30d62d549b20',
- issue: 'SENTRY-VVY',
- release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
- title: 'error: Error -3 while decompressing data: invalid stored block lengths',
- 'issue.id': 3512441874,
- 'project.name': 'sentry',
- };
- let mockedGroup = TestStubs.Group({
- id: '3512441874',
- project: {
- id: '1',
- slug: 'cool-team',
- },
- status: 'ignored',
- assignedTo: {
- id: '12312',
- name: 'ingest',
- type: 'team',
- },
- });
- const mockEventView = EventView.fromSavedQuery({
- id: '',
- name: 'test query',
- version: 2,
- fields: ['title', 'issue'],
- projects: [1],
- });
- const mockedCommit: Commit = {
- dateCreated: '2020-11-30T18:46:31Z',
- id: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
- message: 'ref(commitRow): refactor to fc\n',
- author: {
- id: '0',
- username: 'author',
- ip_address: '192.168.1.1',
- email: 'author@commit.com',
- name: 'Author',
- } as User,
- repository: {
- id: '1',
- integrationId: '2',
- name: 'getsentry/sentry',
- dateCreated: '2019-11-30T18:46:31Z',
- } as Repository,
- releases: [],
- };
- const mockedUser1 = {
- id: '2',
- username: 'author456',
- ip_address: '192.168.1.1',
- email: 'author1@commit.com',
- name: 'Key Name',
- } as User;
- const mockedUser2 = {
- id: '3',
- username: 'author123',
- ip_address: '192.168.1.3',
- email: 'author2@commit.com',
- name: 'Value Name',
- } as User;
- const mockedReleaseWithHealth = TestStubs.Release({
- id: '1',
- shortVersion: 'sentry-android-shop@1.2.0',
- version: 'sentry-android-shop@1.2.0',
- dateCreated: '2010-05-17T02:41:20Z',
- lastEvent: '2011-10-17T02:41:20Z',
- firstEvent: '2010-05-17T02:41:20Z',
- status: 'open',
- commitCount: 4,
- lastCommit: mockedCommit,
- newGroups: 21,
- authors: [mockedUser1, mockedUser2],
- });
- const queryClient = new QueryClient();
- const renderQuickContextContent = (
- dataRow: EventData = defaultRow,
- contextType: ContextType = ContextType.ISSUE,
- eventView?: EventView
- ) => {
- const organization = TestStubs.Organization();
- render(
- <QueryClientProvider client={queryClient}>
- <QuickContextHoverWrapper
- dataRow={dataRow}
- contextType={contextType}
- organization={organization}
- eventView={eventView}
- >
- Text from Child
- </QuickContextHoverWrapper>
- </QueryClientProvider>,
- {organization}
- );
- };
- const makeEvent = (event: Partial<Event> = {}): Event => {
- const evt: Event = {
- ...TestStubs.Event(),
- ...event,
- };
- return evt;
- };
- jest.mock('sentry/utils/useLocation');
- const mockUseLocation = useLocation as jest.MockedFunction<typeof useLocation>;
- describe('Quick Context', function () {
- describe('Quick Context default behaviour', function () {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/events/oldest/',
- method: 'GET',
- body: [],
- });
- });
- afterEach(() => {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- mockUseLocation.mockReset();
- });
- it('Renders child', async () => {
- renderQuickContextContent();
- expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
- });
- it('Renders quick context hover body', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByTestId('quick-context-hover-body')).toBeInTheDocument();
- });
- it('Renders quick context failure message', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- statusCode: 400,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- // Error is expected, do not fail when calling console.error
- jest.spyOn(console, 'error').mockImplementation();
- expect(
- await screen.findByText(/Failed to load context for column./i)
- ).toBeInTheDocument();
- });
- });
- describe('Quick Context Content Issue Column', function () {
- beforeEach(() => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/events/oldest/',
- method: 'GET',
- body: [],
- });
- });
- afterEach(function () {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- });
- it('Renders issue context header with copy button', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Issue/i)).toBeInTheDocument();
- expect(screen.getByText(/SENTRY-VVY/i)).toBeInTheDocument();
- expect(
- screen.getByTestId('quick-context-hover-header-copy-icon')
- ).toBeInTheDocument();
- });
- it('Renders ignored Issue status context when data is loaded', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Ignored/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-ignored-icon')).toBeInTheDocument();
- });
- it('Renders resolved Issue status context when data is loaded', async () => {
- mockedGroup = {...mockedGroup, status: 'resolved'};
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Resolved/i)).toBeInTheDocument();
- expect(screen.getByTestId('icon-check-mark')).toBeInTheDocument();
- });
- it('Renders unresolved Issue status context when data is loaded', async () => {
- mockedGroup = {...mockedGroup, status: 'unresolved'};
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
- expect(screen.getByText(/Unresolved/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-unresolved-icon')).toBeInTheDocument();
- });
- it('Renders assigned To context when data is loaded', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Assigned To/i)).toBeInTheDocument();
- expect(screen.getByText(/#ingest/i)).toBeInTheDocument();
- });
- it('Renders Suspect Commits', async () => {
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/',
- method: 'GET',
- body: mockedGroup,
- });
- MockApiClient.addMockResponse({
- url: '/issues/3512441874/events/oldest/',
- method: 'GET',
- body: {
- eventID: '6b43e285de834ec5b5fe30d62d549b20',
- },
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
- body: {
- committers: [
- {
- author: {name: 'Max Bittker', id: '1'},
- commits: [
- {
- message: 'feat: Added new feature',
- score: 4,
- id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
- repository: TestStubs.Repository(),
- dateCreated: '2018-03-02T18:30:26Z',
- pullRequest: {
- externalUrl: 'url',
- },
- },
- ],
- },
- ],
- },
- });
- renderQuickContextContent();
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Suspect Commits/i)).toBeInTheDocument();
- expect(screen.getByText(/MB/i)).toBeInTheDocument();
- expect(screen.getByText(/View commit/i)).toBeInTheDocument();
- expect(screen.getByText(/by/i)).toBeInTheDocument();
- expect(screen.getByText(/You/i)).toBeInTheDocument();
- });
- });
- describe('Quick Context Content Release Column', function () {
- afterEach(() => {
- queryClient.clear();
- MockApiClient.clearMockResponses();
- });
- it('Renders release header with copy button', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Release/i)).toBeInTheDocument();
- expect(screen.getByText(/22.10.0/i)).toBeInTheDocument();
- expect(screen.getByText(/(aaf33944f93d)/i)).toBeInTheDocument();
- expect(
- screen.getByTestId('quick-context-hover-header-copy-icon')
- ).toBeInTheDocument();
- });
- it('Renders Release details for release', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Created/i)).toBeInTheDocument();
- expect(screen.getByText(/7 years ago/i)).toBeInTheDocument();
- expect(screen.getByText(/Last Event/i)).toBeInTheDocument();
- expect(screen.getByText(/6 years ago/i)).toBeInTheDocument();
- expect(screen.getByText(/New Issues/i)).toBeInTheDocument();
- expect(screen.getByText(/21/i)).toBeInTheDocument();
- });
- it('Renders Last Commit', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Last Commit/i)).toBeInTheDocument();
- expect(screen.getByTestId('quick-context-commit-row')).toBeInTheDocument();
- });
- it('Renders Commit Count and Author when user is NOT in list of authors', async () => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByText('Text from Child'));
- const authorsSectionHeader = within(
- await screen.findByTestId('quick-context-release-author-header')
- );
- expect(authorsSectionHeader.getByText(/4/i)).toBeInTheDocument();
- expect(authorsSectionHeader.getByText(/commits by/i)).toBeInTheDocument();
- expect(authorsSectionHeader.getByText(/2/i)).toBeInTheDocument();
- expect(authorsSectionHeader.getByText(/authors/i)).toBeInTheDocument();
- expect(screen.getByText(/KN/i)).toBeInTheDocument();
- expect(screen.getByText(/VN/i)).toBeInTheDocument();
- });
- it('Renders Commit Count and Author when user is in list of authors', async () => {
- jest.spyOn(ConfigStore, 'get').mockImplementation(() => mockedUser1);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
- body: mockedReleaseWithHealth,
- });
- renderQuickContextContent(defaultRow, ContextType.RELEASE);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/4/i)).toBeInTheDocument();
- expect(screen.getByText(/commits by you and 1 other/i)).toBeInTheDocument();
- expect(screen.getByText(/KN/i)).toBeInTheDocument();
- expect(screen.getByText(/VN/i)).toBeInTheDocument();
- });
- });
- describe('Quick Context Content: Event ID Column', function () {
- it('Renders transaction duration context', async () => {
- const currentTime = Date.now();
- mockUseLocation.mockReturnValueOnce(
- TestStubs.location({
- query: {
- field: 'title',
- },
- })
- );
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent({
- type: EventOrGroupType.TRANSACTION,
- entries: [],
- endTimestamp: currentTime,
- startTimestamp: currentTime - 2,
- }),
- });
- renderQuickContextContent(defaultRow, ContextType.EVENT);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Transaction Duration/i)).toBeInTheDocument();
- expect(screen.getByText(/2.00s/i)).toBeInTheDocument();
- const addAsColumnButton = screen.getByTestId(
- 'quick-context-transaction-duration-add-button'
- );
- expect(addAsColumnButton).toBeInTheDocument();
- userEvent.click(addAsColumnButton);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: '/mock-pathname/',
- query: expect.objectContaining({
- field: ['title', 'transaction.duration'],
- }),
- })
- );
- });
- it('Renders transaction status context', async () => {
- const currentTime = Date.now();
- mockUseLocation.mockReturnValueOnce(
- TestStubs.location({
- query: {
- field: 'title',
- },
- })
- );
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent({
- type: EventOrGroupType.TRANSACTION,
- entries: [],
- endTimestamp: currentTime,
- startTimestamp: currentTime - 2,
- contexts: {
- trace: {
- status: 'ok',
- },
- },
- tags: [
- {
- key: 'http.status_code',
- value: '200',
- },
- ],
- }),
- });
- renderQuickContextContent(defaultRow, ContextType.EVENT);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Status/i)).toBeInTheDocument();
- expect(screen.getByText(/ok/i)).toBeInTheDocument();
- expect(screen.getByText(/HTTP 200/i)).toBeInTheDocument();
- const addAsColumnButton = screen.getByTestId(
- 'quick-context-http-status-add-button'
- );
- expect(addAsColumnButton).toBeInTheDocument();
- userEvent.click(addAsColumnButton);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: '/mock-pathname/',
- query: expect.objectContaining({
- field: ['title', 'http.status_code'],
- }),
- })
- );
- });
- it('Adds columns for saved query', async () => {
- const currentTime = Date.now();
- mockUseLocation.mockReturnValueOnce(
- TestStubs.location({
- query: {
- field: null,
- },
- })
- );
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent({
- type: EventOrGroupType.TRANSACTION,
- entries: [],
- endTimestamp: currentTime,
- startTimestamp: currentTime - 2,
- }),
- });
- renderQuickContextContent(defaultRow, ContextType.EVENT, mockEventView);
- userEvent.hover(screen.getByText('Text from Child'));
- const addAsColumnButton = await screen.findByTestId(
- 'quick-context-transaction-duration-add-button'
- );
- expect(addAsColumnButton).toBeInTheDocument();
- userEvent.click(addAsColumnButton);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: '/mock-pathname/',
- query: expect.objectContaining({
- field: ['title', 'issue', 'transaction.duration'],
- }),
- })
- );
- });
- it('Renders NO stack trace message for error events without stackTraces', async () => {
- jest.spyOn(ConfigStore, 'get').mockImplementation(() => null);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent({type: EventOrGroupType.ERROR, entries: []}),
- });
- renderQuickContextContent(defaultRow, ContextType.EVENT);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(
- await screen.findByText(/There is no stack trace available for this event./i)
- ).toBeInTheDocument();
- });
- it('Renders event id header', async () => {
- jest.spyOn(ConfigStore, 'get').mockImplementation(() => null);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent({type: EventOrGroupType.ERROR, entries: []}),
- });
- renderQuickContextContent(defaultRow, ContextType.EVENT);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByText(/Event ID/i)).toBeInTheDocument();
- expect(screen.getByText(/6b43e285/i)).toBeInTheDocument();
- expect(
- screen.getByTestId('quick-context-hover-header-copy-icon')
- ).toBeInTheDocument();
- });
- it('Renders stack trace as context', async () => {
- const frame: Frame = {
- colNo: 0,
- filename: 'file.js',
- function: 'throwError',
- lineNo: 0,
- absPath: null,
- context: [],
- errors: null,
- inApp: false,
- instructionAddr: null,
- module: null,
- package: null,
- platform: null,
- rawFunction: null,
- symbol: null,
- symbolAddr: null,
- trust: undefined,
- vars: null,
- };
- const thread: ExceptionValue = {
- stacktrace: {
- hasSystemFrames: false,
- registers: {},
- framesOmitted: 0,
- frames: [frame],
- },
- mechanism: null,
- module: null,
- rawStacktrace: null,
- threadId: null,
- type: '',
- value: '',
- };
- const exceptionValue: ExceptionType = {
- values: [thread],
- excOmitted: undefined,
- hasSystemFrames: false,
- };
- const errorEvent: Event = {
- id: '6b43e285de834ec5b5fe30d62d549b20',
- type: EventOrGroupType.ERROR,
- entries: [
- {
- type: EntryType.EXCEPTION,
- data: exceptionValue,
- },
- ],
- } as EventError;
- mockUseLocation.mockReturnValue(
- TestStubs.location({
- query: {
- field: ['issue', 'transaction.duration'],
- },
- })
- );
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
- body: makeEvent(errorEvent),
- });
- const dataRow = {
- ...defaultRow,
- };
- delete dataRow.title;
- renderQuickContextContent(dataRow, ContextType.EVENT);
- userEvent.hover(screen.getByText('Text from Child'));
- expect(await screen.findByTestId('stack-trace-content')).toBeInTheDocument();
- const addAsColumnButton = screen.getByTestId('quick-context-title-add-button');
- expect(addAsColumnButton).toBeInTheDocument();
- expect(screen.getByText(/Title/i)).toBeInTheDocument();
- userEvent.click(addAsColumnButton);
- expect(browserHistory.push).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: '/mock-pathname/',
- query: expect.objectContaining({
- field: ['issue', 'transaction.duration', 'title'],
- }),
- })
- );
- });
- });
- });
|