savedSearchTab.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. within,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import IssueListSavedSearchTab from 'sentry/views/issueList/savedSearchTab';
  9. describe('IssueListSavedSearchTab', () => {
  10. const savedSearchList = [
  11. {
  12. id: '789',
  13. query: 'is:unresolved',
  14. sort: 'date',
  15. name: 'Unresolved',
  16. isPinned: false,
  17. isGlobal: true,
  18. },
  19. {
  20. id: '122',
  21. query: 'global search query',
  22. sort: 'date',
  23. name: 'Global Search',
  24. isPinned: false,
  25. isGlobal: true,
  26. },
  27. {
  28. id: '444',
  29. query: 'is:unresolved assigned:me',
  30. sort: 'date',
  31. name: 'Assigned to me',
  32. isPinned: false,
  33. isGlobal: false,
  34. },
  35. ];
  36. const onSelect = jest.fn();
  37. const onDelete = jest.fn();
  38. function renderSavedSearch({organization} = {}) {
  39. render(
  40. <IssueListSavedSearchTab
  41. organization={organization ?? TestStubs.Organization({access: ['org:write']})}
  42. savedSearchList={savedSearchList}
  43. onSavedSearchSelect={onSelect}
  44. onSavedSearchDelete={onDelete}
  45. query="is:unresolved assigned:lyn@sentry.io"
  46. />,
  47. {context: TestStubs.routerContext()}
  48. );
  49. // Open the saved searches menu
  50. screen.getByRole('button', {name: 'Saved Searches'}).click();
  51. }
  52. afterEach(() => {
  53. jest.resetAllMocks();
  54. });
  55. it('shows a delete button with access', () => {
  56. renderSavedSearch();
  57. const assignedToMe = screen.getByTestId('saved-search-444');
  58. expect(
  59. within(assignedToMe).getByRole('button', {name: 'delete'})
  60. ).toBeInTheDocument();
  61. });
  62. it('does not show a delete button without access', () => {
  63. renderSavedSearch({organization: TestStubs.Organization({access: []})});
  64. const assignedToMe = screen.getByTestId('saved-search-444');
  65. expect(
  66. within(assignedToMe).queryByRole('button', {name: 'delete'})
  67. ).not.toBeInTheDocument();
  68. });
  69. it('does not show a delete button for global search', () => {
  70. renderSavedSearch();
  71. // Should not have a delete button as it is a global search
  72. const globalSearch = screen.getByTestId('global-search-122');
  73. expect(
  74. within(globalSearch).queryByRole('button', {name: 'delete'})
  75. ).not.toBeInTheDocument();
  76. });
  77. it('sends a request when delete button is clicked', async () => {
  78. renderSavedSearch();
  79. // Second item should have a delete button as it is not a global search
  80. userEvent.click(screen.getByRole('button', {name: 'delete'}));
  81. renderGlobalModal();
  82. expect(
  83. await screen.findByText('Are you sure you want to delete this saved search?')
  84. ).toBeInTheDocument();
  85. userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  86. expect(onDelete).toHaveBeenCalledWith(savedSearchList[2]);
  87. });
  88. it('hides is:unresolved global search', () => {
  89. renderSavedSearch();
  90. expect(screen.queryByText('Unresolved')).not.toBeInTheDocument();
  91. });
  92. });