issueSearchWithSavedSearches.spec.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {SearchFixture} from 'sentry-fixture/search';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {IssueSearchWithSavedSearches} from 'sentry/views/issueList/issueSearchWithSavedSearches';
  4. describe('IssueSearchWithSavedSearches', () => {
  5. const defaultProps = {
  6. query: 'is:unresolved',
  7. onSearch: jest.fn(),
  8. };
  9. const savedSearch = SearchFixture({
  10. id: '789',
  11. query: 'is:unresolved TypeError',
  12. sort: 'date',
  13. name: 'Unresolved TypeErrors',
  14. });
  15. beforeEach(() => {
  16. MockApiClient.clearMockResponses();
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/searches/',
  19. body: [savedSearch],
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/organizations/org-slug/tags/',
  23. body: [],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/recent-searches/',
  27. body: [],
  28. });
  29. });
  30. it('displays "Custom Search" label when no saved searches are selected', async () => {
  31. render(<IssueSearchWithSavedSearches {...defaultProps} />);
  32. expect(
  33. await screen.findByRole('button', {name: 'Custom Search'})
  34. ).toBeInTheDocument();
  35. });
  36. it('displays salected saved search label when one is selected', async () => {
  37. render(<IssueSearchWithSavedSearches {...defaultProps} />, {
  38. router: {
  39. params: {
  40. searchId: '789',
  41. },
  42. },
  43. });
  44. expect(
  45. await screen.findByRole('button', {name: savedSearch.name})
  46. ).toBeInTheDocument();
  47. });
  48. });