helpSearchModal.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {openHelpSearchModal} from 'app/actionCreators/modal';
  4. import App from 'app/views/app';
  5. describe('Docs Search Modal', function() {
  6. beforeEach(function() {
  7. MockApiClient.clearMockResponses();
  8. MockApiClient.addMockResponse({
  9. url: '/organizations/',
  10. body: [TestStubs.Organization({slug: 'billy-org', name: 'billy org'})],
  11. });
  12. MockApiClient.addMockResponse({
  13. url: '/organizations/org-slug/projects/',
  14. query: 'foo',
  15. body: [TestStubs.Project({slug: 'foo-project'})],
  16. });
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/teams/',
  19. query: 'foo',
  20. body: [TestStubs.Team({slug: 'foo-team'})],
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/members/',
  24. query: 'foo',
  25. body: TestStubs.Members(),
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/plugins/?plugins=_all',
  29. query: 'foo',
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/config/integrations/',
  34. query: 'foo',
  35. body: [],
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/internal/health/',
  39. body: {
  40. problems: [],
  41. },
  42. });
  43. MockApiClient.addMockResponse({
  44. url: '/assistant/?v2',
  45. body: [],
  46. });
  47. });
  48. it('can open help search modal and complete a search', async function() {
  49. jest.mock('algoliasearch', () => {
  50. const search = jest.fn(() => {
  51. const docHits = [
  52. {
  53. url: '/doc_result',
  54. _highlightResult: {
  55. title: {value: 'Doc result 1'},
  56. },
  57. _snippetResult: {
  58. content: {value: 'Doc result 1 description'},
  59. },
  60. },
  61. ];
  62. const faqHits = [
  63. {
  64. url: '/faq_result',
  65. _highlightResult: {
  66. title: {value: 'FAQ result 1'},
  67. },
  68. _snippetResult: {
  69. body_safe: {value: 'FAQ result 1 description'},
  70. },
  71. },
  72. ];
  73. return Promise.resolve({results: [{hits: docHits}, {hits: faqHits}]});
  74. });
  75. return () => ({search});
  76. });
  77. const wrapper = mountWithTheme(
  78. <App params={{orgId: 'org-slug'}}>{<div>placeholder content</div>}</App>,
  79. TestStubs.routerContext([
  80. {
  81. router: TestStubs.router({
  82. params: {orgId: 'org-slug'},
  83. }),
  84. },
  85. ])
  86. );
  87. // No Modal
  88. expect(wrapper.find('ModalDialog')).toHaveLength(0);
  89. openHelpSearchModal();
  90. await tick();
  91. await tick();
  92. wrapper.update();
  93. // Should have Modal + input
  94. expect(wrapper.find('ModalDialog')).toHaveLength(1);
  95. wrapper.find('ModalDialog input').simulate('change', {target: {value: 'dummy'}});
  96. await tick();
  97. wrapper.update();
  98. expect(wrapper.find('SearchResultWrapper')).toHaveLength(2);
  99. expect(wrapper.find('SearchSources DropdownBox')).toSnapshot();
  100. });
  101. });