123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455 |
- import merge from 'lodash/merge';
- import {GroupFixture} from 'sentry-fixture/group';
- import {GroupStatsFixture} from 'sentry-fixture/groupStats';
- import {MemberFixture} from 'sentry-fixture/member';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {RouterFixture} from 'sentry-fixture/routerFixture';
- import {SearchFixture} from 'sentry-fixture/search';
- import {TagsFixture} from 'sentry-fixture/tags';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {
- act,
- render,
- screen,
- userEvent,
- waitFor,
- waitForElementToBeRemoved,
- } from 'sentry-test/reactTestingLibrary';
- import {textWithMarkupMatcher} from 'sentry-test/utils';
- import StreamGroup from 'sentry/components/stream/group';
- import {DEFAULT_QUERY} from 'sentry/constants';
- import PageFiltersStore from 'sentry/stores/pageFiltersStore';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import TagStore from 'sentry/stores/tagStore';
- import {SavedSearchVisibility} from 'sentry/types/group';
- import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
- import localStorageWrapper from 'sentry/utils/localStorage';
- import * as parseLinkHeader from 'sentry/utils/parseLinkHeader';
- import IssueListWithStores, {
- IssueListOverviewFc as IssueListOverview,
- } from 'sentry/views/issueList/overviewFc';
- // Mock <IssueListActions>
- jest.mock('sentry/views/issueList/actions', () => jest.fn(() => null));
- jest.mock('sentry/components/stream/group', () => jest.fn(() => null));
- const DEFAULT_LINKS_HEADER =
- '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575731:0:1>; rel="previous"; results="false"; cursor="1443575731:0:1", ' +
- '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="next"; results="true"; cursor="1443575000:0:0"';
- const project = ProjectFixture({
- id: '3559',
- name: 'Foo Project',
- slug: 'project-slug',
- firstEvent: new Date().toISOString(),
- });
- const {organization, projects, router} = initializeOrg({
- organization: {
- id: '1337',
- slug: 'org-slug',
- features: ['global-views'],
- access: [],
- },
- router: {
- location: {query: {query: DEFAULT_QUERY}},
- params: {},
- },
- projects: [project],
- });
- const routerProps = {
- params: router.params,
- location: router.location,
- } as RouteComponentProps<{}, {searchId?: string}>;
- const initialRouterConfig = {
- routes: [
- '/organizations/:orgId/issues/',
- '/organizations/:orgId/issues/searches/:searchId/',
- ],
- location: {
- pathname: '/organizations/org-slug/issues/',
- query: {},
- },
- };
- function getSearchInput() {
- const input = screen.getAllByRole('combobox', {name: 'Add a search term'}).at(-1);
- expect(input).toBeInTheDocument();
- return input!;
- }
- describe('IssueList', function () {
- const tags = TagsFixture();
- const group = GroupFixture({project});
- const groupStats = GroupStatsFixture();
- const savedSearch = SearchFixture({
- id: '789',
- query: 'is:unresolved TypeError',
- sort: 'date',
- name: 'Unresolved TypeErrors',
- });
- let fetchMembersRequest: jest.Mock;
- const parseLinkHeaderSpy = jest.spyOn(parseLinkHeader, 'default');
- beforeEach(function () {
- // The tests fail because we have a "component update was not wrapped in act" error.
- // It should be safe to ignore this error, but we should remove the mock once we move to react testing library
- jest.spyOn(console, 'error').mockImplementation(jest.fn());
- Object.defineProperty(Element.prototype, 'clientWidth', {value: 1000});
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [group],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues-stats/',
- body: [groupStats],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch],
- });
- 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/issues-count/',
- method: 'GET',
- body: [{}],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/processingissues/',
- method: 'GET',
- body: [
- {
- project: 'test-project',
- numIssues: 1,
- hasIssues: true,
- lastSeen: '2019-01-16T15:39:11.081Z',
- },
- ],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/',
- method: 'GET',
- body: tags,
- });
- fetchMembersRequest = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- method: 'GET',
- body: [MemberFixture({projects: [project.slug]})],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sent-first-event/',
- body: {sentFirstEvent: true},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [project],
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [parseInt(projects[0]!.id, 10)],
- environments: [],
- datetime: {period: '14d', start: null, end: null, utc: null},
- },
- new Set()
- );
- TagStore.init?.();
- });
- afterEach(function () {
- jest.clearAllMocks();
- MockApiClient.clearMockResponses();
- localStorageWrapper.clear();
- });
- describe('withStores and feature flags', function () {
- let issuesRequest: jest.Mock;
- beforeEach(function () {
- jest.mocked(StreamGroup).mockClear();
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/recent-searches/',
- method: 'GET',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch],
- });
- issuesRequest = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [group],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- });
- it('loads group rows with default query (no pinned queries, async and no query in URL)', async function () {
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: {
- location: {
- pathname: '/organizations/org-slug/issues/',
- query: {},
- },
- },
- });
- await screen.findByRole('grid', {name: 'Create a search query'});
- expect(screen.getByRole('row', {name: 'is:unresolved'})).toBeInTheDocument();
- expect(screen.getByRole('button', {name: /custom search/i})).toBeInTheDocument();
- // primary /issues/ request
- await waitFor(() => {
- expect(issuesRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- // Should not be called with a "query" param, endpoint will find the default query itself
- data: expect.not.stringContaining('query'),
- })
- );
- });
- expect(issuesRequest).toHaveBeenCalledTimes(1);
- });
- it('loads with query in URL and pinned queries', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [
- savedSearch,
- SearchFixture({
- id: '123',
- name: 'My Pinned Search',
- isPinned: true,
- query: 'is:resolved',
- }),
- ],
- });
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: {
- ...initialRouterConfig,
- location: {
- ...initialRouterConfig.location,
- query: {query: 'level:foo'},
- },
- },
- });
- await waitFor(() => {
- // Main /issues/ request
- expect(issuesRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- // Should be called with default query
- data: expect.stringContaining('level%3Afoo'),
- })
- );
- });
- expect(screen.getByRole('row', {name: 'level:foo'})).toBeInTheDocument();
- // Tab shows "custom search"
- expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
- });
- it('loads with a saved query', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [
- SearchFixture({
- id: '123',
- name: 'Assigned to Me',
- isPinned: false,
- isGlobal: true,
- query: 'assigned:me',
- sort: 'trends',
- type: 0,
- }),
- ],
- });
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: {
- ...initialRouterConfig,
- location: {
- pathname: '/organizations/org-slug/issues/searches/123/',
- },
- },
- });
- await waitFor(() => {
- expect(issuesRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- data: expect.stringContaining('searchId=123'),
- })
- );
- });
- expect(screen.getByRole('row', {name: 'assigned:me'})).toBeInTheDocument();
- // Organization saved search selector should have default saved search selected
- expect(screen.getByRole('button', {name: 'Assigned to Me'})).toBeInTheDocument();
- });
- it('loads with a query in URL', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [
- SearchFixture({
- id: '123',
- name: 'Assigned to Me',
- isPinned: false,
- isGlobal: true,
- query: 'assigned:me',
- type: 0,
- }),
- ],
- });
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: merge({}, initialRouterConfig, {
- location: {
- query: {query: 'level:error'},
- },
- }),
- });
- await waitFor(() => {
- expect(issuesRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- // Should be called with default query
- data: expect.stringContaining('level%3Aerror'),
- })
- );
- });
- expect(screen.getByRole('row', {name: 'level:error'})).toBeInTheDocument();
- // Organization saved search selector should have default saved search selected
- expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
- });
- it('loads with an empty query in URL', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [
- SearchFixture({
- id: '123',
- name: 'My Pinned Search',
- isPinned: true,
- isGlobal: false,
- query: 'is:resolved',
- }),
- ],
- });
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: {
- ...initialRouterConfig,
- location: {
- ...initialRouterConfig.location,
- query: {},
- },
- },
- });
- await waitFor(() => {
- expect(issuesRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- // Should be called with empty query
- data: expect.stringContaining(''),
- })
- );
- });
- expect(screen.getByRole('row', {name: 'is:resolved'})).toBeInTheDocument();
- // Organization saved search selector should have default saved search selected
- expect(screen.getByRole('button', {name: 'My Default Search'})).toBeInTheDocument();
- });
- it('caches the search results', async function () {
- issuesRequest = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [...new Array(25)].map((_, i) => ({id: i})),
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- 'X-Hits': '500',
- 'X-Max-Hits': '1000',
- },
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [],
- environments: [],
- datetime: {period: '14d', start: null, end: null, utc: null},
- },
- new Set()
- );
- const {unmount} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- expect(
- await screen.findByText(textWithMarkupMatcher('1-25 of 500'))
- ).toBeInTheDocument();
- expect(issuesRequest).toHaveBeenCalledTimes(1);
- unmount();
- // Mount component again, getting from cache
- render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- expect(
- await screen.findByText(textWithMarkupMatcher('1-25 of 500'))
- ).toBeInTheDocument();
- expect(issuesRequest).toHaveBeenCalledTimes(1);
- });
- it('1 search', async function () {
- const localSavedSearch = {...savedSearch, projectId: null};
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [localSavedSearch],
- });
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await userEvent.click(await screen.findByRole('button', {name: /custom search/i}));
- await userEvent.click(screen.getByRole('button', {name: localSavedSearch.name}));
- await waitFor(() => {
- expect(testRouter.location.pathname).toBe(
- '/organizations/org-slug/issues/searches/789/'
- );
- });
- });
- it('clears a saved search when a custom one is entered', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [
- savedSearch,
- SearchFixture({
- id: '123',
- name: 'Pinned search',
- isPinned: true,
- isGlobal: false,
- query: 'is:resolved',
- }),
- ],
- });
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await screen.findByRole('grid', {name: 'Create a search query'});
- await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
- await userEvent.click(getSearchInput());
- await userEvent.keyboard('dogs{Enter}');
- await waitFor(() => {
- expect(testRouter.location.pathname).toBe('/organizations/org-slug/issues/');
- });
- expect(testRouter.location.query).toEqual(
- expect.objectContaining({
- project: '3559',
- referrer: 'issue-list',
- sort: '',
- query: 'dogs',
- statsPeriod: '14d',
- })
- );
- });
- it('pins a custom query', async function () {
- const pinnedSearch = {
- id: '666',
- name: 'My Pinned Search',
- query: 'assigned:me level:fatal',
- sort: 'date',
- isPinned: true,
- visibility: SavedSearchVisibility.ORGANIZATION,
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch],
- });
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await screen.findByRole('grid', {name: 'Create a search query'});
- await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
- await userEvent.click(getSearchInput());
- await userEvent.paste('assigned:me level:fatal');
- await userEvent.keyboard('{Enter}');
- await waitFor(() => {
- expect(testRouter.location.query.query).toBe('assigned:me level:fatal');
- });
- expect(
- await screen.findByRole('button', {name: 'Custom Search'})
- ).toBeInTheDocument();
- MockApiClient.clearMockResponses();
- const createPin = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/pinned-searches/',
- method: 'PUT',
- body: pinnedSearch,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch, pinnedSearch],
- });
- await userEvent.click(screen.getByLabelText(/Set as Default/i));
- await waitFor(() => {
- expect(createPin).toHaveBeenCalled();
- });
- await waitFor(() => {
- expect(testRouter.location.pathname).toBe(
- '/organizations/org-slug/issues/searches/666/'
- );
- });
- expect(testRouter.location.query.referrer).toBe('search-bar');
- });
- it('unpins a custom query', async function () {
- const pinnedSearch = SearchFixture({
- id: '666',
- name: 'My Pinned Search',
- query: 'assigned:me level:fatal',
- sort: 'date',
- isPinned: true,
- visibility: SavedSearchVisibility.ORGANIZATION,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [pinnedSearch],
- });
- const deletePin = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/pinned-searches/',
- method: 'DELETE',
- });
- const routerWithSavedSearch = RouterFixture({
- params: {searchId: pinnedSearch.id},
- });
- render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
- router: routerWithSavedSearch,
- organization,
- });
- expect(
- await screen.findByRole('button', {name: 'My Default Search'})
- ).toBeInTheDocument();
- await userEvent.click(screen.getByLabelText(/Remove Default/i));
- await waitFor(() => {
- expect(deletePin).toHaveBeenCalled();
- });
- await waitFor(() => {
- expect(routerWithSavedSearch.replace).toHaveBeenLastCalledWith(
- expect.objectContaining({
- pathname: '/organizations/org-slug/issues/',
- })
- );
- });
- });
- it('pins a saved query', async function () {
- const assignedToMe = SearchFixture({
- id: '234',
- name: 'Assigned to Me',
- isPinned: false,
- isGlobal: true,
- query: 'assigned:me',
- sort: 'date',
- type: 0,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch, assignedToMe],
- });
- const createPin = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/pinned-searches/',
- method: 'PUT',
- body: {
- ...savedSearch,
- isPinned: true,
- },
- });
- const routerWithSavedSearch = RouterFixture({params: {searchId: '789'}});
- render(<IssueListWithStores {...merge({}, routerProps, routerWithSavedSearch)} />, {
- router: routerWithSavedSearch,
- organization,
- });
- expect(
- await screen.findByRole('button', {name: savedSearch.name})
- ).toBeInTheDocument();
- await userEvent.click(screen.getByLabelText(/set as default/i));
- await waitFor(() => {
- expect(createPin).toHaveBeenCalled();
- });
- expect(routerWithSavedSearch.replace).toHaveBeenLastCalledWith(
- expect.objectContaining({
- pathname: '/organizations/org-slug/issues/searches/789/',
- })
- );
- });
- it('pinning search should keep project selected', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [savedSearch],
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [123],
- environments: ['prod'],
- datetime: {
- period: null,
- start: null,
- end: null,
- utc: null,
- },
- },
- new Set()
- );
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: merge({}, initialRouterConfig, {
- location: {
- query: {
- project: '123',
- environment: 'prod',
- query: 'assigned:me level:fatal',
- },
- },
- }),
- });
- const createPin = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/pinned-searches/',
- method: 'PUT',
- body: {
- ...savedSearch,
- id: '666',
- name: 'My Pinned Search',
- query: 'assigned:me level:fatal',
- sort: 'date',
- isPinned: true,
- },
- });
- await userEvent.click(await screen.findByLabelText(/set as default/i));
- await waitFor(() => {
- expect(createPin).toHaveBeenCalled();
- });
- await waitFor(() => {
- expect(testRouter.location.pathname).toBe(
- '/organizations/org-slug/issues/searches/666/'
- );
- });
- expect(testRouter.location.query).toEqual(
- expect.objectContaining({
- project: '123',
- environment: 'prod',
- query: 'assigned:me level:fatal',
- })
- );
- });
- it('unpinning search should keep project selected', async function () {
- const localSavedSearch = {
- ...savedSearch,
- id: '666',
- isPinned: true,
- query: 'assigned:me level:fatal',
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/searches/',
- body: [localSavedSearch],
- });
- const deletePin = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/pinned-searches/',
- method: 'DELETE',
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [123],
- environments: ['prod'],
- datetime: {
- period: null,
- start: null,
- end: null,
- utc: null,
- },
- },
- new Set()
- );
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: {
- ...initialRouterConfig,
- location: {
- pathname: '/organizations/org-slug/issues/searches/666/',
- query: {
- project: '123',
- environment: 'prod',
- query: 'assigned:me level:fatal',
- },
- },
- },
- });
- await userEvent.click(await screen.findByLabelText(/Remove Default/i));
- await waitFor(() => {
- expect(deletePin).toHaveBeenCalled();
- });
- expect(testRouter.location.pathname).toBe('/organizations/org-slug/issues/');
- expect(testRouter.location.query).toEqual(
- expect.objectContaining({
- project: '123',
- environment: 'prod',
- query: 'assigned:me level:fatal',
- })
- );
- });
- it('does not allow pagination to "previous" while on first page and resets cursors when navigating back to initial page', async function () {
- const {router: testRouter} = render(<IssueListWithStores {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- expect(await screen.findByRole('button', {name: 'Previous'})).toBeDisabled();
- issuesRequest = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [group],
- headers: {
- Link: '<http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443575000:0:0>; rel="previous"; results="true"; cursor="1443575000:0:1", <http://127.0.0.1:8000/api/0/organizations/org-slug/issues/?cursor=1443574000:0:0>; rel="next"; results="true"; cursor="1443574000:0:0"',
- },
- });
- await userEvent.click(await screen.findByRole('button', {name: 'Next'}));
- await waitFor(() => {
- expect(testRouter.location.query).toEqual({
- cursor: '1443575000:0:0',
- page: '1',
- project: '3559',
- query: DEFAULT_QUERY,
- statsPeriod: '14d',
- referrer: 'issue-list',
- });
- });
- await waitFor(() => {
- expect(screen.getByRole('button', {name: 'Previous'})).toBeEnabled();
- });
- // Click next again
- await userEvent.click(screen.getByRole('button', {name: 'Next'}));
- await waitFor(() => {
- expect(testRouter.location.query).toEqual({
- cursor: '1443574000:0:0',
- page: '2',
- project: '3559',
- query: DEFAULT_QUERY,
- statsPeriod: '14d',
- referrer: 'issue-list',
- });
- });
- // Click previous
- await userEvent.click(screen.getByRole('button', {name: 'Previous'}));
- await waitFor(() => {
- expect(testRouter.location.query).toEqual({
- cursor: '1443575000:0:1',
- page: '1',
- project: '3559',
- query: DEFAULT_QUERY,
- statsPeriod: '14d',
- referrer: 'issue-list',
- });
- });
- // Click previous back to initial page
- await userEvent.click(screen.getByRole('button', {name: 'Previous'}));
- await waitFor(() => {
- expect(testRouter.location.query.cursor).toBeUndefined();
- });
- expect(testRouter.location.query.page).toBeUndefined();
- });
- });
- describe('transitionTo', function () {
- it('pushes to history when query is updated', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- const {router: testRouter} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await userEvent.click(screen.getByRole('button', {name: 'Clear search query'}));
- await userEvent.click(getSearchInput());
- await userEvent.paste('is:ignored');
- await userEvent.keyboard('{enter}');
- await waitFor(() => {
- expect(testRouter.location.query).toEqual({
- project: project.id.toString(),
- query: 'is:ignored',
- statsPeriod: '14d',
- referrer: 'issue-list',
- });
- });
- });
- });
- it('fetches members', async function () {
- render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await waitFor(() => {
- expect(fetchMembersRequest).toHaveBeenCalled();
- });
- });
- describe('componentDidUpdate fetching groups', function () {
- let fetchDataMock: jest.Mock;
- beforeEach(function () {
- fetchDataMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [group],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- fetchDataMock.mockReset();
- });
- it('fetches data on selection change', async function () {
- const {rerender} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [99],
- environments: [],
- datetime: {period: '24h', start: null, end: null, utc: null},
- },
- new Set()
- );
- rerender(<IssueListOverview {...routerProps} />);
- await waitFor(() => {
- expect(fetchDataMock).toHaveBeenCalled();
- });
- });
- it('fetches data on savedSearch change', async function () {
- const {rerender} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- rerender(<IssueListOverview {...routerProps} />);
- await waitFor(() => {
- expect(fetchDataMock).toHaveBeenCalled();
- });
- });
- it('uses correct statsPeriod when fetching issues list and no datetime given', async function () {
- const {rerender} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig: merge({}, initialRouterConfig, {
- location: {
- query: {
- query: DEFAULT_QUERY,
- },
- },
- }),
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [99],
- environments: [],
- datetime: {period: '14d', start: null, end: null, utc: null},
- },
- new Set()
- );
- rerender(<IssueListOverview {...routerProps} />);
- await waitFor(() => {
- expect(fetchDataMock).toHaveBeenLastCalledWith(
- '/organizations/org-slug/issues/',
- expect.objectContaining({
- data: 'collapse=stats&collapse=unhandled&expand=owners&expand=inbox&limit=25&project=99&query=is%3Aunresolved%20issue.priority%3A%5Bhigh%2C%20medium%5D&savedSearch=0&shortIdLookup=1&statsPeriod=14d',
- })
- );
- });
- });
- });
- describe('componentDidUpdate fetching members', function () {
- it('fetches memberlist on project change', async function () {
- const {rerender} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- // Called during componentDidMount
- await waitFor(() => {
- expect(fetchMembersRequest).toHaveBeenCalled();
- });
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [99],
- environments: [],
- datetime: {period: '24h', start: null, end: null, utc: null},
- },
- new Set()
- );
- rerender(<IssueListOverview {...routerProps} />);
- await waitFor(() => {
- expect(fetchMembersRequest).toHaveBeenCalledWith(
- expect.anything(),
- expect.objectContaining({
- query: {
- project: ['99'],
- },
- })
- );
- });
- });
- });
- describe('render states', function () {
- it('displays an error when issues fail to load', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- status: 500,
- statusCode: 500,
- });
- render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- expect(await screen.findByTestId('loading-error')).toBeInTheDocument();
- });
- it('displays "Get out there and write some broken code" with default query', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- expect(
- await screen.findByText(/Get out there and write some broken code!/i)
- ).toBeInTheDocument();
- });
- it('displays "no issues match your search" with a non-default query', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- const {router: testRouter} = render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig: merge({}, initialRouterConfig, {
- location: {
- query: {
- query: DEFAULT_QUERY,
- },
- },
- }),
- });
- await screen.findByRole('grid', {name: 'Create a search query'});
- await userEvent.click(getSearchInput());
- await userEvent.keyboard('foo{enter}');
- await waitFor(() => {
- expect(testRouter.location.query.query).toBe(
- 'is:unresolved issue.priority:[high, medium] foo'
- );
- });
- expect(await screen.findByText(/No issues match your search/i)).toBeInTheDocument();
- });
- });
- describe('Error Robot', function () {
- beforeEach(() => {
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [],
- environments: [],
- datetime: {period: '14d', start: null, end: null, utc: null},
- },
- new Set()
- );
- });
- const createWrapper = async (moreProps: any) => {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [],
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- },
- });
- render(<IssueListOverview {...routerProps} {...moreProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
- };
- it('displays when no projects selected and all projects user is member of, async does not have first event', async function () {
- const projectsBody = [
- ProjectFixture({
- id: '1',
- slug: 'foo',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '2',
- slug: 'bar',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '3',
- slug: 'baz',
- isMember: true,
- firstEvent: null,
- }),
- ];
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sent-first-event/',
- query: {
- is_member: true,
- },
- body: {sentFirstEvent: false},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: projectsBody,
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/foo/issues/',
- body: [],
- });
- await createWrapper({
- organization: OrganizationFixture(),
- });
- expect(await screen.findByTestId('awaiting-events')).toBeInTheDocument();
- });
- it('does not display when no projects selected and any projects have a first event', async function () {
- const projectsBody = [
- ProjectFixture({
- id: '1',
- slug: 'foo',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '2',
- slug: 'bar',
- isMember: true,
- firstEvent: new Date().toISOString(),
- }),
- ProjectFixture({
- id: '3',
- slug: 'baz',
- isMember: true,
- firstEvent: null,
- }),
- ];
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sent-first-event/',
- query: {
- is_member: true,
- },
- body: {sentFirstEvent: true},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: projectsBody,
- });
- await createWrapper({
- organization: OrganizationFixture(),
- });
- expect(screen.queryByTestId('awaiting-events')).not.toBeInTheDocument();
- });
- it('displays when all selected projects do not have first event', async function () {
- const projectsBody = [
- ProjectFixture({
- id: '1',
- slug: 'foo',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '2',
- slug: 'bar',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '3',
- slug: 'baz',
- isMember: true,
- firstEvent: null,
- }),
- ];
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sent-first-event/',
- query: {
- project: [1, 2],
- },
- body: {sentFirstEvent: false},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: projectsBody,
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/foo/issues/',
- body: [],
- });
- await createWrapper({
- selection: {
- projects: [1, 2],
- environments: [],
- datetime: {period: '14d'},
- },
- organization: OrganizationFixture(),
- });
- expect(await screen.findByTestId('awaiting-events')).toBeInTheDocument();
- });
- it('does not display when any selected projects have first event', async function () {
- const projectsBody = [
- ProjectFixture({
- id: '1',
- slug: 'foo',
- isMember: true,
- firstEvent: null,
- }),
- ProjectFixture({
- id: '2',
- slug: 'bar',
- isMember: true,
- firstEvent: new Date().toISOString(),
- }),
- ProjectFixture({
- id: '3',
- slug: 'baz',
- isMember: true,
- firstEvent: new Date().toISOString(),
- }),
- ];
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/sent-first-event/',
- query: {
- project: [1, 2],
- },
- body: {sentFirstEvent: true},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: projectsBody,
- });
- await createWrapper({
- selection: {
- projects: [1, 2],
- environments: [],
- datetime: {period: '14d'},
- },
- organization: OrganizationFixture(),
- });
- expect(screen.queryByTestId('awaiting-events')).not.toBeInTheDocument();
- });
- });
- it('displays a count that represents the current page', async function () {
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/issues/',
- body: [...new Array(25)].map((_, i) => ({id: i})),
- headers: {
- Link: DEFAULT_LINKS_HEADER,
- 'X-Hits': '500',
- 'X-Max-Hits': '1000',
- },
- });
- parseLinkHeaderSpy.mockReturnValue({
- next: {
- results: true,
- cursor: '',
- href: '',
- },
- previous: {
- results: false,
- cursor: '',
- href: '',
- },
- });
- const {rerender} = render(<IssueListOverview {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig: merge({}, initialRouterConfig, {
- location: {
- query: {
- cursor: 'some cursor',
- page: 1,
- },
- },
- }),
- });
- await waitFor(() => {
- expect(screen.getByText(textWithMarkupMatcher('1-25 of 500'))).toBeInTheDocument();
- });
- parseLinkHeaderSpy.mockReturnValue({
- next: {
- results: true,
- cursor: '',
- href: '',
- },
- previous: {
- results: true,
- cursor: '',
- href: '',
- },
- });
- rerender(<IssueListOverview {...routerProps} />);
- await waitFor(() => {
- expect(screen.getByText(textWithMarkupMatcher('26-50 of 500'))).toBeInTheDocument();
- });
- });
- describe('project low trends queue alert', function () {
- beforeEach(function () {
- act(() => ProjectsStore.reset());
- });
- it('does not render event processing alert', async function () {
- act(() => ProjectsStore.loadInitialData([project]));
- render(<IssueListOverview {...routerProps} />, {
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await waitFor(() => {
- expect(screen.queryByText(/event processing/i)).not.toBeInTheDocument();
- });
- });
- describe('renders alert', function () {
- it('for one project', async function () {
- act(() =>
- ProjectsStore.loadInitialData([
- {...project, eventProcessing: {symbolicationDegraded: true}},
- ])
- );
- render(<IssueListOverview {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await waitFor(() => {
- expect(
- screen.getByText(/Event Processing for this project is currently degraded/i)
- ).toBeInTheDocument();
- });
- });
- it('for multiple projects', async function () {
- const projectBar = ProjectFixture({
- id: '3560',
- name: 'Bar Project',
- slug: 'project-slug-bar',
- });
- act(() =>
- ProjectsStore.loadInitialData([
- {
- ...project,
- slug: 'project-slug',
- eventProcessing: {symbolicationDegraded: true},
- },
- {
- ...projectBar,
- slug: 'project-slug-bar',
- eventProcessing: {symbolicationDegraded: true},
- },
- ])
- );
- PageFiltersStore.onInitializeUrlState(
- {
- projects: [Number(project.id), Number(projectBar.id)],
- environments: [],
- datetime: {period: '14d', start: null, end: null, utc: null},
- },
- new Set()
- );
- render(<IssueListOverview {...routerProps} />, {
- organization,
- disableRouterMocks: true,
- initialRouterConfig,
- });
- await waitFor(() => {
- expect(
- screen.getByText(
- textWithMarkupMatcher(
- 'Event Processing for the project-slug, project-slug-bar projects is currently degraded.'
- )
- )
- ).toBeInTheDocument();
- });
- });
- });
- });
- });
|