issueSearchWithSavedSearches.spec.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. });
  26. it('displays "Custom Search" label when no saved searches are selected', () => {
  27. render(<IssueSearchWithSavedSearches {...defaultProps} />);
  28. expect(screen.getByRole('button', {name: 'Custom Search'})).toBeInTheDocument();
  29. });
  30. it('displays salected saved search label when one is selected', async () => {
  31. render(<IssueSearchWithSavedSearches {...defaultProps} />, {
  32. router: {
  33. params: {
  34. searchId: '789',
  35. },
  36. },
  37. });
  38. expect(
  39. await screen.findByRole('button', {name: savedSearch.name})
  40. ).toBeInTheDocument();
  41. });
  42. });