issueListSetAsDefault.spec.tsx 3.2 KB

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