helpSearch.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import HelpSearch from 'sentry/components/helpSearch';
  3. const mockResults = [
  4. {
  5. site: 'docs',
  6. name: 'Documentation',
  7. hits: [
  8. {
  9. id: 'SitePage /platforms/native/guides/minidumps/',
  10. site: 'docs',
  11. url: 'https://docs.sentry.io/platforms/native/guides/minidumps/',
  12. context: {context1: 'Platforms > Native > Guides > Minidumps'},
  13. title: 'Minidumps',
  14. text: 'Sentry can process Minidump crash reports, a memory <mark>dump</mark> used on Windows and by\nopen …',
  15. },
  16. {
  17. id: 'SitePage /product/discover-queries/query-builder/',
  18. site: 'docs',
  19. url: 'https://docs.sentry.io/product/discover-queries/query-builder/',
  20. context: {context1: 'Product > Discover Queries > Query Builder'},
  21. title: 'Query Builder',
  22. text: '… conditions, see Using OR & AND Conditions . Tag <mark>Summ</mark>ary Filters Every event has a list of …',
  23. },
  24. ],
  25. },
  26. {
  27. site: 'help-center',
  28. name: 'Help Center',
  29. hits: [],
  30. },
  31. {
  32. site: 'develop',
  33. name: 'Developer Documentation',
  34. hits: [
  35. {
  36. id: 'eee2b51a-7594-5f86-91db-267c15db5ef6',
  37. site: 'develop',
  38. url: 'https://develop.sentry.dev/services/digests/',
  39. context: {context1: 'Services > Digests'},
  40. title: 'Notification Digests',
  41. text: '… operation, especially on large datasets. Backends <mark>Dumm</mark>y Backend The <mark>dumm</mark>y backend disables digest scheduling …',
  42. },
  43. ],
  44. },
  45. {
  46. site: 'blog',
  47. name: 'Blog Posts',
  48. hits: [
  49. {
  50. id: 'ae61cfd6d4b462d24dd4622b8b7db274',
  51. site: 'blog',
  52. context: {context1: 'Building Sentry: Symbolicator'},
  53. url: 'https://blog.sentry.io/2019/06/13/building-a-sentry-symbolicator/',
  54. title: 'Stacking your cards frames',
  55. text: '… traces. Since iOS is particularly restrictive, we <mark>dump</mark>ed this information into a temporary location and …',
  56. },
  57. ],
  58. },
  59. ];
  60. jest.mock('@sentry-internal/global-search', () => ({
  61. SentryGlobalSearch: jest
  62. .fn()
  63. .mockImplementation(() => ({query: () => Promise.resolve(mockResults)})),
  64. }));
  65. describe('HelpSearch', function () {
  66. it('produces search results', async function () {
  67. render(
  68. <HelpSearch
  69. entryPoint="sidebar_help"
  70. renderInput={({getInputProps}) => (
  71. <input {...getInputProps({type: 'text'})} data-test-id="search" />
  72. )}
  73. />
  74. );
  75. userEvent.type(screen.getByTestId('search'), 'dummy');
  76. await screen.findByText('From Documentation');
  77. for (const result of mockResults) {
  78. expect(screen.getByText(`From ${result.name}`)).toBeInTheDocument();
  79. }
  80. expect(screen.getAllByTestId('highlight')).toHaveLength(5);
  81. });
  82. });