issueSearchWithSavedSearches.spec.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {Search} 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 = Search({
  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. });
  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. });