issueListSetAsDefault.spec.tsx 3.3 KB

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