issueListSetAsDefault.spec.tsx 3.2 KB

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