issueSearchWithSavedSearches.spec.tsx 1.2 KB

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