123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- import {EventFixture} from 'sentry-fixture/event';
- import {EventsStatsFixture} from 'sentry-fixture/events';
- import {GroupFixture} from 'sentry-fixture/group';
- import {LocationFixture} from 'sentry-fixture/locationFixture';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {RouterFixture} from 'sentry-fixture/routerFixture';
- import {TagsFixture} from 'sentry-fixture/tags';
- import {render, renderHook, screen, waitFor} from 'sentry-test/reactTestingLibrary';
- import PageFiltersStore from 'sentry/stores/pageFiltersStore';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {useEventColumns} from 'sentry/views/issueDetails/allEventsTable';
- import {MOCK_EVENTS_TABLE_DATA} from 'sentry/views/performance/transactionSummary/transactionEvents/testUtils';
- import {EventList} from './eventList';
- describe('EventList', () => {
- const organization = OrganizationFixture();
- const project = ProjectFixture({
- environments: ['production', 'staging', 'development'],
- });
- const group = GroupFixture();
- const event = EventFixture({id: 'event-id'});
- const persistantQuery = `issue:${group.shortId}`;
- const totalCount = 100;
- let mockEventList: jest.Mock;
- let mockEventListMeta: jest.Mock;
- beforeEach(() => {
- PageFiltersStore.init();
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [],
- environments: [],
- datetime: {start: null, end: null, period: '14d', utc: null},
- },
- new Set(['environments'])
- );
- ProjectsStore.loadInitialData([project]);
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/actionable-items/`,
- body: {errors: []},
- method: 'GET',
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
- body: TagsFixture(),
- method: 'GET',
- });
- MockApiClient.addMockResponse({
- url: `/organizations/${organization.slug}/events-stats/`,
- body: {'count()': EventsStatsFixture(), 'count_unique(user)': EventsStatsFixture()},
- method: 'GET',
- });
- mockEventList = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- headers: {
- Link:
- `<http://localhost/api/0/organizations/${organization.slug}/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",` +
- `<http://localhost/api/0/organizations/${organization.slug}/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"`,
- },
- body: {
- data: MOCK_EVENTS_TABLE_DATA,
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('user.display');
- },
- ],
- });
- mockEventListMeta = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/',
- headers: {
- Link:
- `<http://localhost/api/0/organizations/${organization.slug}/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",` +
- `<http://localhost/api/0/organizations/${organization.slug}/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"`,
- },
- body: {
- data: [{'count()': totalCount}],
- },
- match: [
- (_url, options) => {
- return options.query?.field?.includes('count()');
- },
- ],
- });
- });
- function renderAllEvents() {
- render(<EventList group={group} project={project} />, {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- pathname: `/organizations/${organization.slug}/issues/${group.id}/events/`,
- }),
- routes: [{name: '', path: 'events/'}],
- }),
- });
- }
- it('renders the list using a discover event query', async function () {
- renderAllEvents();
- const {result} = renderHook(() => useEventColumns(group, organization));
- expect(await screen.findByText('All Events')).toBeInTheDocument();
- expect(mockEventList).toHaveBeenCalledWith(
- '/organizations/org-slug/events/',
- expect.objectContaining({
- query: {
- dataset: 'errors',
- environment: [],
- field: result.current.fields,
- per_page: 50,
- project: [project.id],
- query: persistantQuery,
- referrer: 'issue_details.streamline_list',
- statsPeriod: '14d',
- sort: '-timestamp',
- },
- })
- );
- expect(mockEventListMeta).toHaveBeenCalled();
- expect(screen.getByRole('button', {name: 'Previous Page'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: 'Next Page'})).toBeInTheDocument();
- expect(
- await screen.findByText(
- `Showing 1-${MOCK_EVENTS_TABLE_DATA.length} of ${totalCount} matching events`
- )
- ).toBeInTheDocument();
- // Returns minidump column, but we omit it as a custom column
- const columns = result.current.columnTitles.filter(t => t !== 'Minidump');
- for (const title of columns) {
- expect(screen.getByRole('columnheader', {name: title})).toBeInTheDocument();
- }
- });
- it('updates query from location param change', async function () {
- const [tagKey, tagValue] = ['user.email', 'leander.rodrigues@sentry.io'];
- const locationQuery = {
- query: {
- query: `${tagKey}:${tagValue}`,
- },
- };
- render(<EventList group={group} project={project} />, {
- organization,
- router: RouterFixture({
- location: LocationFixture({
- pathname: `/organizations/${organization.slug}/issues/${group.id}/events/`,
- query: locationQuery.query,
- }),
- routes: [{name: '', path: 'events/'}],
- }),
- });
- const expectedArgs = [
- '/organizations/org-slug/events/',
- expect.objectContaining({
- query: expect.objectContaining({
- query: [persistantQuery, locationQuery.query.query].join(' '),
- }),
- }),
- ];
- await waitFor(() => {
- expect(mockEventList).toHaveBeenCalledWith(...expectedArgs);
- });
- expect(mockEventListMeta).toHaveBeenCalledWith(...expectedArgs);
- });
- });
|