issueListSetAsDefault.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {SavedSearchType} from 'sentry/types';
  4. import IssueListSetAsDefault from 'sentry/views/issueList/issueListSetAsDefault';
  5. describe('IssueListSetAsDefault', () => {
  6. const organization = TestStubs.Organization({
  7. features: ['issue-list-saved-searches-v2'],
  8. });
  9. const {router} = initializeOrg();
  10. const routerProps = {
  11. params: router.params,
  12. location: router.location,
  13. };
  14. const defaultProps = {
  15. organization,
  16. savedSearch: null,
  17. query: 'is:unresolved',
  18. sort: 'date',
  19. ...routerProps,
  20. };
  21. it('can set a search as default', () => {
  22. const mockPinSearch = MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/pinned-searches/',
  24. method: 'PUT',
  25. body: {},
  26. });
  27. render(<IssueListSetAsDefault {...defaultProps} />);
  28. userEvent.click(screen.getByRole('button', {name: /set as default/i}));
  29. expect(mockPinSearch).toHaveBeenCalledWith(
  30. expect.anything(),
  31. expect.objectContaining({
  32. data: {query: 'is:unresolved', sort: 'date', type: SavedSearchType.ISSUE},
  33. })
  34. );
  35. });
  36. it('can remove a default search', () => {
  37. const mockUnpinSearch = MockApiClient.addMockResponse({
  38. url: '/organizations/org-slug/pinned-searches/',
  39. method: 'DELETE',
  40. });
  41. render(
  42. <IssueListSetAsDefault
  43. {...defaultProps}
  44. savedSearch={TestStubs.Search({isPinned: true})}
  45. />
  46. );
  47. userEvent.click(screen.getByRole('button', {name: /remove default/i}));
  48. expect(mockUnpinSearch).toHaveBeenCalledWith(
  49. expect.anything(),
  50. expect.objectContaining({
  51. data: {type: SavedSearchType.ISSUE},
  52. })
  53. );
  54. });
  55. });