123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import React from 'react';
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import Results from 'app/views/eventsV2/results';
- const FIELDS = [
- {
- field: 'title',
- },
- {
- field: 'timestamp',
- },
- {
- field: 'user',
- },
- ];
- const generateFields = () => {
- return {
- field: FIELDS.map(i => i.field),
- };
- };
- describe('EventsV2 > Results', function() {
- const eventTitle = 'Oh no something bad';
- const features = ['events-v2'];
- beforeEach(function() {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {data: [[123, []]]},
- });
- 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/releases/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {
- id: 'string',
- title: 'string',
- 'project.name': 'string',
- timestamp: 'date',
- 'user.id': 'string',
- },
- data: [
- {
- id: 'deadbeef',
- 'user.id': 'alberto leal',
- title: eventTitle,
- 'project.name': 'project-slug',
- timestamp: '2019-05-23T22:12:48+00:00',
- },
- ],
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/project-slug:deadbeef/',
- method: 'GET',
- body: {
- id: '1234',
- size: 1200,
- eventID: 'deadbeef',
- title: 'Oh no something bad',
- message: 'It was not good',
- dateCreated: '2019-05-23T22:12:48+00:00',
- entries: [
- {
- type: 'message',
- message: 'bad stuff',
- data: {},
- },
- ],
- tags: [{key: 'browser', value: 'Firefox'}],
- },
- });
- });
- afterEach(function() {
- MockApiClient.clearMockResponses();
- });
- it('pagination cursor should be cleared when making a search', function() {
- const organization = TestStubs.Organization({
- features,
- projects: [TestStubs.Project()],
- });
- const initialData = initializeOrg({
- organization,
- router: {
- location: {query: {...generateFields(), cursor: '0%3A50%3A0'}},
- },
- });
- const wrapper = mountWithTheme(
- <Results
- organization={organization}
- location={initialData.router.location}
- router={initialData.router}
- />,
- initialData.routerContext
- );
- // ensure cursor query string is initially present in the location
- expect(initialData.router.location).toEqual({
- query: {
- ...generateFields(),
- cursor: '0%3A50%3A0',
- },
- });
- // perform a search
- const search = wrapper.find('#smart-search-input').first();
- search.simulate('change', {target: {value: 'geo:canada'}}).simulate('submit', {
- preventDefault() {},
- });
- // cursor query string should be omitted from the query string
- expect(initialData.router.push).toHaveBeenCalledWith({
- pathname: undefined,
- query: {
- ...generateFields(),
- query: 'geo:canada',
- statsPeriod: '14d',
- },
- });
- });
- });
|