issueListSetAsDefault.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {Search} from 'sentry-fixture/search';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {SavedSearchType, SavedSearchVisibility} from 'sentry/types';
  6. import IssueListSetAsDefault from 'sentry/views/issueList/issueListSetAsDefault';
  7. import {IssueSortOptions} from 'sentry/views/issueList/utils';
  8. describe('IssueListSetAsDefault', () => {
  9. const organization = Organization();
  10. const {router} = initializeOrg();
  11. const routerProps = {
  12. params: router.params,
  13. location: router.location,
  14. };
  15. const defaultProps = {
  16. organization,
  17. query: 'browser:firefox',
  18. sort: IssueSortOptions.DATE,
  19. ...routerProps,
  20. };
  21. beforeEach(() => {
  22. MockApiClient.clearMockResponses();
  23. });
  24. it('can set a search as default', async () => {
  25. MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/searches/',
  27. body: [],
  28. });
  29. const mockPinSearch = MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/pinned-searches/',
  31. method: 'PUT',
  32. body: Search({
  33. isPinned: true,
  34. visibility: SavedSearchVisibility.OWNER_PINNED,
  35. }),
  36. });
  37. render(<IssueListSetAsDefault {...defaultProps} />, {organization});
  38. await userEvent.click(screen.getByRole('button', {name: /set as default/i}));
  39. await waitFor(() => {
  40. expect(mockPinSearch).toHaveBeenCalledWith(
  41. expect.anything(),
  42. expect.objectContaining({
  43. data: {query: 'browser:firefox', sort: 'date', type: SavedSearchType.ISSUE},
  44. })
  45. );
  46. });
  47. });
  48. it('can remove a default search', async () => {
  49. MockApiClient.addMockResponse({
  50. url: '/organizations/org-slug/searches/',
  51. body: [Search({isPinned: true, query: 'browser:firefox'})],
  52. });
  53. const mockUnpinSearch = MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/pinned-searches/',
  55. method: 'DELETE',
  56. });
  57. render(<IssueListSetAsDefault {...defaultProps} />, {organization});
  58. await userEvent.click(await screen.findByRole('button', {name: /remove default/i}));
  59. await waitFor(() => {
  60. expect(mockUnpinSearch).toHaveBeenCalledWith(
  61. expect.anything(),
  62. expect.objectContaining({
  63. data: {type: SavedSearchType.ISSUE},
  64. })
  65. );
  66. });
  67. });
  68. it('does not render anything when on default search and no pinned search', () => {
  69. MockApiClient.addMockResponse({
  70. url: '/organizations/org-slug/searches/',
  71. body: [Search({isPinned: false, query: 'browser:firefox'})],
  72. });
  73. render(<IssueListSetAsDefault {...defaultProps} query="is:unresolved" />, {
  74. organization,
  75. });
  76. expect(screen.queryByRole('button')).not.toBeInTheDocument();
  77. });
  78. it('does render when on default search and existing pinned search', async () => {
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/searches/',
  81. body: [Search({isPinned: true, query: 'browser:firefox'})],
  82. });
  83. render(<IssueListSetAsDefault {...defaultProps} query="is:unresolved" />, {
  84. organization,
  85. });
  86. await screen.findByRole('button', {name: /remove default/i});
  87. });
  88. });